sgl-project/sglang · error · ValueError

embed_tokens.weight has shape {embed_shape} but config says

Error message

embed_tokens.weight has shape {embed_shape} but config says (vocab_size, hidden_size) = ({self.args.vocab_size}, {hidden})

What it means

During sanitize, the shape of model.embed_tokens.weight is compared against (vocab_size, hidden_size) from the config args. Any mismatch — different vocab, different hidden size, or transposed/damaged tensor — raises this error before any compute happens.

Source

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

                    " (weights look already fused: if this is a packaged "
                    'artifact, its config.json must carry "muse_glimmer_mlx_format": '
                    f"{MUSE_GLIMMER_MLX_FORMAT_VERSION})"
                )
            raise ValueError(
                "not a complete raw Muse Glimmer HF checkpoint: "
                f"{len(missing)} missing keys {missing[:4]}"
                f"{'...' if len(missing) > 4 else ''}, "
                f"{len(unexpected)} unexpected keys {unexpected[:4]}"
                f"{'...' if len(unexpected) > 4 else ''}{hint}"
            )

        H = self.args.num_attention_heads
        D = self.args.head_dim
        hidden = self.args.hidden_size

        embed_shape = tuple(weights["model.embed_tokens.weight"].shape)
        if embed_shape != (self.args.vocab_size, hidden):
            raise ValueError(
                f"embed_tokens.weight has shape {embed_shape} but config says "
                f"(vocab_size, hidden_size) = ({self.args.vocab_size}, {hidden})"
            )
        raw_q_shape = tuple(weights["model.layers.0.self_attn.q_proj.weight"].shape)
        if raw_q_shape != (H * D, hidden):
            raise ValueError(
                f"raw q_proj.weight has shape {raw_q_shape}, expected "
                f"({H * D}, {hidden}); a width of {2 * H * D} means the gate "
                "is already fused — such artifacts must carry "
                f'"muse_glimmer_mlx_format": {MUSE_GLIMMER_MLX_FORMAT_VERSION} in config.json'
            )

        new_weights = {}
        for name, w in weights.items():
            # mlx derives RoPE itself; drop cached buffers.
            if "rotary_emb" in name:
                continue
            if any(marker in name for marker in _VISION_KEY_MARKERS):

View on GitHub (pinned to 0132848349)

Solutions

  1. Fix config.json's vocab_size/hidden_size to match the actual embedding tensor
  2. Re-download the correct, unmodified checkpoint+config pair
  3. If the tensor is transposed/corrupted, re-export the safetensors

Example fix

// before: config vocab_size=32000, embed shape (128256, 4096)
// after: "vocab_size": 128256 in config.json
Defensive patterns

Strategy: validation

Validate before calling

emb = weights["model.embed_tokens.weight"].shape
assert tuple(emb) == (cfg["vocab_size"], cfg["hidden_size"])

Prevention

When it happens

Trigger: Loading weights whose embedding matrix dimensions don't match config.json, e.g. vocab_size=32000 in config but a 128256-row embedding, or hidden_size edited by hand.

Common situations: Mixing config.json from one model revision with weights from another (common with quantized/merged variants), typos in vocab_size/hidden_size, or truncated shard downloads.

Related errors


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