sgl-project/sglang · error · ValueError

kv-canary: write_offsets_len must be positive, got {write_of

Error message

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

What it means

write_offsets_len describes the length of the write-offsets output array and must be strictly positive (it always holds at least one leading offset entry). A non-positive value means the output buffer metadata is malformed.

Source

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

    _require_dtype(req_to_token, "req_to_token", torch.int32)
    _require_dtype(lut_tensor, "lut_tensor", torch.int64)
    _require_dtype(
        out_verify_offsets_scratch, "out_verify_offsets_scratch", torch.int64
    )
    _require_dtype(out_write_offsets, "out_write_offsets", torch.int64)
    _require_dtype(
        out_write_seed_slot_indices, "out_write_seed_slot_indices", torch.int64
    )
    _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(

View on GitHub (pinned to 0132848349)

Solutions

  1. Allocate write_offsets with write_req_capacity + 1 elements and pass that as write_offsets_len
  2. Verify write_req_capacity is set to the real pool capacity before deriving lengths

Example fix

// before
write_offsets = torch.zeros(write_req_capacity, dtype=torch.int64, device=dev)
// after
write_offsets = torch.zeros(write_req_capacity + 1, dtype=torch.int64, device=dev)
Defensive patterns

Strategy: validation

Validate before calling

assert write_offsets_len == write_req_capacity + 1 and write_offsets_len > 0

Prevention

When it happens

Trigger: Calling launch_plan_offsets_kernel with write_offsets_len <= 0, usually because write_offsets was empty or the capacity variable used to derive the length was 0/negative.

Common situations: Miscomputing write_offsets_len as write_req_capacity instead of write_req_capacity + 1; passing an empty write_offsets tensor.

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