sgl-project/sglang · error · ValueError
kv-canary: expected input tensors are required when enable_w
Error message
kv-canary: expected input tensors are required when enable_write_input_assert=True
What it means
When enable_write_input_assert=True the write kernel optionally cross-checks the incoming input_ids/positions against caller-supplied expected tensors; both expected_input_tokens and expected_input_positions must then be provided. Omitting them leaves the assert mode unusable, so the launcher raises.
Source
Thrown at python/sglang/kernels/ops/kv_canary/write.py:203
"""
canary_buf = context.canary_buf
real_kv_sources = context.real_kv_sources
if len(real_kv_sources) > consts.MAX_REAL_KV_SOURCES:
raise ValueError(
f"kv-canary: at most {consts.MAX_REAL_KV_SOURCES} RealKvSource entries supported by the CUDA ABI, "
f"got {len(real_kv_sources)}"
)
_assert_contiguous(canary_buf, "canary_buf")
_assert_contiguous(plan.write_offsets, "plan.write_offsets")
_assert_contiguous(plan.write_seed_slot_indices, "plan.write_seed_slot_indices")
_assert_contiguous(plan.write_num_valid_reqs, "plan.write_num_valid_reqs")
_assert_contiguous(input_ids, "input_ids")
_assert_contiguous(positions, "positions")
_assert_contiguous(out_cache_loc, "out_cache_loc")
if enable_write_input_assert:
if expected_input_tokens is None or expected_input_positions is None:
raise ValueError(
"kv-canary: expected input tensors are required when enable_write_input_assert=True"
)
_assert_contiguous(expected_input_tokens, "expected_input_tokens")
_assert_contiguous(expected_input_positions, "expected_input_positions")
else:
if expected_input_tokens is not None or expected_input_positions is not None:
raise ValueError(
"kv-canary: expected input tensors must be None when enable_write_input_assert=False"
)
_assert_contiguous(context.violation_ring, "violation_ring")
_assert_contiguous(context.violation_write_index, "violation_write_index")
_assert_contiguous(context.slot_run_counter, "slot_run_counter")
_assert_contiguous(context.kernel_run_counter, "kernel_run_counter")
_assert_contiguous(
context.enable_chain_position_assert, "enable_chain_position_assert"
)
padded_bufs, source_params = _build_real_kv_source_abi(View on GitHub (pinned to 0132848349)
Solutions
- Pass both expected_input_tokens and expected_input_positions when enable_write_input_assert=True
- If you do not need the cross-check, set enable_write_input_assert=False and pass neither tensor
- Check wrapper signatures for a default of None silently dropping the tensors
Example fix
# before
launch_canary_write_kernel(ctx, plan, ..., enable_write_input_assert=True)
# after
launch_canary_write_kernel(ctx, plan, ..., enable_write_input_assert=True,
expected_input_tokens=exp_tokens, expected_input_positions=exp_positions) Defensive patterns
Strategy: validation
Validate before calling
if enable_write_input_assert:
assert expected_input_tokens is not None and expected_input_positions is not None Type guard
def assert_inputs_consistent(flag: bool, t, p) -> bool:
return (flag and t is not None and p is not None) or (not flag and t is None and p is None) Prevention
- Derive flag and tensors from one config branch
- Write a tiny wrapper that fills defaults so callers cannot half-specify
When it happens
Trigger: Calling launch_canary_write_kernel(..., enable_write_input_assert=True) with expected_input_tokens=None or expected_input_positions=None (only one or neither supplied).
Common situations: Enabling the assert flag from config but forgetting to thread the expected tensors through a wrapper; refactoring call sites where the assert was previously off.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 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/23f24766ecda7758.
Report an issue: GitHub.