{"record":{"id":"9f894a54bce66676","repo":"sgl-project/sglang","slug":"a-b-must-be-contiguous-in-the-last-dim-9f894a","errorCode":null,"errorMessage":"`a`/`b` must be contiguous in the last dim.","messagePattern":"`a`/`b` must be contiguous in the last dim\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/helion/kda_decode.py","lineNumber":239,"sourceCode":"    A_log: torch.Tensor,\n    dt_bias: torch.Tensor,\n    initial_state: torch.Tensor,\n    out: torch.Tensor,\n    ssm_state_indices: torch.Tensor,\n) -> tuple[int, int, int, int, int]:\n    \"\"\"Apply the shape and layout checks from SGLang's packed wrapper.\"\"\"\n    if mixed_qkv.ndim != 2:\n        raise ValueError(\n            f\"`mixed_qkv` must be a 2D tensor (got ndim={mixed_qkv.ndim}).\"\n        )\n    if mixed_qkv.stride(-1) != 1:\n        raise ValueError(\"`mixed_qkv` must be contiguous in the last dim.\")\n    if a.ndim != 2 or b.ndim != 2:\n        raise ValueError(\n            f\"`a` and `b` must be 2D tensors (got a.ndim={a.ndim}, b.ndim={b.ndim}).\"\n        )\n    if a.stride(-1) != 1 or b.stride(-1) != 1:\n        raise ValueError(\"`a`/`b` must be contiguous in the last dim.\")\n    if A_log.ndim != 1 or dt_bias.ndim != 1:\n        raise ValueError(\"`A_log`/`dt_bias` must be 1D tensors.\")\n    if A_log.stride(0) != 1 or dt_bias.stride(0) != 1:\n        raise ValueError(\"`A_log`/`dt_bias` must be contiguous.\")\n    if ssm_state_indices.ndim != 1:\n        raise ValueError(\n            \"`ssm_state_indices` must be 1D for packed decode \"\n            f\"(got ndim={ssm_state_indices.ndim}).\"\n        )\n    if not out.is_contiguous():\n        raise ValueError(\"`out` must be contiguous.\")\n\n    device = mixed_qkv.device\n    if any(\n        tensor.device != device\n        for tensor in (\n            a,\n            b,","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/helion/kda_decode.py#L221-L257","documentation":"The kernel requires a and b contiguous in their last dimension (stride(-1)==1) for coalesced loads; strided views would silently read wrong data otherwise, so validation rejects them.","triggerScenarios":"Passing a or b as a sliced/transposed view with last-dim stride != 1.","commonSituations":"Slicing per-head portions of a fused projection output; passing transposed tensors.","solutions":["Apply .contiguous() to a and b","Produce a/b from a fresh contiguous allocation"],"exampleFix":"# before\nout = decode(qkv, a[:, :d], b[:, :d], ...)\n# after\nout = decode(qkv, a[:, :d].contiguous(), b[:, :d].contiguous(), ...)","handlingStrategy":"validation","validationCode":"a = a.contiguous() if a.stride(-1) != 1 else a\nb = b.contiguous() if b.stride(-1) != 1 else b","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass sliced gate tensors directly; copy first","Add a contiguity pass in the decode prep function"],"tags":["kda","mamba","contiguity","helion"],"backgroundTag":"non-contiguous-tensor","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}