sgl-project/sglang · error · ValueError
`A_log`/`dt_bias` must be contiguous.
Error message
`A_log`/`dt_bias` must be contiguous.
What it means
Same contiguity contract as the other inputs: the 1D A_log and dt_bias vectors must have stride(0) == 1. The wrapper raises when either parameter is a strided view, e.g. a column/row slice of a 2D parameter or a sub-selection of heads with gaps.
Source
Thrown at python/sglang/kernels/ops/attention/fla/fused_recurrent.py:295
ssm_state_indices: torch.Tensor,
use_qk_l2norm_in_kernel: bool = False,
) -> tuple[torch.Tensor, torch.Tensor]:
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(
f"`ssm_state_indices` must be 1D for packed decode (got ndim={ssm_state_indices.ndim})."
)
if not out.is_contiguous():
raise ValueError("`out` must be contiguous.")
dev = mixed_qkv.device
if any(
t.device != dev
for t in (a, b, A_log, dt_bias, initial_state, out, ssm_state_indices)
):
raise ValueError("All inputs must be on the same device.")
B = mixed_qkv.shape[0]
if a.shape[0] != B or b.shape[0] != B:
raise ValueError(
"Mismatched batch sizes: "View on GitHub (pinned to 0132848349)
Solutions
- Materialize compact copies: A_log = A_log.contiguous(); dt_bias = dt_bias.contiguous()
- Store A_log/dt_bias as separate flat parameters per rank instead of slicing packed buffers
Example fix
# before A_log = fused_param[:, 0] # stride 2 # after A_log = fused_param[:, 0].contiguous()
Defensive patterns
Strategy: validation
Validate before calling
A_log = A_log.contiguous() if A_log.stride(0) != 1 else A_log dt_bias = dt_bias.contiguous() if dt_bias.stride(0) != 1 else dt_bias
Type guard
def vec_contiguous(t: torch.Tensor) -> bool:
return t.ndim == 1 and t.stride(0) == 1 Prevention
- Never pass column slices of packed parameter buffers directly; copy them out
- After TP sharding, materialize per-rank parameter copies with .contiguous()
When it happens
Trigger: A_log = w[:, 0] on a (HV, 2) buffer (stride 2), selecting heads via an index tensor leaving non-unit stride, or params loaded as transposed views without materialization.
Common situations: Weight sharding across tensor-parallel ranks where A_log is sliced from a larger per-head buffer; fused parameter storage that packs A_log with other params; passing A_log.t() of a stored row.
Related errors
- `mixed_qkv` must be contiguous in the last dim.
- `a`/`b` must be contiguous in the last dim.
- `A_log`/`dt_bias` must be 1D tensors.
- `out` must be contiguous.
- `initial_state` must be contiguous in the last dim.
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/ad244d2815aec4f3.
Report an issue: GitHub.