{"record":{"id":"7b6e8478f059a4ff","repo":"sgl-project/sglang","slug":"kv-canary-lut-len-must-be-positive-when-has-swa-l","errorCode":null,"errorMessage":"kv-canary: lut_len must be positive when has_swa_lut is True","messagePattern":"kv-canary: lut_len must be positive when has_swa_lut is True","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py","lineNumber":179,"sourceCode":"        raise ValueError(\n            f\"kv-canary: write_req_capacity must be non-negative, got {write_req_capacity}\"\n        )\n    if verify_capacity < 0:\n        raise ValueError(\n            f\"kv-canary: verify_capacity must be non-negative, got {verify_capacity}\"\n        )\n    if req_to_token_stride0 <= 0:\n        raise ValueError(\n            f\"kv-canary: req_to_token_stride0 must be positive, got {req_to_token_stride0}\"\n        )\n    if lut_len < 0:\n        raise ValueError(f\"kv-canary: lut_len must be non-negative, got {lut_len}\")\n    if not isinstance(has_swa_lut, bool):\n        raise ValueError(\n            f\"kv-canary: has_swa_lut must be bool, got {type(has_swa_lut).__name__}\"\n        )\n    if has_swa_lut and lut_len <= 0:\n        raise ValueError(\"kv-canary: lut_len must be positive when has_swa_lut is True\")\n    if not has_swa_lut and lut_len != 0:\n        raise ValueError(\"kv-canary: lut_len must be 0 when has_swa_lut is False\")\n\n    _require_len(req_pool_indices, \"req_pool_indices\", bs)\n    _require_len(prefix_lens, \"prefix_lens\", bs)\n    _require_len(extend_seq_lens, \"extend_seq_lens\", bs)\n    _require_2d(req_to_token, \"req_to_token\")\n    _require_min_len(lut_tensor, \"lut_tensor\", max(lut_len, 1))\n    _require_min_len(\n        out_verify_offsets_scratch,\n        \"out_verify_offsets_scratch\",\n        _PLAN_BS_BLOCK_SIZE + 1,\n    )\n    _require_len(out_write_offsets, \"out_write_offsets\", write_offsets_len)\n    _require_len(\n        out_write_seed_slot_indices,\n        \"out_write_seed_slot_indices\",\n        write_req_capacity,","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py#L161-L197","documentation":"When the SWA LUT specialization is enabled the kernel actually reads the LUT, so lut_len must be at least 1; a zero-length LUT with has_swa_lut=True means the kernel would read out of bounds.","triggerScenarios":"Calling launch_plan_offsets_kernel with has_swa_lut=True but lut_len == 0 (empty LUT tensor) while swa_window_size implies SWA translation is needed.","commonSituations":"SWA mapping tensor allocated empty because the SWA pool was never populated; wiring has_swa_lut from a different flag than the LUT itself.","solutions":["Populate the full-to-SWA LUT before launching and pass its real length","Or set has_swa_lut=False and lut_len=0 if SWA translation genuinely isn't needed"],"exampleFix":"// before\nlaunch_plan_offsets_kernel(..., lut_tensor=torch.zeros(0, dtype=torch.int64), lut_len=0, has_swa_lut=True)\n// after\nlaunch_plan_offsets_kernel(..., lut_tensor=full_to_swa_lut, lut_len=int(full_to_swa_lut.shape[0]), has_swa_lut=True)","handlingStrategy":"validation","validationCode":"if has_swa_lut:\n    assert lut_len >= 1 and int(lut_tensor.shape[0]) >= lut_len","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Populate the SWA LUT before enabling has_swa_lut"],"tags":["kv-canary","lut","swa"],"backgroundTag":"empty-required-buffer","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}