{"record":{"id":"31b63f8629f990c1","repo":"sgl-project/sglang","slug":"unsupported-dtype-obj-dtype","errorCode":null,"errorMessage":"Unsupported dtype: {obj.dtype}","messagePattern":"Unsupported dtype: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/entrypoints/action/protocol.py","lineNumber":31,"sourceCode":"import numpy as np\nfrom PIL import Image\n\nfrom sglang.multimodal_gen.configs.pipeline_configs.cosmos3 import Cosmos3Config\nfrom sglang.multimodal_gen.configs.sample.action import ActionSamplingParams\nfrom sglang.multimodal_gen.configs.sample.cosmos3 import Cosmos3SamplingParams\nfrom sglang.multimodal_gen.configs.sample.sampling_params import SamplingParams\nfrom sglang.multimodal_gen.runtime.entrypoints.action.cosmos3 import (\n    build_cosmos3_action_sampling_params,\n    cosmos3_action_metadata,\n)\nfrom sglang.multimodal_gen.runtime.entrypoints.utils import prepare_request\nfrom sglang.multimodal_gen.runtime.scheduler_client import async_scheduler_client\nfrom sglang.multimodal_gen.runtime.server_args import ServerArgs\n\n\ndef pack_numpy_payload(obj):\n    if isinstance(obj, (np.ndarray, np.generic)) and obj.dtype.kind in (\"V\", \"O\", \"c\"):\n        raise ValueError(f\"Unsupported dtype: {obj.dtype}\")\n    if isinstance(obj, np.ndarray):\n        return {\n            b\"__ndarray__\": True,\n            b\"data\": obj.tobytes(),\n            b\"dtype\": obj.dtype.str,\n            b\"shape\": obj.shape,\n        }\n    if isinstance(obj, np.generic):\n        return {\n            b\"__npgeneric__\": True,\n            b\"data\": obj.item(),\n            b\"dtype\": obj.dtype.str,\n        }\n    return obj\n\n\ndef unpack_numpy_payload(obj):\n    ndarray_marker = obj.get(\"__ndarray__\") or obj.get(b\"__ndarray__\")","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/entrypoints/action/protocol.py#L13-L49","documentation":"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.","triggerScenarios":"Passing image_masks or other array fields as object arrays, structured arrays, or complex-valued arrays in an action request payload.","commonSituations":"Ragged mask lists converted with np.array(...) producing dtype=object; complex-valued sensor data; structured arrays from h5py/pyarrow tables.","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"],"exampleFix":"# before\nmasks = np.array([[1,0],[1]], dtype=object)\n# after\nmasks = np.zeros((2, 2), dtype=np.float32)","handlingStrategy":"type-guard","validationCode":"import numpy as np\ndef packable(a):\n    return not (isinstance(a, np.ndarray) and a.dtype.kind in ('V','O','c'))\nassert packable(arr)","typeGuard":"def is_packable_array(a) -> bool:\n    import numpy as np\n    return not isinstance(a, np.ndarray) or a.dtype.kind not in ('V', 'O', 'c')","tryCatchPattern":null,"preventionTips":["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"],"tags":["numpy","msgpack","serialization","dtype-validation"],"backgroundTag":"unsupported-numpy-dtype-serialization","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}