{"record":{"id":"2639f00eff7694fb","repo":"sgl-project/sglang","slug":"kv-canary-expected-input-tensors-must-be-none-whe-2639f0","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_ref.py","lineNumber":93,"sourceCode":"    if slot_stride_i64 < 4:\n        raise ValueError(\n            f\"kv-canary: canary_buf slot stride must hold at least 4 int64 fields, got {slot_stride_i64}\"\n        )\n\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        expected_input_tokens_host = expected_input_tokens.detach().to(\n            device=work_device, dtype=torch.int64\n        )\n        expected_input_positions_host = expected_input_positions.detach().to(\n            device=work_device, dtype=torch.int64\n        )\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        expected_input_tokens_host = None\n        expected_input_positions_host = None\n\n    violation_rows: list[list[int]] = []\n    total_slots_written = 0\n\n    for r in range(active_reqs):\n        entry_start = int(write_offsets_host[r].item())\n        entry_end = int(write_offsets_host[r + 1].item())\n        entry_count = entry_end - entry_start\n        if entry_count <= 0:\n            continue\n\n        seed_slot = int(seed_slot_indices_host[r].item())\n        running_prev_hash = compute_slot_hash(buf_i64, seed_slot)\n","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kv_canary/write_ref.py#L75-L111","documentation":"With enable_write_input_assert=False the reference write kernel has no consumer for expected tensors, so supplying expected_input_tokens or expected_input_positions is treated as a configuration inconsistency and rejected, mirroring the CUDA launcher's check exactly.","triggerScenarios":"Calling launch_canary_write_kernel_torch_reference(..., enable_write_input_assert=False) while passing either expected tensor.","commonSituations":"Reusing a debug call site with tensors attached after flipping the flag off; generic wrappers that always forward expected tensors regardless of the flag.","solutions":["Remove the expected_* arguments when the flag is False","Or flip enable_write_input_assert to True to actually use them","Gate forwarding of expected tensors on the flag in wrappers"],"exampleFix":"# before\nlaunch_canary_write_kernel_torch_reference(ctx, plan, ..., enable_write_input_assert=False,\n    expected_input_tokens=t)\n# after\nlaunch_canary_write_kernel_torch_reference(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 ref_assert_args_ok(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":["Gate forwarding of expected tensors on the flag","Avoid copy-pasted debug call sites when flipping the flag"],"tags":["kv-canary","reference-implementation","mutually-exclusive"],"backgroundTag":"conflicting-arguments","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}