{"record":{"id":"b3a907ce24c4c308","repo":"sgl-project/sglang","slug":"field-name-must-be-a-tensor-list-of-tensors-li","errorCode":null,"errorMessage":"{field_name} must be a tensor, list of tensors, list of sequence-length lists, or None.","messagePattern":"(.+?) must be a tensor, list of tensors, list of sequence-length lists, or None\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/utils/condition_expansion.py","lineNumber":107,"sourceCode":"                )\n        return expanded\n\n    def expand_field(self, batch, field_name: str) -> None:\n        \"\"\"Expand one field in place, dispatching from its value type.\"\"\"\n        value = getattr(batch, field_name)\n        if value is None:\n            return\n        if isinstance(value, torch.Tensor) or (\n            isinstance(value, list)\n            and all(item is None or isinstance(item, torch.Tensor) for item in value)\n        ):\n            expanded = self._expand_tensors(value, field_name)\n        elif isinstance(value, list) and all(\n            item is None or isinstance(item, list) for item in value\n        ):\n            expanded = self._expand_sequence_lengths(value, field_name)\n        else:\n            raise TypeError(\n                f\"{field_name} must be a tensor, list of tensors, \"\n                \"list of sequence-length lists, or None.\"\n            )\n        setattr(batch, field_name, expanded)\n","sourceCodeStart":89,"sourceCodeEnd":112,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/utils/condition_expansion.py#L89-L112","documentation":"expand_field only accepts four shapes for a conditioning field: a single tensor, a list of tensors, a list of sequence-length lists (each item None or a list), or None. Anything else (e.g. a list mixing tensors and ints, a numpy array, a list of dicts) raises this TypeError before setattr on the batch.","triggerScenarios":"Calling expand_conditioning_to_sample_batch / expand_field with a field value that is a numpy array, a list of ints/floats, or a heterogeneous list (tensors mixed with non-list scalars). Note a plain list of ints fails the `all(item is None or isinstance(item, list))` check.","commonSituations":"Passing numpy arrays instead of torch tensors; passing raw token-id lists instead of wrapping them in tensors or lists-of-lists; optional fields that become [None, tensor] mixed lists.","solutions":["Convert numpy arrays to torch tensors before calling expand_field","Wrap bare scalar/int lists as list-of-lists if they represent sequence lengths, or as tensors otherwise","Ensure list fields are homogeneous: all tensors, or all None/list items"],"exampleFix":"# before\nbatch.cond_embeds = np.array([...])\n# after\nimport torch\nbatch.cond_embeds = torch.from_numpy(np.array([...]))","handlingStrategy":"type-guard","validationCode":"import torch\nok = value is None or isinstance(value, torch.Tensor) or (isinstance(value, list) and (all(isinstance(i, torch.Tensor) for i in value) or all(i is None or isinstance(i, list) for i in value)))","typeGuard":"def is_expandable(value) -> bool:\n    if value is None or isinstance(value, torch.Tensor):\n        return True\n    if isinstance(value, list) and value:\n        return all(isinstance(i, torch.Tensor) for i in value) or all(\n            i is None or isinstance(i, list) for i in value\n        )\n    return False","tryCatchPattern":"try:\n    expand_field(...)\nexcept TypeError as e:\n    raise ValueError(f'Bad conditioning field type: {e}') from e","preventionTips":["Convert numpy to torch at the boundary","Keep list fields homogeneous","Add unit tests covering all four accepted shapes"],"tags":["type-validation","conditioning","multimodal"],"backgroundTag":"type-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}