{"record":{"id":"8b6916bba1d40f88","repo":"sgl-project/sglang","slug":"kv-canary-expected-input-tensors-must-be-none-whe","errorCode":null,"errorMessage":"kv-canary: expected input tensors must be None when enable_write_input_assert=False","messagePattern":"kv-canary: expected input tensors must be None when enable_write_input_assert=False","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/kv_canary/write.py","lineNumber":210,"sourceCode":"        )\n\n    _assert_contiguous(canary_buf, \"canary_buf\")\n    _assert_contiguous(plan.write_offsets, \"plan.write_offsets\")\n    _assert_contiguous(plan.write_seed_slot_indices, \"plan.write_seed_slot_indices\")\n    _assert_contiguous(plan.write_num_valid_reqs, \"plan.write_num_valid_reqs\")\n    _assert_contiguous(input_ids, \"input_ids\")\n    _assert_contiguous(positions, \"positions\")\n    _assert_contiguous(out_cache_loc, \"out_cache_loc\")\n    if enable_write_input_assert:\n        if expected_input_tokens is None or expected_input_positions is None:\n            raise ValueError(\n                \"kv-canary: expected input tensors are required when enable_write_input_assert=True\"\n            )\n        _assert_contiguous(expected_input_tokens, \"expected_input_tokens\")\n        _assert_contiguous(expected_input_positions, \"expected_input_positions\")\n    else:\n        if expected_input_tokens is not None or expected_input_positions is not None:\n            raise ValueError(\n                \"kv-canary: expected input tensors must be None when enable_write_input_assert=False\"\n            )\n    _assert_contiguous(context.violation_ring, \"violation_ring\")\n    _assert_contiguous(context.violation_write_index, \"violation_write_index\")\n    _assert_contiguous(context.slot_run_counter, \"slot_run_counter\")\n    _assert_contiguous(context.kernel_run_counter, \"kernel_run_counter\")\n    _assert_contiguous(\n        context.enable_chain_position_assert, \"enable_chain_position_assert\"\n    )\n\n    padded_bufs, source_params = _build_real_kv_source_abi(\n        real_kv_sources=real_kv_sources, device=canary_buf.device\n    )\n\n    module = _jit_canary_write_module()\n    module.canary_write_step_cuda(\n        canary_buf,\n        plan.write_offsets,","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kv_canary/write.py#L192-L228","documentation":"The mutually-exclusive counterpart of the assert-mode check: with enable_write_input_assert=False the kernel has no path that consumes expected tensors, so passing either expected_input_tokens or expected_input_positions is rejected to catch inconsistent configuration.","triggerScenarios":"Calling launch_canary_write_kernel(..., enable_write_input_assert=False, expected_input_tokens=t) (or with expected_input_positions) — tensors supplied while asserts are disabled.","commonSituations":"Toggling the assert flag off (for perf) while leaving the expected tensors wired in from a debug run; copy-pasted call sites with a stale flag.","solutions":["Set enable_write_input_assert=True if you actually want the cross-check","Otherwise drop the expected_* arguments from the call","Make the flag and the tensors derive from a single config branch so they cannot disagree"],"exampleFix":"# before\nlaunch_canary_write_kernel(ctx, plan, ..., enable_write_input_assert=False, expected_input_tokens=t)\n# after\nlaunch_canary_write_kernel(ctx, plan, ..., enable_write_input_assert=False)","handlingStrategy":"validation","validationCode":"if not enable_write_input_assert:\n    expected_input_tokens = expected_input_positions = None","typeGuard":"def assert_inputs_consistent(flag: bool, t, p) -> bool:\n    return (flag and t is not None and p is not None) or (not flag and t is None and p is None)","tryCatchPattern":null,"preventionTips":["Never forward expected tensors unconditionally from generic wrappers","Toggle flag and tensors together"],"tags":["kv-canary","argument-validation","mutually-exclusive"],"backgroundTag":"conflicting-arguments","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}