{"record":{"id":"26be4dcc46ca9176","repo":"sgl-project/sglang","slug":"kv-canary-req-to-token-stride0-must-be-positive","errorCode":null,"errorMessage":"kv-canary: req_to_token_stride0 must be positive, got {req_to_token_stride0}","messagePattern":"kv-canary: req_to_token_stride0 must be positive, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py","lineNumber":169,"sourceCode":"\n    if bs < 0 or bs > _PLAN_BS_BLOCK_SIZE:\n        raise ValueError(\n            f\"kv-canary: offsets kernel bs must be in [0, {_PLAN_BS_BLOCK_SIZE}], got {bs}\"\n        )\n    if write_offsets_len <= 0:\n        raise ValueError(\n            f\"kv-canary: write_offsets_len must be positive, got {write_offsets_len}\"\n        )\n    if write_req_capacity < 0:\n        raise ValueError(\n            f\"kv-canary: write_req_capacity must be non-negative, got {write_req_capacity}\"\n        )\n    if verify_capacity < 0:\n        raise ValueError(\n            f\"kv-canary: verify_capacity must be non-negative, got {verify_capacity}\"\n        )\n    if req_to_token_stride0 <= 0:\n        raise ValueError(\n            f\"kv-canary: req_to_token_stride0 must be positive, got {req_to_token_stride0}\"\n        )\n    if lut_len < 0:\n        raise ValueError(f\"kv-canary: lut_len must be non-negative, got {lut_len}\")\n    if not isinstance(has_swa_lut, bool):\n        raise ValueError(\n            f\"kv-canary: has_swa_lut must be bool, got {type(has_swa_lut).__name__}\"\n        )\n    if has_swa_lut and lut_len <= 0:\n        raise ValueError(\"kv-canary: lut_len must be positive when has_swa_lut is True\")\n    if not has_swa_lut and lut_len != 0:\n        raise ValueError(\"kv-canary: lut_len must be 0 when has_swa_lut is False\")\n\n    _require_len(req_pool_indices, \"req_pool_indices\", bs)\n    _require_len(prefix_lens, \"prefix_lens\", bs)\n    _require_len(extend_seq_lens, \"extend_seq_lens\", bs)\n    _require_2d(req_to_token, \"req_to_token\")\n    _require_min_len(lut_tensor, \"lut_tensor\", max(lut_len, 1))","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py#L151-L187","documentation":"req_to_token_stride0 must be a positive int because the kernel multiplies row indices by it to address the req_to_token mapping; stride 0 or negative would alias rows or index backwards.","triggerScenarios":"Calling launch_plan_offsets_kernel with req_to_token_stride0 <= 0 while req_to_token is a real 2-D tensor (its stride(0) is always > 0 for a non-empty tensor).","commonSituations":"Passing a default/sentinel 0 instead of int(req_to_token.stride(0)); an empty or broadcast req_to_token tensor whose stride collapsed.","solutions":["Pass req_to_token_stride0 = int(req_to_token.stride(0))","Ensure req_to_token is a properly allocated [max_reqs, max_context_len] tensor, not an empty expand()ed view"],"exampleFix":"// before\nlaunch_plan_offsets_kernel(..., req_to_token_stride0=0)\n// after\nlaunch_plan_offsets_kernel(..., req_to_token_stride0=int(req_to_token.stride(0)))","handlingStrategy":"validation","validationCode":"req_to_token_stride0 = int(req_to_token.stride(0))\nassert req_to_token_stride0 > 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never hardcode stride; always read it from the tensor"],"tags":["kv-canary","stride","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}