sgl-project/sglang · error · ValueError

`b` must have shape [B, HV] with HV={HV} (got b.shape={tuple

Error message

`b` must have shape [B, HV] with HV={HV} (got b.shape={tuple(b.shape)}).

What it means

The gate tensor b must have width HV (one scalar gate per value head), matching the head count of initial_state. This fires when b carries per-channel values (HV*K), per-query-head values (H), or is truncated.

Source

Thrown at python/sglang/kernels/ops/attention/fla/fused_recurrent.py:593

    if ssm_state_indices.shape[0] != B:
        raise ValueError(
            f"`ssm_state_indices` must have shape [B] (got {tuple(ssm_state_indices.shape)}; expected ({B},))."
        )

    if initial_state.ndim != 4:
        raise ValueError(
            f"`initial_state` must be a 4D tensor (got ndim={initial_state.ndim})."
        )
    if initial_state.stride(-1) != 1:
        raise ValueError("`initial_state` must be contiguous in the last dim.")
    HV, V, K = initial_state.shape[-3:]
    if a.shape[1] != HV * K:
        raise ValueError(
            f"`a` must have shape [B, HV*K] with HV={HV}, K={K} "
            f"(got a.shape={tuple(a.shape)})."
        )
    if b.shape[1] != HV:
        raise ValueError(
            f"`b` must have shape [B, HV] with HV={HV} (got b.shape={tuple(b.shape)})."
        )
    if A_log.numel() != HV:
        raise ValueError(f"`A_log` must have {HV} elements (got {A_log.numel()}).")
    if dt_bias.numel() != HV * K:
        raise ValueError(
            f"`dt_bias` must have {HV * K} elements (got {dt_bias.numel()})."
        )
    if out.shape != (B, 1, HV, V):
        raise ValueError(
            f"`out` must have shape {(B, 1, HV, V)} (got out.shape={tuple(out.shape)})."
        )

    qkv_dim = mixed_qkv.shape[1]
    qk_dim = qkv_dim - HV * V
    if qk_dim <= 0 or qk_dim % 2 != 0:
        raise ValueError(
            f"Invalid packed `mixed_qkv` last dim={qkv_dim} for HV={HV}, V={V}."

View on GitHub (pinned to 0132848349)

Solutions

  1. Slice b to exactly HV columns
  2. Verify split sizes: gate.split([HV*K, HV], dim=-1) for (a, b)
  3. Assert b.shape == (B, HV) from initial_state.shape[-3]

Example fix

# before
a, b = proj.split([HV*K, H], dim=-1)
# after
a, b = proj.split([HV*K, HV], dim=-1)
Defensive patterns

Strategy: validation

Validate before calling

HV = initial_state.shape[-3]
assert b.shape == (mixed_qkv.shape[0], HV), (b.shape, HV)

Prevention

When it happens

Trigger: b.shape[1] != HV, e.g. b sliced with the a-tensor's width, or built with query head count H in a GQA model.

Common situations: Incorrect split offsets in a fused gating projection; GQA models where H != HV and the wrong count is used for b.

Related errors


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