sgl-project/sglang · error · ValueError

`mixed_qkv` must be contiguous in the last dim.

Error message

`mixed_qkv` must be contiguous in the last dim.

What it means

The kernel reads mixed_qkv rows with unit stride in the last dimension; a non-contiguous last dim (e.g. a strided view or transpose) would produce wrong memory access. The validator enforces mixed_qkv.stride(-1) == 1.

Source

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


def validate_packed_decode_inputs(
    mixed_qkv: torch.Tensor,
    a: torch.Tensor,
    b: torch.Tensor,
    A_log: torch.Tensor,
    dt_bias: torch.Tensor,
    initial_state: torch.Tensor,
    out: torch.Tensor,
    ssm_state_indices: torch.Tensor,
) -> tuple[int, int, int, int, int]:
    """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.")

View on GitHub (pinned to 0132848349)

Solutions

  1. Call .contiguous() on mixed_qkv before the call
  2. Or allocate/produce mixed_qkv directly contiguous in the last dim

Example fix

# before
out = decode(mixed_qkv[:, :kdim], ...)
# after
qkv = mixed_qkv[:, :kdim].contiguous()
out = decode(qkv, ...)
Defensive patterns

Strategy: validation

Validate before calling

mixed_qkv = mixed_qkv.contiguous() if mixed_qkv.stride(-1) != 1 else mixed_qkv

Type guard

def last_dim_contiguous(t: torch.Tensor) -> bool:
    return t.stride(-1) == 1

Prevention

When it happens

Trigger: Passing a sliced or transposed mixed_qkv view where the last dim has stride > 1.

Common situations: Slicing a larger projection output tensor (qkv_buf[:, :D]); passing a transposed tensor from a fused kernel.

Related errors


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