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
- Convert the array to a supported numeric dtype before sending: arr.astype(np.float32) or np.stack(list_of_arrays)
- For object arrays of same-shaped items, use np.stack(arr.tolist()) to get a concrete dtype
- 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
- Cast arrays to concrete numeric dtypes (float32/int32) before sending
- Use np.stack for lists of same-shaped arrays instead of np.array(object)
- Avoid complex dtypes in request payloads
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
- Cannot msgpack encode object of type {type(obj)} with enc_ho
- Cannot msgpack decode object of type {type(obj)} as {tp} wit
- Unhandled known MessagePack extension code: {code}
- {name} must have dtype {dtype}, got {t.dtype}
- kv-canary: scatter_req_token_ids flat_in must be int64, got
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/31b63f8629f990c1.
Report an issue: GitHub.