sgl-project/sglang · error · ValueError

max_seqlen must be positive, got {max_seqlen}

Error message

max_seqlen must be positive, got {max_seqlen}

What it means

When max_seqlen is provided to the Kimi-K3 ViT CUDA graph runner it must be positive; None disables the bound, but an explicit value <= 0 is rejected because it would exclude every sequence.

Source

Thrown at python/sglang/srt/multimodal/kimi_k3_vit_cuda_graph_runner.py:50

    outputs: Tuple[torch.Tensor, ...]
    metadata: KimiK3VisionForwardMetadata


class KimiK3ViTCudaGraphRunner:
    def __init__(
        self,
        tower: KimiK3VisionTower,
        *,
        capacity: int,
        min_hits: int,
        max_seqlen: int | None = None,
    ) -> None:
        if capacity <= 0:
            raise ValueError(f"capacity must be positive, got {capacity}")
        if min_hits <= 0:
            raise ValueError(f"min_hits must be positive, got {min_hits}")
        if max_seqlen is not None and max_seqlen <= 0:
            raise ValueError(f"max_seqlen must be positive, got {max_seqlen}")
        self.tower = tower
        self.capacity = capacity
        self.min_hits = min_hits
        self.max_seqlen = max_seqlen
        self.graphs: dict[Hashable, _CapturedVisionGraph] = {}
        self.seen: OrderedDict[Hashable, int] = OrderedDict()
        self.failed_keys: set[Hashable] = set()
        self._graph_memory_pool: Any = None
        self._capacity_logged = False
        self._max_seqlen_logged = False
        logger.info(
            "Kimi-K3 ViT CUDA graph: capacity=%d min_hits=%d max_seqlen=%s",
            capacity,
            min_hits,
            max_seqlen,
        )

    @staticmethod

View on GitHub (pinned to 0132848349)

Solutions

  1. Pass max_seqlen=None when unlimited
  2. Otherwise pass a positive bound, e.g. the model's max vision sequence length
  3. Sanitize: max_seqlen = max_seqlen if max_seqlen and max_seqlen > 0 else None

Example fix

// before
runner = KimiK3VitCudaGraphRunner(tower=t, capacity=8, min_hits=2, max_seqlen=cfg.max_len or 0)
// after
runner = KimiK3VitCudaGraphRunner(tower=t, capacity=8, min_hits=2, max_seqlen=cfg.max_len or None)
Defensive patterns

Strategy: validation

Validate before calling

if max_seqlen is not None and max_seqlen <= 0:
    max_seqlen = None  # or raise in strict mode

Prevention

When it happens

Trigger: Passing max_seqlen=0 or negative while intending 'no limit' — the API uses None for unlimited, not 0.

Common situations: Config schemas defaulting unset ints to 0; passing max_model_len-1 style computed values that underflow to 0 for tiny test configs.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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