sgl-project/sglang · error · ValueError

image_token_counts must be non-empty

Error message

image_token_counts must be non-empty

What it means

minimax_h3_multi_image_presentation (fl2va keyframe path) requires at least one image token count because it must emit `<Picture N>:` + IMAGE_PAD blocks for every image in the prompt.

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/presentation.py:123

            video_token_id=video_token_id,
        )


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:

View on GitHub (pinned to 0132848349)

Solutions

  1. Compute per-image token counts (from image resolution/patch math) and pass a non-empty list
  2. If the prompt is text-only, use minimax_h3_text_only_ids instead
  3. Check that the number of counts matches the number of images referenced in the prompt

Example fix

// before
minimax_h3_multi_image_presentation(tok, prompt=p, image_token_counts=[])
// after
minimax_h3_multi_image_presentation(tok, prompt=p, image_token_counts=[196, 196])
Defensive patterns

Strategy: validation

Validate before calling

if not image_token_counts:
    raise ValueError("at least one image token count required")

Type guard

def has_image_counts(cs: list[int]) -> bool:
    return len(cs) > 0 and all(c > 0 for c in cs)

Prevention

When it happens

Trigger: Calling minimax_h3_multi_image_presentation with image_token_counts=[] while prompt describes images.

Common situations: Multi-image prompts where vision token budgets were not computed (missing preprocessor output); conditioning built before image sizes are known; accidentally passing the wrong variable (e.g. video counts).

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/b31ca29f22c09c3f. Report an issue: GitHub.