{"record":{"id":"81362a1652f96efe","repo":"sgl-project/sglang","slug":"name-index-has-len-sequence-lengths-entrie","errorCode":null,"errorMessage":"{name}[{index}] has {len(sequence_lengths)} entries; expected {self.prompt_batch_size} (per-prompt) or {self.sample_batch_size} (per-sample).","messagePattern":"(.+?)\\[(.+?)\\] has (.+?) entries; expected (.+?) \\(per-prompt\\) or (.+?) \\(per-sample\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/utils/condition_expansion.py","lineNumber":85,"sourceCode":"            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)\n            elif len(sequence_lengths) == self.prompt_batch_size:\n                expanded.append(\n                    [\n                        sequence_length\n                        for sequence_length in sequence_lengths\n                        for _ in range(repeats)\n                    ]\n                )\n            else:\n                raise ValueError(\n                    f\"{name}[{index}] has {len(sequence_lengths)} entries; expected \"\n                    f\"{self.prompt_batch_size} (per-prompt) or \"\n                    f\"{self.sample_batch_size} (per-sample).\"\n                )\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","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/utils/condition_expansion.py#L67-L103","documentation":"Raised by ConditionExpander._expand_sequence_lengths when a per-prompt/per-sample list-of-lists field (e.g. sequence lengths) has an inner list whose length matches neither the prompt batch size nor the sample batch size. The expander repeats each per-prompt entry `repeats` times to reach sample granularity; a mismatched length means the conditioning data is inconsistent with the current batch.","triggerScenarios":"Calling expand_conditioning_to_sample_batch / expand_field with a field that is a list of lists (sequence-length style) where len of the list at some index != prompt_batch_size and != sample_batch_size. Typically happens when cond_* inputs were built for a different number of prompts or when samples_per_prompt changed between construction and expansion.","commonSituations":"Mixing per-prompt tensors with per-sample sequence-length lists in one batch; changing samples_per_prompt or image/video counts after building the conditioning dict; off-by-one when padding prompts.","solutions":["Check that each sequence-length list has exactly prompt_batch_size entries (or exactly sample_batch_size for already-expanded data) before calling expand_field","Rebuild the conditioning field after changing samples_per_prompt / batch composition","If the data is already per-sample, pass it as sample_batch_size-length lists so the per-sample branch applies"],"exampleFix":"# before\nbatch.cond_seq_lens = [[12]]  # 1 prompt but prompt_batch_size=2\n# after\nbatch.cond_seq_lens = [[12], [12]]  # one entry per prompt","handlingStrategy":"validation","validationCode":"assert all(len(x) in (expander.prompt_batch_size, expander.sample_batch_size) for x in field), 'length mismatch'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build all conditioning fields from the same batch construction code path","Assert entry counts against prompt/sample batch size before expansion","Re-derive conditioning after changing samples_per_prompt"],"tags":["batch-validation","conditioning","multimodal"],"backgroundTag":"batch-size-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}