sgl-project/sglang · error · ValueError

{name} must be an int or a sequence of ints

Error message

{name} must be an int or a sequence of ints

What it means

_as_int_list normalizes image_token_count which may be a single int or a sequence of ints; anything else (float, str, dict, None handled separately) is rejected.

Source

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

    per type.
    """
    return minimax_h3_ref2va_video_presentation(
        tokenizer,
        prompt=prompt,
        condition_labels=condition_labels,
        image_token_count=image_token_count,
        video_block_token_counts=None,
        video_block_timestamps=None,
    )


def _as_int_list(value: int | Sequence[int] | None, *, name: str) -> list[int]:
    if value is None:
        return []
    if isinstance(value, int):
        return [int(value)]
    if not isinstance(value, Sequence) or isinstance(value, (str, bytes)):
        raise ValueError(f"{name} must be an int or a sequence of ints")
    return [int(item) for item in value]


def _as_nested_int_list(
    value: Sequence[int] | Sequence[Sequence[int]] | None,
    *,
    name: str,
) -> list[list[int]]:
    if value is None:
        return []
    if not isinstance(value, Sequence) or isinstance(value, (str, bytes)):
        raise ValueError(f"{name} must be a sequence")
    if len(value) == 0:
        return []
    first = value[0]
    if isinstance(first, Sequence) and not isinstance(first, (str, bytes)):
        out: list[list[int]] = []
        for group in value:

View on GitHub (pinned to 0132848349)

Solutions

  1. Coerce to int or list[int] before calling (e.g. int(x) or x.tolist())
  2. Ensure config values are parsed as integers, not strings
  3. For multiple images pass a list of ints

Example fix

// before
image_token_count="196"
// after
image_token_count=196
Defensive patterns

Strategy: type-guard

Validate before calling

image_token_count = [int(v) for v in (image_token_count if isinstance(image_token_count, (list, tuple)) else [image_token_count])]

Type guard

def is_int_or_int_seq(v) -> bool:
    if isinstance(v, bool):
        return False
    if isinstance(v, int):
        return True
    return isinstance(v, (list, tuple)) and not isinstance(v, (str, bytes)) and all(isinstance(i, int) for i in v)

Prevention

When it happens

Trigger: Passing image_token_count=196.0, "196", or a numpy 2-D array to minimax_h3_ref2va_video_presentation; strings/bytes are explicitly rejected even though they are Sequences.

Common situations: JSON configs delivering numbers as strings; numpy float scalars from budget calculators; passing a dict of per-image counts.

Related errors


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