sgl-project/sglang · error · ValueError

{gate_name} has shape {tuple(g.shape)}, expected ({H * D}, {

Error message

{gate_name} has shape {tuple(g.shape)}, expected ({H * D}, {hidden})

What it means

When use_attn_output_gate is enabled, each layer's output_gate_proj.weight must have shape (num_attention_heads * head_dim, hidden_size) before being interleaved with q_proj per head. A gate tensor of any other shape fails this per-key check during sanitize.

Source

Thrown at python/sglang/srt/hardware_backend/mlx/models/muse_glimmer_mlx.py:703

            if "rotary_emb" in name:
                continue
            if any(marker in name for marker in _VISION_KEY_MARKERS):
                continue
            # Consumed below when its q_proj comes up.
            if name.endswith("output_gate_proj.weight"):
                continue

            # The reference computes rms_norm(x, weight + 1.0) for these four
            # norms; fold the +1 so plain nn.RMSNorm is exact.  model.norm
            # (MuseGlimmerFinalRMSNorm) is deliberately not offset.
            if name.endswith(_OFFSET_NORM_SUFFIXES):
                w = w + 1.0

            if name.endswith("q_proj.weight") and self.args.use_attn_output_gate:
                gate_name = name.replace("q_proj.weight", "output_gate_proj.weight")
                g = weights[gate_name]
                if tuple(g.shape) != (H * D, hidden):
                    raise ValueError(
                        f"{gate_name} has shape {tuple(g.shape)}, expected "
                        f"({H * D}, {hidden})"
                    )
                # Per-head interleave [q_head; gate_head]: (H*D, hidden) x2
                # -> (H, 2D, hidden) -> (2*H*D, hidden).
                w = mx.concatenate(
                    [w.reshape(H, D, hidden), g.reshape(H, D, hidden)], axis=1
                ).reshape(2 * H * D, hidden)

            new_weights[name] = w

        return new_weights


def _normalize_rc_layout(weights: dict) -> dict:
    """Rewrite RC multimodal keys to the raw text-only schema.

    Drops the vision tower/adapter/projection, strips the

View on GitHub (pinned to 0132848349)

Solutions

  1. Restore config.json's num_attention_heads/head_dim to the values the checkpoint was exported with
  2. Verify each layer's output_gate_proj.weight shape: should be (H*D, hidden)
  3. Re-download the checkpoint if the tensor itself is corrupt

Example fix

# before: config head_dim=128 -> expects (32*128, 4096) but tensor is (2048, 4096)
# after: set "head_dim": 64 (so H*D == 2048) to match the real tensors
Defensive patterns

Strategy: validation

Validate before calling

H, D, hid = cfg["num_attention_heads"], cfg["head_dim"], cfg["hidden_size"]
for k, g in weights.items():
    if k.endswith("output_gate_proj.weight"):
        assert tuple(g.shape) == (H * D, hid), k

Prevention

When it happens

Trigger: Loading a raw checkpoint where an output_gate_proj.weight tensor has an unexpected shape — e.g. head_dim or num_attention_heads changed in config after export, or a corrupted/mis-shaped gate shard.

Common situations: Editing head_dim/num_attention_heads in config.json without matching weights, mixing per-tensor-quantized artifacts that altered dims, or a bad shard merge producing wrong gate shapes.

Related errors


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