sgl-project/sglang · error · ValueError

Unsupported dtype: {obj.dtype}

Error message

Unsupported dtype: {obj.dtype}

What it means

When msgpack-serializing numpy payloads for the action endpoint, pack_numpy_payload rejects arrays whose dtype.kind is 'V' (void/structured), 'O' (object), or 'c' (complex). These dtypes cannot be losslessly serialized via tobytes() and reconstructed from dtype.str, so they fail fast at pack time.

Source

Thrown at python/sglang/multimodal_gen/runtime/entrypoints/action/protocol.py:31

import numpy as np
from PIL import Image

from sglang.multimodal_gen.configs.pipeline_configs.cosmos3 import Cosmos3Config
from sglang.multimodal_gen.configs.sample.action import ActionSamplingParams
from sglang.multimodal_gen.configs.sample.cosmos3 import Cosmos3SamplingParams
from sglang.multimodal_gen.configs.sample.sampling_params import SamplingParams
from sglang.multimodal_gen.runtime.entrypoints.action.cosmos3 import (
    build_cosmos3_action_sampling_params,
    cosmos3_action_metadata,
)
from sglang.multimodal_gen.runtime.entrypoints.utils import prepare_request
from sglang.multimodal_gen.runtime.scheduler_client import async_scheduler_client
from sglang.multimodal_gen.runtime.server_args import ServerArgs


def pack_numpy_payload(obj):
    if isinstance(obj, (np.ndarray, np.generic)) and obj.dtype.kind in ("V", "O", "c"):
        raise ValueError(f"Unsupported dtype: {obj.dtype}")
    if isinstance(obj, np.ndarray):
        return {
            b"__ndarray__": True,
            b"data": obj.tobytes(),
            b"dtype": obj.dtype.str,
            b"shape": obj.shape,
        }
    if isinstance(obj, np.generic):
        return {
            b"__npgeneric__": True,
            b"data": obj.item(),
            b"dtype": obj.dtype.str,
        }
    return obj


def unpack_numpy_payload(obj):
    ndarray_marker = obj.get("__ndarray__") or obj.get(b"__ndarray__")

View on GitHub (pinned to 0132848349)

Solutions

  1. Convert the array to a supported numeric dtype before sending: arr.astype(np.float32) or np.stack(list_of_arrays)
  2. For object arrays of same-shaped items, use np.stack(arr.tolist()) to get a concrete dtype
  3. Drop complex components or split real/imaginary parts explicitly

Example fix

# before
masks = np.array([[1,0],[1]], dtype=object)
# after
masks = np.zeros((2, 2), dtype=np.float32)
Defensive patterns

Strategy: type-guard

Validate before calling

import numpy as np
def packable(a):
    return not (isinstance(a, np.ndarray) and a.dtype.kind in ('V','O','c'))
assert packable(arr)

Type guard

def is_packable_array(a) -> bool:
    import numpy as np
    return not isinstance(a, np.ndarray) or a.dtype.kind not in ('V', 'O', 'c')

Prevention

When it happens

Trigger: Passing image_masks or other array fields as object arrays, structured arrays, or complex-valued arrays in an action request payload.

Common situations: Ragged mask lists converted with np.array(...) producing dtype=object; complex-valued sensor data; structured arrays from h5py/pyarrow tables.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/31b63f8629f990c1. Report an issue: GitHub.