sgl-project/sglang · error · ValueError
`A_log` must be a 1D tensor.
Error message
`A_log` must be a 1D tensor.
What it means
A_log (log decay magnitudes) must be a 1D tensor of length HV for the replaySSM decode kernel — one scalar per value head, shared across tokens. Multi-dim or scalar-wrapped tensors are rejected.
Source
Thrown at python/sglang/kernels/ops/attention/fla/fused_recurrent_linear_replayssm.py:484
Same call surface as the packed decode plus the three ring caches
(``d_cache`` / ``k_cache`` / ``g_cache``) and the per-decode-row
``write_pos`` cursor. ``initial_state`` is both the checkpoint read (h0)
and the (flush-only) checkpoint write (ht), in place.
Allocates nothing persistent: the caller owns the ring tensors and is
responsible for advancing / resetting ``write_pos`` (e.g. ``(write_pos+1) %
L`` after each step). This is a STANDALONE kernel; the memory-pool / cache
integration is a later phase.
"""
if mixed_qkv.ndim != 2:
raise ValueError(f"`mixed_qkv` must be 2D (got ndim={mixed_qkv.ndim}).")
if mixed_qkv.stride(-1) != 1:
raise ValueError("`mixed_qkv` must be contiguous in the last dim.")
if b.ndim != 2:
raise ValueError(f"`b` must be 2D (got b.ndim={b.ndim}).")
if A_log.ndim != 1:
raise ValueError("`A_log` must be a 1D tensor.")
if initial_state.ndim != 4:
raise ValueError(f"`initial_state` must be 4D (got ndim={initial_state.ndim}).")
if not out.is_contiguous():
raise ValueError("`out` must be contiguous.")
if write_pos.ndim != 1 or write_pos.dtype != torch.int32:
raise ValueError("`write_pos` must be a 1D int32 tensor.")
if force_flush is not None and (
force_flush.ndim != 1 or force_flush.dtype != torch.int32
):
raise ValueError("`force_flush` must be a 1D int32 tensor or None.")
B = mixed_qkv.shape[0]
num_state_slots, HV, V, K = initial_state.shape
qkv_dim = mixed_qkv.shape[1]
q_dim = (qkv_dim - HV * V) // 2
if q_dim <= 0 or q_dim % K != 0:
raise ValueError(
f"Invalid packed `mixed_qkv` last dim={qkv_dim} for HV={HV}, V={V}, K={K}."View on GitHub (pinned to 0132848349)
Solutions
- Squeeze/reshape A_log to exactly 1D: A_log.reshape(-1) (verify numel == HV)
- Load the checkpoint parameter and squeeze() any singleton dims
Example fix
// before A_log = ckpt['A_log'] # [1, HV] // after A_log = ckpt['A_log'].squeeze() # [HV], ndim==1
Defensive patterns
Strategy: validation
Validate before calling
A_log = A_log.reshape(-1) assert A_log.ndim == 1 and A_log.numel() == HV
Type guard
def is_1d_a_log(t: torch.Tensor, HV: int) -> bool:
return t.ndim == 1 and t.numel() == HV Prevention
- Squeeze checkpoint params at load time
- Add unit tests for param layouts
When it happens
Trigger: Passing A_log as [T, HV], [1, HV], or [B, HV] (kept a batch dim), or the raw parameter with extra dims from the checkpoint.
Common situations: Checkpoint params stored as [1, HV]; test fixtures generating batched decay tensors; reusing b's layout for A_log.
Related errors
- `mixed_qkv` must be 2D (got ndim={mixed_qkv.ndim}).
- `b` must be 2D (got b.ndim={b.ndim}).
- `initial_state` must be 4D (got ndim={initial_state.ndim}).
- `dt_bias` must have {HV * K} elements (got {dt_bias.numel()}
- Invalid packed Q size {q_dim}: must be divisible by K={K}. K
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/1b537fa8fae05859.
Report an issue: GitHub.