{"record":{"id":"a3f43f4285d19ad5","repo":"sgl-project/sglang","slug":"kv-canary-cuda-graph-max-bs-must-be-non-negative","errorCode":null,"errorMessage":"kv-canary: cuda_graph_max_bs must be non-negative, got {cuda_graph_max_bs}","messagePattern":"kv-canary: cuda_graph_max_bs must be non-negative, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/kv_canary/capacities.py","lineNumber":72,"sourceCode":"                \"kv-canary: req_to_token_pool_size must be positive, \"\n                f\"got {req_to_token_pool_size}\"\n            )\n        if max_seq_len_per_req <= 0:\n            raise ValueError(\n                \"kv-canary: max_seq_len_per_req must be positive, \"\n                f\"got {max_seq_len_per_req}\"\n            )\n        if pool_slot_count <= 0:\n            raise ValueError(\n                f\"kv-canary: pool_slot_count must be positive, got {pool_slot_count}\"\n            )\n\n        cuda_graph_config = get_exec().graph.cuda_graph_config\n        cuda_graph_max_bs = (\n            cuda_graph_config.decode.max_bs if cuda_graph_config is not None else 0\n        ) or 0\n        if cuda_graph_max_bs < 0:\n            raise ValueError(\n                f\"kv-canary: cuda_graph_max_bs must be non-negative, got {cuda_graph_max_bs}\"\n            )\n\n        spec_num_draft_tokens = get_spec().speculative_num_draft_tokens\n        if spec_num_draft_tokens is None:\n            spec_num_draft_tokens = 0\n        if spec_num_draft_tokens < 0:\n            raise ValueError(\n                \"kv-canary: speculative_num_draft_tokens must be non-negative, \"\n                f\"got {spec_num_draft_tokens}\"\n            )\n\n        max_prefill_tokens = get_schedule().max_prefill_tokens\n        if max_prefill_tokens <= 0:\n            raise ValueError(\n                f\"kv-canary: max_prefill_tokens must be positive, got {max_prefill_tokens}\"\n            )\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/kv_canary/capacities.py#L54-L90","documentation":"from_args reads the CUDA graph decode max batch size from the runtime config (defaulting to 0 when graphs are disabled) and requires it to be non-negative. A negative value would corrupt the canary's batch-size capacity math, so it raises ValueError with the offending number.","triggerScenarios":"Calling install_canary/from_args when cuda_graph_config.decode.max_bs is negative — only possible via a programmatically built CUDA graph config or a server-args override that sets a negative max batch size (e.g. --cuda-graph-max-bs -1 reaching the config unvalidated).","commonSituations":"Test harnesses or scripts constructing graph configs manually with invalid negative max_bs; flags like --cuda-graph-max-bs set to negative sentinel values meaning 'disabled' where 0 is expected.","solutions":["Use 0 (or omit the flag) to disable CUDA graphs instead of a negative value","Validate/normalize cuda_graph_max_bs >= 0 before building configs in custom launch code","Check the constructed cuda_graph_config.decode.max_bs in a debugger/repro script"],"exampleFix":"# before\n--cuda-graph-max-bs -1\n\n# after\n--cuda-graph-max-bs 0  # or omit to use defaults","handlingStrategy":"validation","validationCode":"cfg = get_exec().graph.cuda_graph_config\nmax_bs = (cfg.decode.max_bs if cfg is not None else 0) or 0\nif max_bs < 0:\n    raise SystemExit(\"cuda_graph_max_bs must be >= 0; use 0 to disable graphs\")\ncaps = CanaryLaunchCapacities.from_args(...)","typeGuard":"def is_non_negative(n) -> bool:\n    return isinstance(n, int) and n >= 0","tryCatchPattern":null,"preventionTips":["Use 0/omit flags to disable CUDA graphs, never negative sentinels","Validate programmatic graph configs before launch","Document 0-as-disabled convention in launch tooling"],"tags":["kv-canary","validation","cuda-graph","value-error"],"backgroundTag":"config-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}