sgl-project/sglang · error · ValueError
image_token_count must be positive
Error message
image_token_count must be positive
What it means
Each image in the fl2va multi-image presentation needs a positive IMAGE_PAD token count; a zero or negative count cannot form a valid vision block.
Source
Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/presentation.py:127
def minimax_h3_text_only_ids(tokenizer: Any, prompt: str) -> torch.Tensor:
"""t2va presentation: verbatim prompt, no special tokens."""
if not prompt:
raise ValueError("prompt must be non-empty")
return torch.tensor(_text_ids(tokenizer, prompt), dtype=torch.long)
def minimax_h3_multi_image_presentation(
tokenizer: Any,
*,
prompt: str,
image_token_counts: list[int],
) -> tuple[torch.Tensor, torch.Tensor]:
if not image_token_counts:
raise ValueError("image_token_counts must be non-empty")
presentation = _Presentation()
for index, count in enumerate(image_token_counts, start=1):
if int(count) <= 0:
raise ValueError("image_token_count must be positive")
presentation.text(_text_ids(tokenizer, f"<Picture {index}>: "))
presentation.vision(_vision_block_ids(tokenizer, IMAGE_PAD, count))
presentation.text(_text_ids(tokenizer, prompt))
return presentation.build()
def minimax_h3_ref2va_presentation(
tokenizer: Any,
*,
prompt: str,
condition_labels: list[tuple[str, int]],
image_token_count: int | list[int] | None,
) -> tuple[torch.Tensor, torch.Tensor]:
"""ref2va positive presentation:
per condition in request order — image i: ``<Picture i>: `` label followed
by the vision block; audio j: ``<Audio j>: `` label only (audio content
never enters Qwen) — then the verbatim prompt. Returns ``(ids, token_tags)``View on GitHub (pinned to 0132848349)
Solutions
- Recompute the offending entry's token budget from image dimensions
- Clamp to at least 1 or drop that image and its `<Picture N>` reference
- Add pre-call validation of all counts
Example fix
// before image_token_counts=[196, 0] // after image_token_counts=[196, 196]
Defensive patterns
Strategy: validation
Validate before calling
assert all(int(c) > 0 for c in image_token_counts), "image counts must be positive"
Type guard
def valid_image_counts(cs: list[int]) -> bool:
return all(isinstance(c, int) and c > 0 for c in cs) Prevention
- Recompute counts from image resolution with a floor of 1
- Validate the list before the API call
When it happens
Trigger: Passing image_token_counts containing a 0 or negative entry, e.g. [196, 0].
Common situations: Resolution-derived token math flooring to 0 for tiny images; default zero-filled arrays; index bugs mapping image sizes to counts.
Related errors
- image_token_counts must be non-empty
- MiniMax-H3 adaln_t_table must have shape [N, D] with N >= 2,
- MiniMax H3 AdaLN cache has invalid timestep plans
- TP size must be positive.
- num_attention_heads must be positive.
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/f339c22f9bb819af.
Report an issue: GitHub.