{"record":{"id":"18b1a9616918ca29","repo":"sgl-project/sglang","slug":"kv-canary-launch-canary-plan-kernels-torch-refere-18b1a9","errorCode":null,"errorMessage":"kv-canary: launch_canary_plan_kernels_torch_reference requires req_to_verify_expected_tokens_valid_lens when req_to_verify_expected_tokens is set","messagePattern":"kv-canary: launch_canary_plan_kernels_torch_reference requires req_to_verify_expected_tokens_valid_lens when req_to_verify_expected_tokens is set","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/kv_canary/plan_ref.py","lineNumber":59,"sourceCode":"    )\n    prefix_lens_host = prefix_lens.detach().to(device=work_device, dtype=torch.int64)\n    extend_seq_lens_host = extend_seq_lens.detach().to(\n        device=work_device, dtype=torch.int64\n    )\n    req_to_token_host = req_to_token.detach().to(device=work_device, dtype=torch.int64)\n\n    lut: Optional[torch.Tensor] = None\n    if full_to_swa_index_mapping is not None:\n        lut = full_to_swa_index_mapping.detach().to(device=work_device)\n\n    expected_token_pool_host: Optional[torch.Tensor] = None\n    req_to_verify_expected_tokens_valid_lens_host: Optional[torch.Tensor] = None\n    if req_to_verify_expected_tokens is not None:\n        expected_token_pool_host = req_to_verify_expected_tokens.detach().to(\n            device=work_device, dtype=torch.int64\n        )\n        if req_to_verify_expected_tokens_valid_lens is None:\n            raise ValueError(\n                \"kv-canary: launch_canary_plan_kernels_torch_reference requires \"\n                \"req_to_verify_expected_tokens_valid_lens when req_to_verify_expected_tokens is set\"\n            )\n        req_to_verify_expected_tokens_valid_lens_host = (\n            req_to_verify_expected_tokens_valid_lens.detach().to(\n                device=work_device, dtype=torch.int64\n            )\n        )\n\n    total_verify = _materialize_verify_entries(\n        verify_plan_out=verify_plan_out,\n        req_pool_indices_host=req_pool_indices_host,\n        prefix_lens_host=prefix_lens_host,\n        req_to_token_host=req_to_token_host,\n        swa_window_size=swa_window_size,\n        lut=lut,\n        verify_capacity=verify_capacity,\n        work_device=work_device,","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kv_canary/plan_ref.py#L41-L77","documentation":"When req_to_verify_expected_tokens is provided to the torch reference planner, the companion valid-lengths tensor req_to_verify_expected_tokens_valid_lens is mandatory — the reference needs per-request lengths to know how many entries in the ragged expected-token pool are valid. Passing the token pool without its lengths raises ValueError.","triggerScenarios":"Calling launch_canary_plan_kernels_torch_reference(..., req_to_verify_expected_tokens=tokens, req_to_verify_expected_tokens_valid_lens=None).","commonSituations":"Building inputs ad hoc in tests or a new integration where the ragged token pool is populated but the seq-len vector is forgotten; partial migration from an older signature that had no valid_lens parameter.","solutions":["Pass a 1-D int tensor of shape [bs] giving each request's valid token count in the pool","If you truly have no expected tokens, pass req_to_verify_expected_tokens=None to skip the feature entirely","Build both tensors together from the same loop over requests so they cannot diverge"],"exampleFix":"# before\nlaunch_ref(..., req_to_verify_expected_tokens=tok_pool, req_to_verify_expected_tokens_valid_lens=None)\n# after\nlaunch_ref(..., req_to_verify_expected_tokens=tok_pool, req_to_verify_expected_tokens_valid_lens=valid_lens)","handlingStrategy":"validation","validationCode":"if req_to_verify_expected_tokens is not None:\n    assert req_to_verify_expected_tokens_valid_lens is not None","typeGuard":"def has_expected_tokens_args(tokens, valid_lens):\n    return tokens is None or valid_lens is not None","tryCatchPattern":null,"preventionTips":["Build tokens and valid_lens in the same loop; never set one without the other"],"tags":["kv-cache","missing-argument","ragged-tensor","validation"],"backgroundTag":"missing-required-parameter","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}