sgl-project/sglang · error · ValueError
{name}[{index}] has {len(sequence_lengths)} entries; expecte
Error message
{name}[{index}] has {len(sequence_lengths)} entries; expected {self.prompt_batch_size} (per-prompt) or {self.sample_batch_size} (per-sample). What it means
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.
Source
Thrown at python/sglang/multimodal_gen/runtime/utils/condition_expansion.py:85
return None
repeats = self.sample_batch_size // self.prompt_batch_size
expanded = []
for index, sequence_lengths in enumerate(value):
if (
sequence_lengths is None
or len(sequence_lengths) == self.sample_batch_size
):
expanded.append(sequence_lengths)
elif len(sequence_lengths) == self.prompt_batch_size:
expanded.append(
[
sequence_length
for sequence_length in sequence_lengths
for _ in range(repeats)
]
)
else:
raise ValueError(
f"{name}[{index}] has {len(sequence_lengths)} entries; expected "
f"{self.prompt_batch_size} (per-prompt) or "
f"{self.sample_batch_size} (per-sample)."
)
return expanded
def expand_field(self, batch, field_name: str) -> None:
"""Expand one field in place, dispatching from its value type."""
value = getattr(batch, field_name)
if value is None:
return
if isinstance(value, torch.Tensor) or (
isinstance(value, list)
and all(item is None or isinstance(item, torch.Tensor) for item in value)
):
expanded = self._expand_tensors(value, field_name)
elif isinstance(value, list) and all(
item is None or isinstance(item, list) for item in valueView on GitHub (pinned to 0132848349)
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
Example fix
# before batch.cond_seq_lens = [[12]] # 1 prompt but prompt_batch_size=2 # after batch.cond_seq_lens = [[12], [12]] # one entry per prompt
Defensive patterns
Strategy: validation
Validate before calling
assert all(len(x) in (expander.prompt_batch_size, expander.sample_batch_size) for x in field), 'length mismatch'
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- QwenImageEditPlus expects either one shared condition image
- {field_name} must be a tensor, list of tensors, list of sequ
- cos/sin shape does not cover image tokens and head_dim
- Unsupported image type: {type(image)}
- QwenImage RoPE text cache overflow before denoising: require
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/81362a1652f96efe.
Report an issue: GitHub.