vllm-project/vllm · error · ValueError

Unsupported data type for serialization: {type(data)}

Error message

Unsupported data type for serialization: {type(data)}

What it means

The write path of ShmObjectStorage expects `data` to be either bytes (single pickle/serialized blob) or a list of bytes chunks (multimodal items). The branch that copies data into the shared memory view raises ValueError for anything else, guarding against writing a malformed layout into shm.

Source

Thrown at vllm/distributed/device_communicators/shm_object_storage.py:523

    def copy_to_buffer(
        self,
        data: bytes | list[bytes],
        data_bytes: int,
        metadata: bytes,
        md_bytes: int,
        data_view: memoryview,
    ) -> None:
        data_view[self.flag_bytes : self.flag_bytes + md_bytes] = metadata
        if isinstance(data, bytes):
            data_view[-data_bytes:] = data
        elif isinstance(data, list):
            start_idx = self.flag_bytes + md_bytes
            for item_bytes in data:
                item_size = len(item_bytes)
                data_view[start_idx : start_idx + item_size] = item_bytes
                start_idx += item_size
        else:
            raise ValueError(f"Unsupported data type for serialization: {type(data)}")

    def increment_writer_flag(self, id: int) -> None:
        """Set the in-use flag for the writer."""
        self.writer_flag[id] = self.writer_flag.get(id, 0) + 1

    def increment_reader_flag(self, data_view: memoryview) -> None:
        """Set the in-use flag for the reader."""
        # >0 for in-use flag
        reader_count = self.ring_buffer.byte2int(data_view)
        data_view[:] = self.ring_buffer.int2byte(reader_count + 1)

    def free_unused(self) -> None:
        """Free unused buffers in the ring buffer."""
        # try to free up 2*max_object_size bytes of space in the ring buffer,
        # since the buffer might be fragmented
        freed_ids = self.ring_buffer.free_buf(
            self.default_is_free_check, 2 * self.max_object_size
        )

View on GitHub (pinned to c794754062)

Solutions

  1. Fix serialize() to return (bytes, data_bytes, metadata, md_bytes) with the payload strictly bytes or list[bytes]
  2. Convert memoryview/bytearray payloads with bytes(...) before returning
  3. Add a unit test asserting the serde's return types match the write path's expectations

Example fix

# before
def serialize(self, value):
    return memoryview(buf), n, md, md_n  # ValueError in writer

# after
def serialize(self, value):
    return bytes(buf), n, md, md_n
Defensive patterns

Strategy: type-guard

Validate before calling

data, data_bytes, md, md_bytes = serde.serialize(value)
assert isinstance(data, (bytes, list)), "serialize() must return bytes or list[bytes]"

Type guard

def serde_payload_ok(data) -> bool:
    return isinstance(data, bytes) or (
        isinstance(data, list) and all(isinstance(x, bytes) for x in data)
    )

Prevention

When it happens

Trigger: A custom ObjectSerde.serialize() returning a data payload that is e.g. a torch.Tensor, str, numpy array, or list of non-bytes items instead of bytes/list[bytes]; the writer then hits this when storing the object.

Common situations: Extending ShmObjectStorage with a new serde class whose serialize() return contract is misunderstood; refactors that changed serialize()'s return type from bytes to memoryview or bytearray without casting.

Related errors


AI-assisted analysis of vllm-project/vllm@c794754062 (2026-08-14). Data as JSON: /api/errors/d28424e3c725c8ab. Report an issue: GitHub.