{"record":{"id":"269635c31b0e313f","repo":"sgl-project/sglang","slug":"out-must-be-contiguous-269635","errorCode":null,"errorMessage":"`out` must be contiguous.","messagePattern":"`out` must be contiguous\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/helion/kda_decode.py","lineNumber":250,"sourceCode":"    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,\n            A_log,\n            dt_bias,\n            initial_state,\n            out,\n            ssm_state_indices,\n        )\n    ):\n        raise ValueError(\"All inputs must be on the same device.\")\n\n    B = mixed_qkv.shape[0]\n    if a.shape[0] != B or b.shape[0] != B:","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/helion/kda_decode.py#L232-L268","documentation":"The output tensor must be fully contiguous because the Triton kernel writes it with flat offsets. A non-contiguous out (overlapping or strided storage) would produce incorrect results, so it is rejected before launch.","triggerScenarios":"Passing an out tensor that is a transposed/sliced view or has non-standard strides.","commonSituations":"Preallocating out as a view of a larger buffer; passing a tensor sliced from an output cache.","solutions":["Allocate out with torch.empty_like/empty of the exact shape (contiguous)","Or call out = out.contiguous() before the call (note: writes won't propagate back to the original view)"],"exampleFix":"# before\nout = buf[:, 0]  # strided view\ndecode(..., out=out, ...)\n# after\nout = torch.empty(B, out_dim, device=qkv.device, dtype=qkv.dtype)\ndecode(..., out=out, ...)","handlingStrategy":"validation","validationCode":"if not out.is_contiguous():\n    out = torch.empty_like(out, memory_format=torch.contiguous_format)","typeGuard":"def safe_out(o: torch.Tensor) -> torch.Tensor:\n    return o if o.is_contiguous() else o.contiguous().clone()","tryCatchPattern":null,"preventionTips":["Always allocate out with torch.empty in the wrapper","Never pass output views into Triton kernels"],"tags":["kda","mamba","contiguity","output-buffer","helion"],"backgroundTag":"non-contiguous-tensor","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}