@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 3443aaf8dd
Fork 0

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 15, 04:45 UTC

Move to a faster base64 implementation (#19984)

Signed-off-by: h-avsha <avshalom.manevich@hcompany.ai>

h-avsha committed Jun 25, 2025 at 06:33 UTC 3443aaf8dd7cb0e2f40dd1e6d9d36c8db23c6597
2 files changed +6 -5
requirements/common.txt
+1
@@ -44,3 +44,4 @@ watchfiles # required for http server to monitor the updates of TLS files
44 python-json-logger # Used by logging as per examples/others/logging_configuration.md
45 scipy # Required for phi-4-multimodal-instruct
46 ninja # Required for xgrammar, rocm, tpu, xpu
47 +pybase64 # fast base64 implementation
vllm/multimodal/image.py
+5 -5
@@ -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 from io import BytesIO
5 from pathlib import Path
6
7 +import pybase64
8 import torch
9 from PIL import Image
10
@@ -55,7 +55,7 @@ class ImageMediaIO(MediaIO[Image.Image]):
55 return convert_image_mode(image, self.image_mode)
56
57 def load_base64(self, media_type: str, data: str) -> Image.Image:
58 - return self.load_bytes(base64.b64decode(data))
58 + return self.load_bytes(pybase64.b64decode(data, validate=True))
59
60 def load_file(self, filepath: Path) -> Image.Image:
61 image = Image.open(filepath)
@@ -75,7 +75,7 @@ class ImageMediaIO(MediaIO[Image.Image]):
75 image.save(buffer, image_format)
76 data = buffer.getvalue()
77
78 - return base64.b64encode(data).decode('utf-8')
78 + return pybase64.b64encode(data).decode('utf-8')
79
80
81 class ImageEmbeddingMediaIO(MediaIO[torch.Tensor]):
@@ -88,10 +88,10 @@ class ImageEmbeddingMediaIO(MediaIO[torch.Tensor]):
88 return torch.load(buffer, weights_only=True)
89
90 def load_base64(self, media_type: str, data: str) -> torch.Tensor:
91 - return self.load_bytes(base64.b64decode(data))
91 + return self.load_bytes(pybase64.b64decode(data, validate=True))
92
93 def load_file(self, filepath: Path) -> torch.Tensor:
94 return torch.load(filepath, weights_only=True)
95
96 def encode_base64(self, media: torch.Tensor) -> str:
97 - return base64.b64encode(media.numpy()).decode('utf-8')
97 + return pybase64.b64encode(media.numpy()).decode('utf-8')