{"record":{"id":"1ef96ef8da1de4e1","repo":"sgl-project/sglang","slug":"name-entries-must-be-tensors-or-none","errorCode":null,"errorMessage":"{name} entries must be tensors or None.","messagePattern":"(.+?) entries must be tensors or None\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/utils/condition_expansion.py","lineNumber":57,"sourceCode":"                f\"{name} has batch dim {current_batch_size} (shape \"\n                f\"{tuple(value.shape)}); expected {self.prompt_batch_size} \"\n                f\"(per-prompt) or {self.sample_batch_size} (per-sample).\"\n            )\n        repeats = self.sample_batch_size // self.prompt_batch_size\n        return value.repeat_interleave(repeats, dim=0)\n\n    def _expand_tensors(self, value, name: str):\n        \"\"\"Expand a tensor or each tensor in a list, preserving its container.\"\"\"\n        if value is None:\n            return None\n        if isinstance(value, torch.Tensor):\n            return self._expand_tensor(value, name)\n        if not isinstance(value, list):\n            raise TypeError(f\"{name} must be a tensor, list of tensors, or None.\")\n        if any(\n            item is not None and not isinstance(item, torch.Tensor) for item in value\n        ):\n            raise TypeError(f\"{name} entries must be tensors or None.\")\n        return [\n            self._expand_tensor(item, f\"{name}[{index}]\") if item is not None else None\n            for index, item in enumerate(value)\n        ]\n\n    def _expand_sequence_lengths(\n        self, value: list[list[int] | None] | None, name: str\n    ) -> list[list[int] | None] | None:\n        if value is None:\n            return None\n        repeats = self.sample_batch_size // self.prompt_batch_size\n        expanded = []\n        for index, sequence_lengths in enumerate(value):\n            if (\n                sequence_lengths is None\n                or len(sequence_lengths) == self.sample_batch_size\n            ):\n                expanded.append(sequence_lengths)","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/utils/condition_expansion.py#L39-L75","documentation":"Thrown by ConditionExpansion._expand_tensors when the value is a list but some entries are neither None nor torch.Tensor — list containers must contain only tensors (or None placeholders).","triggerScenarios":"Passing a mixed list like [tensor, 0.5] or [np.array(...), tensor] to expand_field.","commonSituations":"Padding a conditioning list with a default scalar instead of None; partially converted numpy-to-torch lists; inserting a default value for missing items.","solutions":["Use None for missing list entries, not 0 or other defaults","Convert every numpy array entry to a tensor before calling expand_field","Add an assert/isinstance sweep over the list at construction time"],"exampleFix":"# before\nconds = [t1, 0.0]  # placeholder for missing item\n# after\nconds = [t1, None]","handlingStrategy":"type-guard","validationCode":"assert all(i is None or isinstance(i, torch.Tensor) for i in value), \"list entries must be tensors or None\"","typeGuard":"def is_tensor_list(v) -> bool:\n    import torch\n    return isinstance(v, list) and all(i is None or isinstance(i, torch.Tensor) for i in v)","tryCatchPattern":null,"preventionTips":["Use None (never 0/scalars) as the placeholder for missing conditioning entries"],"tags":["batching","type-error","validation"],"backgroundTag":"type-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}