sgl-project/sglang · error · ValueError

kv-canary: verify_capacity must be non-negative, got {verify

Error message

kv-canary: verify_capacity must be non-negative, got {verify_capacity}

What it means

The verify-pool capacity passed to the offsets kernel must be non-negative; negative capacity cannot describe any pool and would corrupt the kernel's bounds computations.

Source

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

    )
    _require_dtype(out_verify_num_valid, "out_verify_num_valid", torch.int32)
    _require_dtype(out_verify_enable, "out_verify_enable", torch.int32)
    _require_dtype(out_write_num_valid_reqs, "out_write_num_valid_reqs", torch.int32)

    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)

View on GitHub (pinned to 0132848349)

Solutions

  1. Derive verify_capacity from verify_plan_out buffers or pool config and clamp at 0
  2. Log pool sizes at startup to catch negative capacities early

Example fix

// before
verify_capacity = total - write_capacity
// after
verify_capacity = int(verify_slot_indices.shape[0])  # or max(0, total - write_capacity)
Defensive patterns

Strategy: validation

Validate before calling

verify_capacity = max(0, int(verify_capacity))

Prevention

When it happens

Trigger: Calling launch_plan_offsets_kernel with verify_capacity < 0, typically from a pool-size calculation that underflowed or an uninitialized value.

Common situations: Spec-decode verify pool sized as (total - write_capacity) that underflows; a config typo yielding negative pool size.

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/25a193de82c0171b. Report an issue: GitHub.