A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 6, 14:30 UTC
[Chore] Replace all base64 usages with faster pybase64 package (#37290)
Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn>
Isotr0py committed
Mar 17, 2026 at 22:44 UTC
a836524d2073fa08d327fc1b13bf791a17c65b82
37 files changed
+46
-40
examples/online_serving/openai_chat_completion_client_for_multimodal.py
+1
-1
@@ -20,9 +20,9 @@ run the script with
20
python openai_chat_completion_client_for_multimodal.py --chat-type audio
21
"""
22
23
-import base64
23
import os
24
25
+import pybase64 as base64
26
import requests
27
from openai import OpenAI
28
from utils import get_first_model
examples/online_serving/openai_realtime_client.py
+1
-1
@@ -24,11 +24,11 @@ The script:
24
25
import argparse
26
import asyncio
27
-import base64
27
import json
28
29
import librosa
30
import numpy as np
31
+import pybase64 as base64
32
import websockets
33
34
from vllm.assets.audio import AudioAsset
examples/online_serving/openai_realtime_microphone_client.py
+1
-1
@@ -18,13 +18,13 @@ Requirements: websockets, numpy, gradio
18
19
import argparse
20
import asyncio
21
-import base64
21
import json
22
import queue
23
import threading
24
25
import gradio as gr
26
import numpy as np
27
+import pybase64 as base64
28
import websockets
29
30
SAMPLE_RATE = 16_000
examples/pooling/embed/embedding_requests_base64_online.py
+1
-1
@@ -7,8 +7,8 @@ NOTE:
7
"""
8
9
import argparse
10
-import base64
10
11
+import pybase64 as base64
12
import requests
13
import torch
14
examples/pooling/embed/vision_embedding_online.py
+1
-1
@@ -7,10 +7,10 @@ Refer to each `run_*` function for the command to run the server for that model.
7
"""
8
9
import argparse
10
-import base64
10
import io
11
from typing import Literal
12
13
+import pybase64 as base64
14
from openai import OpenAI
15
from openai._types import NOT_GIVEN, NotGiven
16
from openai.types.chat import ChatCompletionMessageParam
examples/pooling/plugin/prithvi_geospatial_mae_io_processor.py
+1
-1
@@ -1,8 +1,8 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
-import base64
3
import os
4
5
+import pybase64 as base64
6
import torch
7
8
from vllm import LLM
examples/pooling/plugin/prithvi_geospatial_mae_online.py
+1
-1
@@ -1,9 +1,9 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
-import base64
4
import os
5
6
+import pybase64 as base64
7
import requests
8
9
# This example shows how to perform an online inference that generates
examples/pooling/score/colqwen3_rerank_online.py
+1
-1
@@ -15,9 +15,9 @@ Then run this script:
15
python colqwen3_rerank_online.py
16
"""
17
18
-import base64
18
from io import BytesIO
19
20
+import pybase64 as base64
21
import requests
22
from PIL import Image
23
examples/pooling/token_embed/colqwen3_token_embed_online.py
+1
-1
@@ -21,10 +21,10 @@ Then run this script:
21
"""
22
23
import argparse
24
-import base64
24
from io import BytesIO
25
26
import numpy as np
27
+import pybase64 as base64
28
import requests
29
from PIL import Image
30
tests/benchmarks/test_random_multimodal_dataset_video.py
+1
-1
@@ -1,12 +1,12 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
-import base64
4
import os
5
from tempfile import NamedTemporaryFile
6
from typing import Any, cast
7
8
import cv2
9
+import pybase64 as base64
10
import pytest
11
from transformers import AutoTokenizer, PreTrainedTokenizerBase
12
tests/distributed/test_weight_transfer.py
+1
-1
@@ -6,10 +6,10 @@ Unit tests for engine classes (parsing, validation, registry).
6
Integration tests for NCCL and IPC weight transfer between processes using Ray.
7
"""
8
9
-import base64
9
import pickle
10
from unittest.mock import MagicMock
11
12
+import pybase64 as base64
13
import pytest
14
import ray
15
import torch
tests/entrypoints/openai/chat_completion/test_audio_in_video.py
+1
-1
@@ -1,10 +1,10 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
-import base64
4
import json
5
6
import openai
7
+import pybase64 as base64
8
import pytest
9
import pytest_asyncio
10
tests/entrypoints/openai/chat_completion/test_vision_embeds.py
+1
-2
@@ -1,9 +1,8 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
-import base64
5
-
4
import numpy as np
5
+import pybase64 as base64
6
import pytest
7
import requests
8
import torch
tests/entrypoints/openai/completion/test_completion_with_prompt_embeds.py
+1
-1
@@ -1,11 +1,11 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
-import base64
4
import io
5
import json
6
7
import openai # use the official client for correctness check
8
+import pybase64 as base64
9
import pytest
10
import pytest_asyncio
11
import torch
tests/entrypoints/openai/test_realtime_validation.py
+1
-1
@@ -2,12 +2,12 @@
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
import asyncio
5
-import base64
5
import json
6
import warnings
7
8
import librosa
9
import numpy as np
10
+import pybase64 as base64
11
import pytest
12
import websockets
13
tests/entrypoints/pooling/embed/test_cohere_online.py
+1
-1
@@ -7,10 +7,10 @@ embedding models, covering text embedding, embedding type conversions,
7
response structure, batching, normalisation, and semantic similarity.
8
"""
9
10
-import base64
10
import struct
11
12
import numpy as np
13
+import pybase64 as base64
14
import pytest
15
import requests
16
tests/entrypoints/pooling/embed/test_cohere_online_vision.py
+1
-1
@@ -6,11 +6,11 @@ Validates image embedding, batching, normalisation, and embedding type
6
conversions through the /v2/embed endpoint.
7
"""
8
9
-import base64
9
import struct
10
import zlib
11
12
import numpy as np
13
+import pybase64 as base64
14
import pytest
15
import requests
16
tests/entrypoints/pooling/embed/test_online.py
+1
-1
@@ -1,11 +1,11 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
-import base64
4
import json
5
6
import numpy as np
7
import openai
8
+import pybase64 as base64
9
import pytest
10
import pytest_asyncio
11
import requests
tests/entrypoints/pooling/embed/test_protocol.py
+1
-1
@@ -3,10 +3,10 @@
3
"""Unit tests for Cohere embed protocol: build_typed_embeddings and its
4
underlying packing helpers, plus Cohere-specific serving helpers."""
5
6
-import base64
6
import struct
7
8
import numpy as np
9
+import pybase64 as base64
10
import pytest
11
12
from vllm.entrypoints.pooling.embed.protocol import (
tests/entrypoints/pooling/pooling/test_online.py
+1
-1
@@ -1,10 +1,10 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
-import base64
4
import json
5
6
import numpy as np
7
+import pybase64 as base64
8
import pytest
9
import requests
10
import torch
tests/models/multimodal/generation/vlm_utils/model_utils.py
+1
-1
@@ -1235,9 +1235,9 @@ def voxtral_patch_hf_runner(hf_model: "HfRunner") -> "HfRunner":
1235
generated).
1236
"""
1237
1238
- import base64
1238
import io
1239
1240
+ import pybase64 as base64
1241
import soundfile as sf
1242
1243
processor = hf_model.processor
tests/models/multimodal/pooling/test_colpali.py
+1
-1
@@ -7,9 +7,9 @@ ColPali is a multi-vector retrieval model based on PaliGemma backbone
7
It produces per-token embeddings for both text and image inputs.
8
"""
9
10
-import base64
10
from io import BytesIO
11
12
+import pybase64 as base64
13
import pytest
14
import torch
15
from PIL import Image
tests/models/multimodal/pooling/test_colqwen3.py
+1
-1
@@ -7,9 +7,9 @@ ColBERT-style late interaction scoring (MaxSim). It produces per-token
7
embeddings for both text and image inputs.
8
"""
9
10
-import base64
10
from io import BytesIO
11
12
+import pybase64 as base64
13
import pytest
14
import torch
15
from PIL import Image
tests/models/multimodal/pooling/test_llama_nemotron_vl.py
+1
-1
@@ -9,10 +9,10 @@ Tests for the LlamaNemotronVL model family:
9
Both variants share a SigLIP vision encoder with a bidirectional LLaMA backbone.
10
"""
11
12
-import base64
12
from io import BytesIO
13
from pathlib import Path
14
15
+import pybase64 as base64
16
import pytest
17
import torch
18
from transformers import AutoModel, AutoModelForSequenceClassification, AutoProcessor
tests/multimodal/media/test_audio.py
+1
-1
@@ -1,11 +1,11 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
-import base64
3
from pathlib import Path
4
from unittest.mock import patch
5
6
import librosa
7
import numpy as np
8
+import pybase64 as base64
9
import pytest
10
11
from vllm.multimodal.media import AudioMediaIO
tests/multimodal/media/test_connector.py
+1
-1
@@ -2,13 +2,13 @@
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
import asyncio
5
-import base64
5
import mimetypes
6
import os
7
from tempfile import NamedTemporaryFile, TemporaryDirectory
8
9
import aiohttp
10
import numpy as np
11
+import pybase64 as base64
12
import pytest
13
import requests
14
import torch
tests/plugins/prithvi_io_processor_plugin/prithvi_io_processor/prithvi_processor.py
+1
-1
@@ -1,7 +1,6 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
-import base64
4
import datetime
5
import os
6
import tempfile
@@ -11,6 +10,7 @@ from typing import Any
10
11
import albumentations
12
import numpy as np
13
+import pybase64 as base64
14
import rasterio
15
import regex as re
16
import torch
tests/plugins_tests/test_terratorch_io_processor_plugins.py
+1
-1
@@ -1,9 +1,9 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
-import base64
3
import io
4
5
import imagehash
6
+import pybase64 as base64
7
import pytest
8
import requests
9
from PIL import Image
tests/renderers/test_sparse_tensor_validation.py
+1
-1
@@ -5,9 +5,9 @@ Tests verify that malicious sparse tensors are rejected before they can trigger
5
out-of-bounds memory writes during to_dense() operations.
6
"""
7
8
-import base64
8
import io
9
10
+import pybase64 as base64
11
import pytest
12
import torch
13
tools/pre_commit/check_forbidden_imports.py
+8
@@ -59,6 +59,14 @@ CHECK_IMPORTS = {
59
"vllm/v1/serial_utils.py",
60
},
61
),
62
+ "base64": ForbiddenImport(
63
+ pattern=r"^\s*(?:import\s+base64(?:$|\s|,)|from\s+base64\s+import)",
64
+ tip=(
65
+ "Replace 'import base64' with 'import pybase64' "
66
+ "or 'import pybase64 as base64'."
67
+ ),
68
+ allowed_pattern=re.compile(r"^\s*import\s+pybase64(\s*|\s+as\s+base64\s*)$"),
69
+ ),
70
"re": ForbiddenImport(
71
pattern=r"^\s*(?:import\s+re(?:$|\s|,)|from\s+re\s+import)",
72
tip="Replace 'import re' with 'import regex as re' or 'import regex'.",
vllm/benchmarks/datasets.py
+1
-1
@@ -14,7 +14,6 @@ generation. Supported dataset types include:
14
15
import argparse
16
import ast
17
-import base64
17
import io
18
import json
19
import logging
@@ -31,6 +30,7 @@ from tempfile import NamedTemporaryFile
30
from typing import Any, cast
31
32
import numpy as np
33
+import pybase64 as base64
34
from huggingface_hub import snapshot_download
35
from PIL import Image
36
from typing_extensions import deprecated
vllm/distributed/weight_transfer/ipc_engine.py
+1
-1
@@ -2,12 +2,12 @@
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
"""IPC-based weight transfer engine using CUDA IPC for communication."""
4
5
-import base64
5
import pickle
6
from collections.abc import Callable, Iterator
7
from dataclasses import asdict, dataclass
8
from typing import Any
9
10
+import pybase64 as base64
11
import requests
12
import torch
13
from torch.multiprocessing.reductions import reduce_tensor
vllm/entrypoints/openai/realtime/connection.py
+1
-1
@@ -2,13 +2,13 @@
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
import asyncio
5
-import base64
5
import json
6
from collections.abc import AsyncGenerator
7
from http import HTTPStatus
8
from uuid import uuid4
9
10
import numpy as np
11
+import pybase64 as base64
12
from fastapi import WebSocket
13
from starlette.websockets import WebSocketDisconnect
14
vllm/entrypoints/openai/run_batch.py
+1
-1
@@ -2,7 +2,6 @@
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
import asyncio
5
-import base64
5
import sys
6
import tempfile
7
from argparse import Namespace
@@ -13,6 +12,7 @@ from typing import Any, TypeAlias
12
from urllib.parse import urlparse
13
14
import aiohttp
15
+import pybase64 as base64
16
import torch
17
from fastapi import UploadFile
18
from prometheus_client import start_http_server
vllm/entrypoints/pooling/embed/protocol.py
+1
-1
@@ -6,13 +6,13 @@ OpenAI: https://platform.openai.com/docs/api-reference/embeddings
6
Cohere: https://docs.cohere.com/reference/embed
7
"""
8
9
-import base64
9
import builtins
10
import struct
11
import time
12
from collections.abc import Sequence
13
from typing import Literal, TypeAlias
14
15
+import pybase64 as base64
16
from pydantic import BaseModel, Field
17
18
from vllm import PoolingParams
vllm/multimodal/media/audio.py
+2
-3
@@ -1,6 +1,5 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
-import base64
3
from io import BytesIO
4
from pathlib import Path
5
@@ -138,7 +137,7 @@ class AudioMediaIO(MediaIO[tuple[npt.NDArray, float]]):
137
media_type: str,
138
data: str,
139
) -> tuple[npt.NDArray, float]:
141
- return self.load_bytes(base64.b64decode(data))
140
+ return self.load_bytes(pybase64.b64decode(data))
141
142
def load_file(self, filepath: Path) -> tuple[npt.NDArray, float]:
143
return librosa.load(filepath, sr=None)
@@ -155,7 +154,7 @@ class AudioMediaIO(MediaIO[tuple[npt.NDArray, float]]):
154
soundfile.write(buffer, audio, sr, format=audio_format)
155
data = buffer.getvalue()
156
158
- return base64.b64encode(data).decode("utf-8")
157
+ return pybase64.b64encode(data).decode("utf-8")
158
159
160
class AudioEmbeddingMediaIO(MediaIO[torch.Tensor]):
vllm/multimodal/media/video.py
+2
-2
@@ -1,12 +1,12 @@
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
-import base64
3
from functools import partial
4
from pathlib import Path
5
from typing import Any
6
7
import numpy as np
8
import numpy.typing as npt
9
+import pybase64
10
from PIL import Image
11
12
from vllm import envs
@@ -84,7 +84,7 @@ class VideoMediaIO(MediaIO[tuple[npt.NDArray, dict[str, Any]]]):
84
[np.asarray(load_frame(frame_data)) for frame_data in data.split(",")]
85
), {}
86
87
- return self.load_bytes(base64.b64decode(data))
87
+ return self.load_bytes(pybase64.b64decode(data))
88
89
def load_file(self, filepath: Path) -> tuple[npt.NDArray, dict[str, Any]]:
90
with filepath.open("rb") as f: