sgl-project/sglang · error · ValueError
kv-canary: launch_canary_plan_kernels_torch_reference…
Error message
kv-canary: launch_canary_plan_kernels_torch_reference requires req_to_verify_expected_tokens_valid_lens when req_to_verify_expected_tokens is set
What it means
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.
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
Example fix
# before launch_ref(..., req_to_verify_expected_tokens=tok_pool, req_to_verify_expected_tokens_valid_lens=None) # after launch_ref(..., req_to_verify_expected_tokens=tok_pool, req_to_verify_expected_tokens_valid_lens=valid_lens)
Defensive patterns
Strategy: validation
Validate before calling
if req_to_verify_expected_tokens is not None:
assert req_to_verify_expected_tokens_valid_lens is not None Type guard
def has_expected_tokens_args(tokens, valid_lens):
return tokens is None or valid_lens is not None Prevention
- Build tokens and valid_lens in the same loop; never set one without the other
When it happens
Trigger: Calling launch_canary_plan_kernels_torch_reference(..., req_to_verify_expected_tokens=tokens, req_to_verify_expected_tokens_valid_lens=None).
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- v_cache must be provided
- --disagg-server-addr is required for --disagg-role
- Either num_inference_steps, sigmas, or timesteps must be…
- items must be provided
- kv-canary: launch_canary_plan_kernels_torch_reference…
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/18b1a9616918ca29.
Report an issue: GitHub.
Appendix: source
Thrown at python/sglang/kernels/ops/kv_canary/plan_ref.py:59
)
prefix_lens_host = prefix_lens.detach().to(device=work_device, dtype=torch.int64)
extend_seq_lens_host = extend_seq_lens.detach().to(
device=work_device, dtype=torch.int64
)
req_to_token_host = req_to_token.detach().to(device=work_device, dtype=torch.int64)
lut: Optional[torch.Tensor] = None
if full_to_swa_index_mapping is not None:
lut = full_to_swa_index_mapping.detach().to(device=work_device)
expected_token_pool_host: Optional[torch.Tensor] = None
req_to_verify_expected_tokens_valid_lens_host: Optional[torch.Tensor] = None
if req_to_verify_expected_tokens is not None:
expected_token_pool_host = req_to_verify_expected_tokens.detach().to(
device=work_device, dtype=torch.int64
)
if req_to_verify_expected_tokens_valid_lens is None:
raise ValueError(
"kv-canary: launch_canary_plan_kernels_torch_reference requires "
"req_to_verify_expected_tokens_valid_lens when req_to_verify_expected_tokens is set"
)
req_to_verify_expected_tokens_valid_lens_host = (
req_to_verify_expected_tokens_valid_lens.detach().to(
device=work_device, dtype=torch.int64
)
)
total_verify = _materialize_verify_entries(
verify_plan_out=verify_plan_out,
req_pool_indices_host=req_pool_indices_host,
prefix_lens_host=prefix_lens_host,
req_to_token_host=req_to_token_host,
swa_window_size=swa_window_size,
lut=lut,
verify_capacity=verify_capacity,
work_device=work_device,View on GitHub (pinned to 0132848349)