sgl-project/sglang · error · ValueError

kv-canary: req_to_token_stride0 must be positive, got {req_t

Error message

kv-canary: req_to_token_stride0 must be positive, got {req_to_token_stride0}

What it means

req_to_token_stride0 must be a positive int because the kernel multiplies row indices by it to address the req_to_token mapping; stride 0 or negative would alias rows or index backwards.

Source

Thrown at python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py:169

    if bs < 0 or bs > _PLAN_BS_BLOCK_SIZE:
        raise ValueError(
            f"kv-canary: offsets kernel bs must be in [0, {_PLAN_BS_BLOCK_SIZE}], got {bs}"
        )
    if write_offsets_len <= 0:
        raise ValueError(
            f"kv-canary: write_offsets_len must be positive, got {write_offsets_len}"
        )
    if write_req_capacity < 0:
        raise ValueError(
            f"kv-canary: write_req_capacity must be non-negative, got {write_req_capacity}"
        )
    if verify_capacity < 0:
        raise ValueError(
            f"kv-canary: verify_capacity must be non-negative, got {verify_capacity}"
        )
    if req_to_token_stride0 <= 0:
        raise ValueError(
            f"kv-canary: req_to_token_stride0 must be positive, got {req_to_token_stride0}"
        )
    if lut_len < 0:
        raise ValueError(f"kv-canary: lut_len must be non-negative, got {lut_len}")
    if not isinstance(has_swa_lut, bool):
        raise ValueError(
            f"kv-canary: has_swa_lut must be bool, got {type(has_swa_lut).__name__}"
        )
    if has_swa_lut and lut_len <= 0:
        raise ValueError("kv-canary: lut_len must be positive when has_swa_lut is True")
    if not has_swa_lut and lut_len != 0:
        raise ValueError("kv-canary: lut_len must be 0 when has_swa_lut is False")

    _require_len(req_pool_indices, "req_pool_indices", bs)
    _require_len(prefix_lens, "prefix_lens", bs)
    _require_len(extend_seq_lens, "extend_seq_lens", bs)
    _require_2d(req_to_token, "req_to_token")
    _require_min_len(lut_tensor, "lut_tensor", max(lut_len, 1))

View on GitHub (pinned to 0132848349)

Solutions

  1. Pass req_to_token_stride0 = int(req_to_token.stride(0))
  2. Ensure req_to_token is a properly allocated [max_reqs, max_context_len] tensor, not an empty expand()ed view

Example fix

// before
launch_plan_offsets_kernel(..., req_to_token_stride0=0)
// after
launch_plan_offsets_kernel(..., req_to_token_stride0=int(req_to_token.stride(0)))
Defensive patterns

Strategy: validation

Validate before calling

req_to_token_stride0 = int(req_to_token.stride(0))
assert req_to_token_stride0 > 0

Prevention

When it happens

Trigger: Calling launch_plan_offsets_kernel with req_to_token_stride0 <= 0 while req_to_token is a real 2-D tensor (its stride(0) is always > 0 for a non-empty tensor).

Common situations: Passing a default/sentinel 0 instead of int(req_to_token.stride(0)); an empty or broadcast req_to_token tensor whose stride collapsed.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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