{"record":{"id":"e6f0f3f4d6bd88c3","repo":"sgl-project/sglang","slug":"kv-canary-lut-len-must-be-0-when-has-swa-lut-is-f","errorCode":null,"errorMessage":"kv-canary: lut_len must be 0 when has_swa_lut is False","messagePattern":"kv-canary: lut_len must be 0 when has_swa_lut is False","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py","lineNumber":181,"sourceCode":"        )\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,\n    )\n    _require_len(out_verify_num_valid, \"out_verify_num_valid\", 1)","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py#L163-L199","documentation":"When there is no SWA LUT the kernel specialization expects lut_len to be exactly 0 so it can skip LUT addressing entirely; a nonzero lut_len with has_swa_lut=False indicates inconsistent arguments.","triggerScenarios":"Calling launch_plan_offsets_kernel with has_swa_lut=False but lut_len > 0, e.g. passing a placeholder LUT tensor while disabling the flag.","commonSituations":"Inconsistent derivation of the pair — the flag computed from one source (window size) and the length from another (a non-None tensor).","solutions":["Derive both from the same source: has_swa_lut = lut is not None; lut_len = int(lut.shape[0]) if has_swa_lut else 0","Use the module's prepare-LUT helper which returns a consistent (lut, len, flag) triple"],"exampleFix":"// before\nlaunch_plan_offsets_kernel(..., lut_tensor=lut, lut_len=int(lut.shape[0]), has_swa_lut=False)\n// after\nhas_swa = lut is not None\nlaunch_plan_offsets_kernel(..., lut_tensor=lut if has_swa else zeros1, lut_len=int(lut.shape[0]) if has_swa else 0, has_swa_lut=has_swa)","handlingStrategy":"validation","validationCode":"has_swa_lut = lut is not None\nlut_len = int(lut.shape[0]) if has_swa_lut else 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive flag and length from the same tensor reference"],"tags":["kv-canary","lut","swa"],"backgroundTag":"inconsistent-arguments","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}