{"record":{"id":"0ebfd3cfe51f62be","repo":"sgl-project/sglang","slug":"capacity-must-be-positive-got-capacity","errorCode":null,"errorMessage":"capacity must be positive, got {capacity}","messagePattern":"capacity must be positive, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/multimodal/kimi_k3_vit_cuda_graph_runner.py","lineNumber":46,"sourceCode":"@dataclass\nclass _CapturedVisionGraph:\n    graph: torch.cuda.CUDAGraph\n    input_buffer: torch.Tensor\n    outputs: Tuple[torch.Tensor, ...]\n    metadata: KimiK3VisionForwardMetadata\n\n\nclass KimiK3ViTCudaGraphRunner:\n    def __init__(\n        self,\n        tower: KimiK3VisionTower,\n        *,\n        capacity: int,\n        min_hits: int,\n        max_seqlen: int | None = None,\n    ) -> None:\n        if capacity <= 0:\n            raise ValueError(f\"capacity must be positive, got {capacity}\")\n        if min_hits <= 0:\n            raise ValueError(f\"min_hits must be positive, got {min_hits}\")\n        if max_seqlen is not None and max_seqlen <= 0:\n            raise ValueError(f\"max_seqlen must be positive, got {max_seqlen}\")\n        self.tower = tower\n        self.capacity = capacity\n        self.min_hits = min_hits\n        self.max_seqlen = max_seqlen\n        self.graphs: dict[Hashable, _CapturedVisionGraph] = {}\n        self.seen: OrderedDict[Hashable, int] = OrderedDict()\n        self.failed_keys: set[Hashable] = set()\n        self._graph_memory_pool: Any = None\n        self._capacity_logged = False\n        self._max_seqlen_logged = False\n        logger.info(\n            \"Kimi-K3 ViT CUDA graph: capacity=%d min_hits=%d max_seqlen=%s\",\n            capacity,\n            min_hits,","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/multimodal/kimi_k3_vit_cuda_graph_runner.py#L28-L64","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a positive capacity (>=1)","If you meant to disable the CUDA-graph cache, don't construct the runner at all rather than passing 0","Guard derived capacity: capacity = max(1, computed)"],"exampleFix":"// before\nrunner = KimiK3VitCudaGraphRunner(tower=t, capacity=args.graph_cap, min_hits=2)\n// after\nif args.graph_cap > 0:\n    runner = KimiK3VitCudaGraphRunner(tower=t, capacity=args.graph_cap, min_hits=2)\nelse:\n    runner = None","handlingStrategy":"validation","validationCode":"assert capacity is None or isinstance(capacity, int) and capacity > 0, f\"capacity must be positive, got {capacity}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 0/None to mean 'disabled' at your config layer and skip constructing the runner","Clamp computed capacities: max(1, value)"],"tags":["cuda-graph","kimi-k3","config-validation","vision-tower"],"backgroundTag":"invalid-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}