Skip to content

vllm.executor.msgspec_utils

decode_hook

decode_hook(type: Type, obj: Any) -> Any

Custom msgspec dec hook that supports array types.

See https://jcristharif.com/msgspec/api.html#msgspec.msgpack.Encoder

Source code in vllm/executor/msgspec_utils.py
def decode_hook(type: Type, obj: Any) -> Any:
    """Custom msgspec dec hook that supports array types.

    See https://jcristharif.com/msgspec/api.html#msgspec.msgpack.Encoder
    """
    if type is array:
        deserialized = array(VLLM_TOKEN_ID_ARRAY_TYPE)
        deserialized.frombytes(obj)
        return deserialized

encode_hook

encode_hook(obj: Any) -> Any

Custom msgspec enc hook that supports array types.

See https://jcristharif.com/msgspec/api.html#msgspec.msgpack.Encoder

Source code in vllm/executor/msgspec_utils.py
def encode_hook(obj: Any) -> Any:
    """Custom msgspec enc hook that supports array types.

    See https://jcristharif.com/msgspec/api.html#msgspec.msgpack.Encoder
    """
    if isinstance(obj, array):
        assert obj.typecode == VLLM_TOKEN_ID_ARRAY_TYPE, (
            f"vLLM array type should use '{VLLM_TOKEN_ID_ARRAY_TYPE}' type. "
            f"Given array has a type code of {obj.typecode}.")
        return obj.tobytes()