sgl-project/sglang · error · ValueError
kv-canary: lut_len must be non-negative, got {lut_len}
Error message
kv-canary: lut_len must be non-negative, got {lut_len} What it means
lut_len reports the length of the full-to-SWA LUT passed to the offsets kernel and must be non-negative; negative lengths indicate a shape extraction bug in the caller.
Source
Thrown at python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py:173
)
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))
_require_min_len(
out_verify_offsets_scratch,
"out_verify_offsets_scratch",
_PLAN_BS_BLOCK_SIZE + 1,View on GitHub (pinned to 0132848349)
Solutions
- Use the prepare helper that derives (lut, lut_len, has_swa_lut) from the tensor or None, guaranteeing non-negative lut_len
- Pass lut_len=0 with has_swa_lut=False when there is no LUT
Example fix
// before launch_plan_offsets_kernel(..., lut_len=-1, has_swa_lut=False) // after launch_plan_offsets_kernel(..., lut_len=0, has_swa_lut=False)
Defensive patterns
Strategy: validation
Validate before calling
lut_len = max(0, int(lut_len)) assert (lut_len > 0) == has_swa_lut or lut_len == 0
Prevention
- Derive lut_len from the tensor shape, never from arithmetic
When it happens
Trigger: Calling launch_plan_offsets_kernel with lut_len < 0 (usually derived from int(lut.shape[0]) of a malformed tensor or an arithmetic underflow).
Common situations: LUT length computed as (a - b) that underflows; passing -1 as a 'no LUT' sentinel instead of 0 with has_swa_lut=False.
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
- kv-canary: launch_canary_plan_kernels requires full_to_swa_i
- kv-canary: launch_canary_plan_kernels verify_capacity={verif
- kv-canary: launch_plan_entries_kernel requires req_to_verify
- kv-canary: write_offsets_len must be positive, got {write_of
- kv-canary: write_req_capacity must be non-negative, got {wri
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/32ef25ca632fd395.
Report an issue: GitHub.