[Chore] Replace all base64 usages with faster pybase64 package (#37290)
Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn>
This commit is contained in:
@@ -20,9 +20,9 @@ run the script with
|
|||||||
python openai_chat_completion_client_for_multimodal.py --chat-type audio
|
python openai_chat_completion_client_for_multimodal.py --chat-type audio
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
import requests
|
import requests
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
from utils import get_first_model
|
from utils import get_first_model
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ The script:
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import base64
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import librosa
|
import librosa
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
import websockets
|
import websockets
|
||||||
|
|
||||||
from vllm.assets.audio import AudioAsset
|
from vllm.assets.audio import AudioAsset
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ Requirements: websockets, numpy, gradio
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import base64
|
|
||||||
import json
|
import json
|
||||||
import queue
|
import queue
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
import websockets
|
import websockets
|
||||||
|
|
||||||
SAMPLE_RATE = 16_000
|
SAMPLE_RATE = 16_000
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ NOTE:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import base64
|
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
import requests
|
import requests
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ Refer to each `run_*` function for the command to run the server for that model.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import base64
|
|
||||||
import io
|
import io
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
from openai._types import NOT_GIVEN, NotGiven
|
from openai._types import NOT_GIVEN, NotGiven
|
||||||
from openai.types.chat import ChatCompletionMessageParam
|
from openai.types.chat import ChatCompletionMessageParam
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
import base64
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
from vllm import LLM
|
from vllm import LLM
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import base64
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
# This example shows how to perform an online inference that generates
|
# This example shows how to perform an online inference that generates
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ Then run this script:
|
|||||||
python colqwen3_rerank_online.py
|
python colqwen3_rerank_online.py
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
import requests
|
import requests
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ Then run this script:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import base64
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
import requests
|
import requests
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import base64
|
|
||||||
import os
|
import os
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
from transformers import AutoTokenizer, PreTrainedTokenizerBase
|
from transformers import AutoTokenizer, PreTrainedTokenizerBase
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ Unit tests for engine classes (parsing, validation, registry).
|
|||||||
Integration tests for NCCL and IPC weight transfer between processes using Ray.
|
Integration tests for NCCL and IPC weight transfer between processes using Ray.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
|
||||||
import pickle
|
import pickle
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import ray
|
import ray
|
||||||
import torch
|
import torch
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import base64
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import openai
|
import openai
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import base64
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
import torch
|
import torch
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import base64
|
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import openai # use the official client for correctness check
|
import openai # use the official client for correctness check
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
import torch
|
import torch
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import base64
|
|
||||||
import json
|
import json
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
import librosa
|
import librosa
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import websockets
|
import websockets
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ embedding models, covering text embedding, embedding type conversions,
|
|||||||
response structure, batching, normalisation, and semantic similarity.
|
response structure, batching, normalisation, and semantic similarity.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ Validates image embedding, batching, normalisation, and embedding type
|
|||||||
conversions through the /v2/embed endpoint.
|
conversions through the /v2/embed endpoint.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
|
||||||
import struct
|
import struct
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import base64
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import openai
|
import openai
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
import requests
|
import requests
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
"""Unit tests for Cohere embed protocol: build_typed_embeddings and its
|
"""Unit tests for Cohere embed protocol: build_typed_embeddings and its
|
||||||
underlying packing helpers, plus Cohere-specific serving helpers."""
|
underlying packing helpers, plus Cohere-specific serving helpers."""
|
||||||
|
|
||||||
import base64
|
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from vllm.entrypoints.pooling.embed.protocol import (
|
from vllm.entrypoints.pooling.embed.protocol import (
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import base64
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
import torch
|
import torch
|
||||||
|
|||||||
@@ -1235,9 +1235,9 @@ def voxtral_patch_hf_runner(hf_model: "HfRunner") -> "HfRunner":
|
|||||||
generated).
|
generated).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
|
||||||
import io
|
import io
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
import soundfile as sf
|
import soundfile as sf
|
||||||
|
|
||||||
processor = hf_model.processor
|
processor = hf_model.processor
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ ColPali is a multi-vector retrieval model based on PaliGemma backbone
|
|||||||
It produces per-token embeddings for both text and image inputs.
|
It produces per-token embeddings for both text and image inputs.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import torch
|
import torch
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ ColBERT-style late interaction scoring (MaxSim). It produces per-token
|
|||||||
embeddings for both text and image inputs.
|
embeddings for both text and image inputs.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import torch
|
import torch
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ Tests for the LlamaNemotronVL model family:
|
|||||||
Both variants share a SigLIP vision encoder with a bidirectional LLaMA backbone.
|
Both variants share a SigLIP vision encoder with a bidirectional LLaMA backbone.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import torch
|
import torch
|
||||||
from transformers import AutoModel, AutoModelForSequenceClassification, AutoProcessor
|
from transformers import AutoModel, AutoModelForSequenceClassification, AutoProcessor
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
import base64
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import librosa
|
import librosa
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from vllm.multimodal.media import AudioMediaIO
|
from vllm.multimodal.media import AudioMediaIO
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import base64
|
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
from tempfile import NamedTemporaryFile, TemporaryDirectory
|
from tempfile import NamedTemporaryFile, TemporaryDirectory
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
import torch
|
import torch
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import base64
|
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
@@ -11,6 +10,7 @@ from typing import Any
|
|||||||
|
|
||||||
import albumentations
|
import albumentations
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
import rasterio
|
import rasterio
|
||||||
import regex as re
|
import regex as re
|
||||||
import torch
|
import torch
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
import base64
|
|
||||||
import io
|
import io
|
||||||
|
|
||||||
import imagehash
|
import imagehash
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ Tests verify that malicious sparse tensors are rejected before they can trigger
|
|||||||
out-of-bounds memory writes during to_dense() operations.
|
out-of-bounds memory writes during to_dense() operations.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
|
||||||
import io
|
import io
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
import pytest
|
import pytest
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,14 @@ CHECK_IMPORTS = {
|
|||||||
"vllm/v1/serial_utils.py",
|
"vllm/v1/serial_utils.py",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
"base64": ForbiddenImport(
|
||||||
|
pattern=r"^\s*(?:import\s+base64(?:$|\s|,)|from\s+base64\s+import)",
|
||||||
|
tip=(
|
||||||
|
"Replace 'import base64' with 'import pybase64' "
|
||||||
|
"or 'import pybase64 as base64'."
|
||||||
|
),
|
||||||
|
allowed_pattern=re.compile(r"^\s*import\s+pybase64(\s*|\s+as\s+base64\s*)$"),
|
||||||
|
),
|
||||||
"re": ForbiddenImport(
|
"re": ForbiddenImport(
|
||||||
pattern=r"^\s*(?:import\s+re(?:$|\s|,)|from\s+re\s+import)",
|
pattern=r"^\s*(?:import\s+re(?:$|\s|,)|from\s+re\s+import)",
|
||||||
tip="Replace 'import re' with 'import regex as re' or 'import regex'.",
|
tip="Replace 'import re' with 'import regex as re' or 'import regex'.",
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ generation. Supported dataset types include:
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import ast
|
import ast
|
||||||
import base64
|
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
@@ -31,6 +30,7 @@ from tempfile import NamedTemporaryFile
|
|||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
from huggingface_hub import snapshot_download
|
from huggingface_hub import snapshot_download
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from typing_extensions import deprecated
|
from typing_extensions import deprecated
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
"""IPC-based weight transfer engine using CUDA IPC for communication."""
|
"""IPC-based weight transfer engine using CUDA IPC for communication."""
|
||||||
|
|
||||||
import base64
|
|
||||||
import pickle
|
import pickle
|
||||||
from collections.abc import Callable, Iterator
|
from collections.abc import Callable, Iterator
|
||||||
from dataclasses import asdict, dataclass
|
from dataclasses import asdict, dataclass
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
import requests
|
import requests
|
||||||
import torch
|
import torch
|
||||||
from torch.multiprocessing.reductions import reduce_tensor
|
from torch.multiprocessing.reductions import reduce_tensor
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import base64
|
|
||||||
import json
|
import json
|
||||||
from collections.abc import AsyncGenerator
|
from collections.abc import AsyncGenerator
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import pybase64 as base64
|
||||||
from fastapi import WebSocket
|
from fastapi import WebSocket
|
||||||
from starlette.websockets import WebSocketDisconnect
|
from starlette.websockets import WebSocketDisconnect
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import base64
|
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from argparse import Namespace
|
from argparse import Namespace
|
||||||
@@ -13,6 +12,7 @@ from typing import Any, TypeAlias
|
|||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import pybase64 as base64
|
||||||
import torch
|
import torch
|
||||||
from fastapi import UploadFile
|
from fastapi import UploadFile
|
||||||
from prometheus_client import start_http_server
|
from prometheus_client import start_http_server
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ OpenAI: https://platform.openai.com/docs/api-reference/embeddings
|
|||||||
Cohere: https://docs.cohere.com/reference/embed
|
Cohere: https://docs.cohere.com/reference/embed
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import base64
|
|
||||||
import builtins
|
import builtins
|
||||||
import struct
|
import struct
|
||||||
import time
|
import time
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from typing import Literal, TypeAlias
|
from typing import Literal, TypeAlias
|
||||||
|
|
||||||
|
import pybase64 as base64
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from vllm import PoolingParams
|
from vllm import PoolingParams
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
import base64
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -138,7 +137,7 @@ class AudioMediaIO(MediaIO[tuple[npt.NDArray, float]]):
|
|||||||
media_type: str,
|
media_type: str,
|
||||||
data: str,
|
data: str,
|
||||||
) -> tuple[npt.NDArray, float]:
|
) -> tuple[npt.NDArray, float]:
|
||||||
return self.load_bytes(base64.b64decode(data))
|
return self.load_bytes(pybase64.b64decode(data))
|
||||||
|
|
||||||
def load_file(self, filepath: Path) -> tuple[npt.NDArray, float]:
|
def load_file(self, filepath: Path) -> tuple[npt.NDArray, float]:
|
||||||
return librosa.load(filepath, sr=None)
|
return librosa.load(filepath, sr=None)
|
||||||
@@ -155,7 +154,7 @@ class AudioMediaIO(MediaIO[tuple[npt.NDArray, float]]):
|
|||||||
soundfile.write(buffer, audio, sr, format=audio_format)
|
soundfile.write(buffer, audio, sr, format=audio_format)
|
||||||
data = buffer.getvalue()
|
data = buffer.getvalue()
|
||||||
|
|
||||||
return base64.b64encode(data).decode("utf-8")
|
return pybase64.b64encode(data).decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
class AudioEmbeddingMediaIO(MediaIO[torch.Tensor]):
|
class AudioEmbeddingMediaIO(MediaIO[torch.Tensor]):
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||||
import base64
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
|
import pybase64
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from vllm import envs
|
from vllm import envs
|
||||||
@@ -84,7 +84,7 @@ class VideoMediaIO(MediaIO[tuple[npt.NDArray, dict[str, Any]]]):
|
|||||||
[np.asarray(load_frame(frame_data)) for frame_data in data.split(",")]
|
[np.asarray(load_frame(frame_data)) for frame_data in data.split(",")]
|
||||||
), {}
|
), {}
|
||||||
|
|
||||||
return self.load_bytes(base64.b64decode(data))
|
return self.load_bytes(pybase64.b64decode(data))
|
||||||
|
|
||||||
def load_file(self, filepath: Path) -> tuple[npt.NDArray, dict[str, Any]]:
|
def load_file(self, filepath: Path) -> tuple[npt.NDArray, dict[str, Any]]:
|
||||||
with filepath.open("rb") as f:
|
with filepath.open("rb") as f:
|
||||||
|
|||||||
Reference in New Issue
Block a user