{"record":{"id":"7930c86556268a7a","repo":"sgl-project/sglang","slug":"input-data-must-be-a-torch-tensor-but-got-type-7930c8","errorCode":null,"errorMessage":"Input 'data' must be a torch.Tensor, but got {type}","messagePattern":"Input 'data' must be a torch\\.Tensor, but got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/multimodal/transport/cuda_ipc.py","lineNumber":194,"sourceCode":"    or device-wide synchronization.\n    \"\"\"\n\n    def __init__(\n        self,\n        data: torch.Tensor,\n        info_data: torch.Tensor,\n        pool_ipc_handle,\n        pool_byte_offset: int,\n        ready_byte_offset: int,\n        ack_byte_offset: int,\n        generation: int,\n        total_consumer_count: int,\n        use_pool_handle_cache: bool,\n    ):\n        if (not isinstance(data, torch.Tensor)) or (\n            not isinstance(info_data, torch.Tensor)\n        ):\n            raise TypeError(\n                f\"Input 'data' must be a torch.Tensor, but got {type(data)}\"\n            )\n\n        self._init_stream_ordered_consumer(\n            ready_byte_offset=ready_byte_offset,\n            ack_byte_offset=ack_byte_offset,\n            generation=generation,\n            total_consumer_count=total_consumer_count,\n            transport_name=\"CUDA IPC\",\n        )\n\n        self.proxy_state = {\n            \"ipc_extra\": {\n                \"pool_handle\": pool_ipc_handle,\n                \"pool_byte_offset\": pool_byte_offset,\n                \"shape\": data.shape,\n                \"dtype\": data.dtype,\n                \"stride\": data.stride(),","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/multimodal/transport/cuda_ipc.py#L176-L212","documentation":"The CUDA IPC consumer-side handle constructor demands both data and info_data be torch.Tensor objects; anything else (numpy arrays, cupy, storage objects) fails this TypeError immediately. IPC handles wrap raw CUDA tensors shared across processes, so no implicit conversion is attempted.","triggerScenarios":"Constructing the IPC consumer with data as np.ndarray, a UntypedStorage, or a cupy array — even if info_data is a tensor, either failing isinstance triggers the raise.","commonSituations":"Interoperability layers passing numpy-backed multimodal embeddings; refactors that switched internal buffers from tensors to other array types; a storage handle opened from bytes not yet wrapped via torch.Tensor._from_storage.","solutions":["Wrap buffers in torch.Tensor before constructing the handle: torch.frombuffer / tensor.view(torch.uint8)","Ensure CUDA tensors, not CPU numpy — the transport requires device tensors","Keep info_data as a uint8 CUDA tensor per the transport contract"],"exampleFix":"# before\nhandle = ConsumerHandle(data=np_array, info_data=info_tensor, ...)\n# after\ndata = torch.frombuffer(np_array.get(), dtype=np.uint8).cuda()\nhandle = ConsumerHandle(data=data, info_data=info_tensor, ...)","handlingStrategy":"type-guard","validationCode":"assert isinstance(data, torch.Tensor) and data.is_cuda, 'data must be a CUDA tensor'","typeGuard":"import torch\ndef is_cuda_tensor(x) -> bool:\n    return isinstance(x, torch.Tensor) and x.is_cuda","tryCatchPattern":null,"preventionTips":["Convert numpy buffers to torch CUDA tensors at the IPC boundary","Keep transport buffers as uint8 CUDA tensors end-to-end"],"tags":["cuda-ipc","type-validation","torch-tensor","multimodal-transport"],"backgroundTag":"unsupported-input-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}