sgl-project/sglang · error · ValueError
image_token_count required for an image reference
Error message
image_token_count required for an image reference
What it means
While walking condition_labels, an image reference was encountered but there are fewer normalized image_token_count entries than image references in the plan.
Source
Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/presentation.py:266
)
image_token_counts = _as_int_list(image_token_count, name="image_token_count")
video_counts_by_ref = _as_nested_int_list(
video_block_token_counts,
name="video_block_token_counts",
)
video_timestamps_by_ref = _as_nested_float_list(
video_block_timestamps,
name="video_block_timestamps",
)
if len(video_counts_by_ref) != len(video_timestamps_by_ref):
raise ValueError("video block token counts and timestamps must align")
image_seen = 0
video_seen = 0
for cond_type, ordinal in condition_labels:
if cond_type == "image":
image_seen += 1
if image_seen > len(image_token_counts):
raise ValueError("image_token_count required for an image reference")
count = int(image_token_counts[image_seen - 1])
if count <= 0:
raise ValueError("image_token_count required for an image reference")
presentation.text(_text_ids(tokenizer, f"<Picture {ordinal}>: "))
presentation.vision(_vision_block_ids(tokenizer, IMAGE_PAD, count))
elif cond_type == "audio":
presentation.text(_text_ids(tokenizer, f"<Audio {ordinal}>: "))
elif cond_type == "video":
video_seen += 1
if video_seen > len(video_counts_by_ref):
raise ValueError(
"video reference requires block token counts and timestamps"
)
counts = video_counts_by_ref[video_seen - 1]
timestamps = video_timestamps_by_ref[video_seen - 1]
if not counts or not timestamps:
raise ValueError(
"video reference requires block token counts and timestamps"View on GitHub (pinned to 0132848349)
Solutions
- Pass image_token_count as a list with one positive entry per image reference
- Regenerate counts to match the current condition_labels plan
- Remove extra image references from the plan
Example fix
// before
condition_labels=[("image",1),("image",2)], image_token_count=196
// after
condition_labels=[("image",1),("image",2)], image_token_count=[196,196] Defensive patterns
Strategy: validation
Validate before calling
n_images = sum(1 for t, _ in condition_labels if t == "image") assert len(image_token_counts_list) >= n_images
Prevention
- Derive counts length from the plan's image count
- Always use a list for multi-image plans
When it happens
Trigger: condition_labels contains 2 image entries but image_token_count=196 (a single int normalizes to [196]) — the second image reference finds no count.
Common situations: Passing a scalar image_token_count for a multi-image plan; forgetting to extend counts for additional images; plan changed to include more images than the conditioning data provides.
Related errors
- video block token counts and timestamps must align
- video reference requires block token counts and timestamps
- unused image_token_count entries
- unused video block token count entries
- seq_len {seq_len} < used rows {used}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/aeb4198d98304d50.
Report an issue: GitHub.