sgl-project/sglang · error · ValueError
kv-canary: has_swa_lut must be bool, got {type(has_swa_lut).
Error message
kv-canary: has_swa_lut must be bool, got {type(has_swa_lut).__name__} What it means
has_swa_lut is a compile-time specialization flag for the JIT offsets kernel and must be a genuine Python bool, since the value is used to select which kernel variant is compiled and launched.
Source
Thrown at python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py:175
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,
)
_require_len(out_write_offsets, "out_write_offsets", write_offsets_len)View on GitHub (pinned to 0132848349)
Solutions
- Pass has_swa_lut = full_to_swa_index_mapping is not None (a real bool)
- Convert foreign boolean types with bool(...) before calling
Example fix
// before launch_plan_offsets_kernel(..., has_swa_lut=int(lut is not None)) // after launch_plan_offsets_kernel(..., has_swa_lut=lut is not None)
Defensive patterns
Strategy: type-guard
Validate before calling
has_swa_lut = bool(full_to_swa_index_mapping is not None)
Type guard
def as_kernel_flag(value) -> bool:
if not isinstance(value, bool):
raise TypeError(f"expected bool, got {type(value).__name__}")
return value Prevention
- Always pass `lut is not None` style expressions so the flag is a real bool
When it happens
Trigger: Calling launch_plan_offsets_kernel with has_swa_lut as a non-bool (e.g. 0/1, numpy bool, torch bool tensor, or None).
Common situations: Passing full_to_swa_index_mapping is not None directly without converting to bool, or forwarding a numpy/torch boolean from data pipelines.
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/f3b0c82c4cc15612.
Report an issue: GitHub.