{"record":{"id":"fe0b0e12d9c5d168","repo":"sgl-project/sglang","slug":"ssm-state-indices-must-be-1d-for-packed-decode-fe0b0e","errorCode":null,"errorMessage":"`ssm_state_indices` must be 1D for packed decode (got ndim={ssm_state_indices.ndim}).","messagePattern":"`ssm_state_indices` must be 1D for packed decode \\(got ndim=(.+?)\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/helion/kda_decode.py","lineNumber":245,"sourceCode":"    \"\"\"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,\n            A_log,\n            dt_bias,\n            initial_state,\n            out,\n            ssm_state_indices,\n        )","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/helion/kda_decode.py#L227-L263","documentation":"ssm_state_indices maps each batch row to its state slot and must be a 1D tensor of length B for packed decode. Passing 2D indices (e.g. [B,1]) fails validation.","triggerScenarios":"Calling packed decode with ssm_state_indices of ndim != 1.","commonSituations":"Reusing request-to-cache index tensors shaped [B,1] from another backend; forgetting to flatten after a gather.","solutions":["Flatten: ssm_state_indices.view(-1) or .squeeze(-1)","Ensure the index tensor is produced as [B]"],"exampleFix":"# before\nout = decode(qkv, a, b, A_log, dt_bias, state, out, idx[:, None], ...)\n# after\nout = decode(qkv, a, b, A_log, dt_bias, state, out, idx.view(-1), ...)","handlingStrategy":"validation","validationCode":"ssm_state_indices = ssm_state_indices.view(-1)\nassert ssm_state_indices.ndim == 1","typeGuard":"def is_flat_indices(t: torch.Tensor) -> bool:\n    return t.ndim == 1","tryCatchPattern":null,"preventionTips":["Standardize on [B] index tensors in the state cache API","Flatten indices at creation site"],"tags":["kda","mamba","tensor-shape","state-indices","helion"],"backgroundTag":"invalid-tensor-shape","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}