sgl-project/sglang · error · ValueError

`a`/`b` must be contiguous in the last dim.

Error message

`a`/`b` must be contiguous in the last dim.

What it means

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.

Source

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

    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.")

    device = mixed_qkv.device
    if any(
        tensor.device != device
        for tensor in (
            a,
            b,

View on GitHub (pinned to 0132848349)

Solutions

  1. Apply .contiguous() to a and b
  2. Produce a/b from a fresh contiguous allocation

Example fix

# before
out = decode(qkv, a[:, :d], b[:, :d], ...)
# after
out = decode(qkv, a[:, :d].contiguous(), b[:, :d].contiguous(), ...)
Defensive patterns

Strategy: validation

Validate before calling

a = a.contiguous() if a.stride(-1) != 1 else a
b = b.contiguous() if b.stride(-1) != 1 else b

Prevention

When it happens

Trigger: Passing a or b as a sliced/transposed view with last-dim stride != 1.

Common situations: Slicing per-head portions of a fused projection output; passing transposed tensors.

Related errors


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