sgl-project/sglang · error · ValueError

capacity must be positive, got {capacity}

Error message

capacity must be positive, got {capacity}

What it means

The Kimi-K3 ViT CUDA graph runner requires a strictly positive cache capacity; capacity <= 0 raises immediately in __init__. Capacity bounds how many captured vision graphs are retained, so zero/negative values are meaningless.

Source

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

@dataclass
class _CapturedVisionGraph:
    graph: torch.cuda.CUDAGraph
    input_buffer: torch.Tensor
    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,

View on GitHub (pinned to 0132848349)

Solutions

  1. Pass a positive capacity (>=1)
  2. If you meant to disable the CUDA-graph cache, don't construct the runner at all rather than passing 0
  3. Guard derived capacity: capacity = max(1, computed)

Example fix

// before
runner = KimiK3VitCudaGraphRunner(tower=t, capacity=args.graph_cap, min_hits=2)
// after
if args.graph_cap > 0:
    runner = KimiK3VitCudaGraphRunner(tower=t, capacity=args.graph_cap, min_hits=2)
else:
    runner = None
Defensive patterns

Strategy: validation

Validate before calling

assert capacity is None or isinstance(capacity, int) and capacity > 0, f"capacity must be positive, got {capacity}"

Prevention

When it happens

Trigger: Constructing the graph runner with capacity=0 or a negative number, often from a config default of 0 or an env/CLI override that disables the feature incorrectly.

Common situations: Setting --kimi-k3-vit-graph-cache-capacity 0 intending to disable graphs (should instead not enable the runner); computing capacity from a formula (e.g. num_graphs - max_bs) that can go negative.

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/0ebfd3cfe51f62be. Report an issue: GitHub.