vllm.v1.serial_utils
¶
Classes:
-
MsgpackDecoder–Decoder with custom torch tensor and numpy array serialization.
-
MsgpackEncoder–Encoder with custom torch tensor and numpy array serialization.
-
OOBTensorConsumer– -
PydanticMsgspecMixin–Make a
msgspec.Structcompatible with Pydantic for both -
UtilityResult–Wrapper for special handling when serializing/deserializing.
Functions:
-
run_method–Run a method of an object with the given arguments and keyword arguments.
MsgpackDecoder
¶
Decoder with custom torch tensor and numpy array serialization.
Note that unlike vanilla msgspec Decoders, this interface is generally
not thread-safe when encoding tensors / numpy arrays.
oob_tensor_provider must be used when an OOBTensorConsumer is used on the
encoder side.
MsgpackEncoder
¶
Encoder with custom torch tensor and numpy array serialization.
Note that unlike vanilla msgspec Encoders, this interface is generally
not thread-safe when encoding tensors / numpy arrays.
By default, arrays below 256B are serialized inline Larger will get sent via dedicated messages. Note that this is a per-tensor limit.
When a oob_tensor_consumer is provided, tensors (CUDA and CPU) will be
offered to it for out-of-band handling.
OOBTensorConsumer
¶
Bases: ABC
Methods:
-
__call__–Called with tensors for the current message.
-
new_message–Called at the start of each new encoded message.
__call__(tensor)
abstractmethod
¶
Called with tensors for the current message. Returns None to reject the tensor (falls back to regular serialization), otherwise a dict with arbitrary placeholder data to be included in the serialized message.
new_message()
abstractmethod
¶
Called at the start of each new encoded message.
PydanticMsgspecMixin
¶
Make a msgspec.Struct compatible with Pydantic for both
validation (JSON/dict -> Struct) and serialization
(Struct -> JSON-safe dict).
Subclasses may set __pydantic_msgspec_exclude__ (a set[str])
to list non-underscore field names that should also be stripped from
serialized output. Fields whose names start with _ are always
excluded automatically.
Methods:
-
__get_pydantic_core_schema__–Make msgspec.Struct compatible with Pydantic, respecting defaults.
__get_pydantic_core_schema__(source_type, handler)
classmethod
¶
Make msgspec.Struct compatible with Pydantic, respecting defaults.
Handle JSON=>msgspec.Struct. Used when exposing msgspec.Struct to the
API as input or in /docs. Note this is cached by Pydantic and not
called on every validation.
_serialize_msgspec(value)
staticmethod
¶
Serialize a msgspec.Struct to a JSON-compatible dict, stripping
private (_-prefixed) and explicitly excluded fields.
Uses msgspec.to_builtins which respects omit_defaults=True,
so only fields that differ from their declared defaults are included.
_validate_msgspec(value)
classmethod
¶
Validate and convert input to msgspec.Struct instance.
UtilityResult
¶
Wrapper for special handling when serializing/deserializing.
_decode_type_info_recursive(type_info, data, convert_fn)
¶
Recursively decode type information for nested structures of lists/dicts.
_encode_type_info_recursive(obj)
¶
Recursively encode type information for nested structures of lists/dicts.
run_method(obj, method, args, kwargs)
¶
Run a method of an object with the given arguments and keyword arguments. If the method is string, it will be converted to a method using getattr. If the method is serialized bytes and will be deserialized using cloudpickle. If the method is a callable, it will be called directly.