{"record":{"id":"e8f84eea1eb0f3a9","repo":"sgl-project/sglang","slug":"kv-canary-req-to-token-stride0-req-to-token-stri","errorCode":null,"errorMessage":"kv-canary: req_to_token_stride0={req_to_token_stride0} does not match req_to_token.stride(0)={int(req_to_token.stride(0))}","messagePattern":"kv-canary: req_to_token_stride0=(.+?) does not match req_to_token\\.stride\\(0\\)=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py","lineNumber":214,"sourceCode":"        \"out_write_seed_slot_indices\",\n        write_req_capacity,\n    )\n    _require_len(out_verify_num_valid, \"out_verify_num_valid\", 1)\n    _require_len(out_verify_enable, \"out_verify_enable\", 1)\n    _require_len(out_write_num_valid_reqs, \"out_write_num_valid_reqs\", 1)\n    _require_1d(lut_tensor, \"lut_tensor\")\n\n    if write_offsets_len != write_req_capacity + 1:\n        raise ValueError(\n            f\"kv-canary: write_offsets_len must equal write_req_capacity + 1, got \"\n            f\"{write_offsets_len} and {write_req_capacity}\"\n        )\n    if bs > write_req_capacity:\n        raise ValueError(\n            f\"kv-canary: bs={bs} exceeds write_req_capacity={write_req_capacity}\"\n        )\n    if req_to_token_stride0 != int(req_to_token.stride(0)):\n        raise ValueError(\n            f\"kv-canary: req_to_token_stride0={req_to_token_stride0} does not match \"\n            f\"req_to_token.stride(0)={int(req_to_token.stride(0))}\"\n        )\n\n    _require_same_device(\n        out_verify_offsets_scratch,\n        \"out_verify_offsets_scratch\",\n        (\n            (req_pool_indices, \"req_pool_indices\"),\n            (prefix_lens, \"prefix_lens\"),\n            (extend_seq_lens, \"extend_seq_lens\"),\n            (req_to_token, \"req_to_token\"),\n            (lut_tensor, \"lut_tensor\"),\n            (out_write_offsets, \"out_write_offsets\"),\n            (out_write_seed_slot_indices, \"out_write_seed_slot_indices\"),\n            (out_verify_num_valid, \"out_verify_num_valid\"),\n            (out_verify_enable, \"out_verify_enable\"),\n            (out_write_num_valid_reqs, \"out_write_num_valid_reqs\"),","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/kv_canary/plan/offsets_kernel.py#L196-L232","documentation":"The row stride must match the actual stride(0) of the req_to_token tensor so kernel address arithmetic matches memory layout. A mismatch (e.g. from a sliced, transposed, or expanded view) would read wrong rows.","triggerScenarios":"Calling launch_plan_offsets_kernel with req_to_token_stride0 != int(req_to_token.stride(0)) — passing a hardcoded max_context_len while the tensor is a non-contiguous view, or vice versa.","commonSituations":"req_to_token refactored to a slice/view of a larger mapping (e.g. for DP shards), changing its row stride while callers still pass the old constant.","solutions":["Always derive the argument: req_to_token_stride0 = int(req_to_token.stride(0))","If a contiguous layout is assumed, call req_to_token = req_to_token.contiguous() first and pass stride accordingly"],"exampleFix":"// before\nlaunch_plan_offsets_kernel(..., req_to_token_stride0=max_context_len)\n// after\nreq_to_token = req_to_token.contiguous()\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))\n# or enforce layout\nreq_to_token = req_to_token.contiguous()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call .contiguous() on req_to_token if layout assumptions changed"],"tags":["kv-canary","stride","layout"],"backgroundTag":"tensor-stride-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}