sgl-project/sglang · error · ValueError

kv-canary: launch_plan_entries_kernel requires req_to_verify

Error message

kv-canary: launch_plan_entries_kernel requires req_to_verify_expected_tokens_valid_lens when req_to_verify_expected_tokens is set

What it means

When a req_to_verify_expected_tokens pool tensor is supplied, the entries kernel also needs its valid-lengths companion tensor so it knows how many entries per request are meaningful. Without valid_lens the kernel cannot safely read expected-token rows.

Source

Thrown at python/sglang/kernels/ops/kv_canary/plan/entries_kernel.py:51

    full_to_swa_index_mapping: Optional[torch.Tensor],
    verify_offsets_scratch: torch.Tensor,
    verify_enable: torch.Tensor,
    req_to_verify_expected_tokens: Optional[torch.Tensor],
    req_to_verify_expected_tokens_valid_lens: Optional[torch.Tensor],
    out_verify_slot_indices: torch.Tensor,
    out_verify_expected_tokens: torch.Tensor,
    out_verify_expected_positions: torch.Tensor,
    out_verify_prev_slot_indices: torch.Tensor,
    kv_token_id_vs_position_offset: int,
    swa_window_size: int,
) -> None:
    has_swa_lut = full_to_swa_index_mapping is not None
    has_verify_expected_token_pool = req_to_verify_expected_tokens is not None
    if (
        has_verify_expected_token_pool
        and req_to_verify_expected_tokens_valid_lens is None
    ):
        raise ValueError(
            "kv-canary: launch_plan_entries_kernel requires "
            "req_to_verify_expected_tokens_valid_lens when req_to_verify_expected_tokens is set"
        )
    module = _jit_plan_entries_module(has_swa_lut, has_verify_expected_token_pool)
    module.plan_entries(
        req_pool_indices,
        prefix_lens,
        req_to_token,
        full_to_swa_index_mapping,
        verify_offsets_scratch,
        verify_enable,
        req_to_verify_expected_tokens,
        req_to_verify_expected_tokens_valid_lens,
        out_verify_slot_indices,
        out_verify_expected_tokens,
        out_verify_expected_positions,
        out_verify_prev_slot_indices,
        int(kv_token_id_vs_position_offset),

View on GitHub (pinned to 0132848349)

Solutions

  1. Pass req_to_verify_expected_tokens_valid_lens (same bs, int32) together with the pool tensor
  2. If you don't need expected-token tracking, pass req_to_verify_expected_tokens=None

Example fix

// before
launch_plan_entries_kernel(..., req_to_verify_expected_tokens=pool, req_to_verify_expected_tokens_valid_lens=None)
// after
launch_plan_entries_kernel(..., req_to_verify_expected_tokens=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

Prevention

When it happens

Trigger: Calling launch_plan_entries_kernel (usually via launch_canary_plan_kernels) with req_to_verify_expected_tokens set but req_to_verify_expected_tokens_valid_lens=None.

Common situations: Adding expected-token tracking for spec-decode verification and passing the pool tensor but not the per-request valid length vector produced alongside it.

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


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/2bb675d3f6476cd7. Report an issue: GitHub.