sgl-project/sglang · error · ValueError

`ssm_state_indices` must be 1D for packed decode (got ndim={

Error message

`ssm_state_indices` must be 1D for packed decode (got ndim={ssm_state_indices.ndim}).

What it means

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.

Source

Thrown at python/sglang/kernels/ops/attention/helion/kda_decode.py:245

    """Apply the shape and layout checks from SGLang's packed wrapper."""
    if mixed_qkv.ndim != 2:
        raise ValueError(
            f"`mixed_qkv` must be a 2D tensor (got ndim={mixed_qkv.ndim})."
        )
    if mixed_qkv.stride(-1) != 1:
        raise ValueError("`mixed_qkv` must be contiguous in the last dim.")
    if a.ndim != 2 or b.ndim != 2:
        raise ValueError(
            f"`a` and `b` must be 2D tensors (got a.ndim={a.ndim}, b.ndim={b.ndim})."
        )
    if a.stride(-1) != 1 or b.stride(-1) != 1:
        raise ValueError("`a`/`b` must be contiguous in the last dim.")
    if A_log.ndim != 1 or dt_bias.ndim != 1:
        raise ValueError("`A_log`/`dt_bias` must be 1D tensors.")
    if A_log.stride(0) != 1 or dt_bias.stride(0) != 1:
        raise ValueError("`A_log`/`dt_bias` must be contiguous.")
    if ssm_state_indices.ndim != 1:
        raise ValueError(
            "`ssm_state_indices` must be 1D for packed decode "
            f"(got ndim={ssm_state_indices.ndim})."
        )
    if not out.is_contiguous():
        raise ValueError("`out` must be contiguous.")

    device = mixed_qkv.device
    if any(
        tensor.device != device
        for tensor in (
            a,
            b,
            A_log,
            dt_bias,
            initial_state,
            out,
            ssm_state_indices,
        )

View on GitHub (pinned to 0132848349)

Solutions

  1. Flatten: ssm_state_indices.view(-1) or .squeeze(-1)
  2. Ensure the index tensor is produced as [B]

Example fix

# before
out = decode(qkv, a, b, A_log, dt_bias, state, out, idx[:, None], ...)
# after
out = decode(qkv, a, b, A_log, dt_bias, state, out, idx.view(-1), ...)
Defensive patterns

Strategy: validation

Validate before calling

ssm_state_indices = ssm_state_indices.view(-1)
assert ssm_state_indices.ndim == 1

Type guard

def is_flat_indices(t: torch.Tensor) -> bool:
    return t.ndim == 1

Prevention

When it happens

Trigger: Calling packed decode with ssm_state_indices of ndim != 1.

Common situations: Reusing request-to-cache index tensors shaped [B,1] from another backend; forgetting to flatten after a gather.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/fe0b0e12d9c5d168. Report an issue: GitHub.