Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions vllm/v1/serial_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
bytestr = Union[bytes, bytearray, memoryview, zmq.Frame]


def _log_insecure_serialization_warning():
logger.warning_once("Allowing insecure serialization using pickle due to "
"VLLM_ALLOW_INSECURE_SERIALIZATION=1")


class MsgpackEncoder:
"""Encoder with custom torch tensor and numpy array serialization.

Expand All @@ -60,9 +65,7 @@ def __init__(self, size_threshold: Optional[int] = None):
self.aux_buffers: Optional[list[bytestr]] = None
self.size_threshold = size_threshold
if envs.VLLM_ALLOW_INSECURE_SERIALIZATION:
logger.warning(
"Allowing insecure serialization using pickle due to "
"VLLM_ALLOW_INSECURE_SERIALIZATION=1")
_log_insecure_serialization_warning()

def encode(self, obj: Any) -> Sequence[bytestr]:
try:
Expand Down Expand Up @@ -119,7 +122,9 @@ def enc_hook(self, obj: Any) -> Any:
for item in itemlist]

if not envs.VLLM_ALLOW_INSECURE_SERIALIZATION:
raise TypeError(f"Object of type {type(obj)} is not serializable")
raise TypeError(f"Object of type {type(obj)} is not serializable"
"Set VLLM_ALLOW_INSECURE_SERIALIZATION=1 to allow "
"fallback to pickle-based serialization.")

if isinstance(obj, FunctionType):
# `pickle` is generally faster than cloudpickle, but can have
Expand Down Expand Up @@ -202,9 +207,7 @@ def __init__(self, t: Optional[Any] = None):
dec_hook=self.dec_hook)
self.aux_buffers: Sequence[bytestr] = ()
if envs.VLLM_ALLOW_INSECURE_SERIALIZATION:
logger.warning(
"Allowing insecure deserialization using pickle due to "
"VLLM_ALLOW_INSECURE_SERIALIZATION=1")
_log_insecure_serialization_warning()

def decode(self, bufs: Union[bytestr, Sequence[bytestr]]) -> Any:
if isinstance(bufs, (bytes, bytearray, memoryview, zmq.Frame)):
Expand Down