{"record":{"id":"8c99a668999506ff","repo":"sgl-project/sglang","slug":"raw-q-proj-weight-has-shape-raw-q-shape-expecte","errorCode":null,"errorMessage":"raw q_proj.weight has shape {raw_q_shape}, expected ({H * D}, {hidden}); a width of {2 * H * D} means the gate is already fused — such artifacts must carry \"muse_glimmer_mlx_format\": {MUSE_GLIMMER_MLX_FORMAT_VERSION} in config.json","messagePattern":"raw q_proj\\.weight has shape (.+?), expected \\((.+?), (.+?)\\); a width of (.+?) means the gate is already fused — such artifacts must carry \"muse_glimmer_mlx_format\": (.+?) in config\\.json","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/hardware_backend/mlx/models/muse_glimmer_mlx.py","lineNumber":675,"sourceCode":"                f\"{len(missing)} missing keys {missing[:4]}\"\n                f\"{'...' if len(missing) > 4 else ''}, \"\n                f\"{len(unexpected)} unexpected keys {unexpected[:4]}\"\n                f\"{'...' if len(unexpected) > 4 else ''}{hint}\"\n            )\n\n        H = self.args.num_attention_heads\n        D = self.args.head_dim\n        hidden = self.args.hidden_size\n\n        embed_shape = tuple(weights[\"model.embed_tokens.weight\"].shape)\n        if embed_shape != (self.args.vocab_size, hidden):\n            raise ValueError(\n                f\"embed_tokens.weight has shape {embed_shape} but config says \"\n                f\"(vocab_size, hidden_size) = ({self.args.vocab_size}, {hidden})\"\n            )\n        raw_q_shape = tuple(weights[\"model.layers.0.self_attn.q_proj.weight\"].shape)\n        if raw_q_shape != (H * D, hidden):\n            raise ValueError(\n                f\"raw q_proj.weight has shape {raw_q_shape}, expected \"\n                f\"({H * D}, {hidden}); a width of {2 * H * D} means the gate \"\n                \"is already fused — such artifacts must carry \"\n                f'\"muse_glimmer_mlx_format\": {MUSE_GLIMMER_MLX_FORMAT_VERSION} in config.json'\n            )\n\n        new_weights = {}\n        for name, w in weights.items():\n            # mlx derives RoPE itself; drop cached buffers.\n            if \"rotary_emb\" in name:\n                continue\n            if any(marker in name for marker in _VISION_KEY_MARKERS):\n                continue\n            # Consumed below when its q_proj comes up.\n            if name.endswith(\"output_gate_proj.weight\"):\n                continue\n\n            # The reference computes rms_norm(x, weight + 1.0) for these four","sourceCodeStart":657,"sourceCodeEnd":693,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/hardware_backend/mlx/models/muse_glimmer_mlx.py#L657-L693","documentation":"For a raw (non-packaged) checkpoint, q_proj.weight must have shape (num_attention_heads * head_dim, hidden_size). If the observed width is exactly 2*H*D, the output gate has already been fused into q_proj, which means the artifact is packaged and its config.json must declare muse_glimmer_mlx_format.","triggerScenarios":"Loading fused q_proj weights (width 2*H*D) without the muse_glimmer_mlx_format marker in config.json, so sanitize takes the raw path and rejects the fused tensor shape.","commonSituations":"Downloading a pre-fused MLX artifact whose config.json is missing or stripped of the format marker, or renaming/repacking dirs and losing the marker.","solutions":["Add \\\"muse_glimmer_mlx_format\\\": <MUSE_GLIMMER_MLX_FORMAT_VERSION> to the artifact's config.json","Or use the original raw HF export where q_proj is unfused","Or repackage correctly so config and weights agree"],"exampleFix":"// before: fused q_proj (8192, 4096) with no marker in config.json\n// after: config.json gains\n\"muse_glimmer_mlx_format\": 1  // = MUSE_GLIMMER_MLX_FORMAT_VERSION","handlingStrategy":"validation","validationCode":"H, D, hid = cfg[\"num_attention_heads\"], cfg[\"head_dim\"], cfg[\"hidden_size\"]\nq = weights[\"model.layers.0.self_attn.q_proj.weight\"].shape\nif q[0] == 2 * H * D:\n    assert cfg.get(\"muse_glimmer_mlx_format\") is not None, \"fused weights need format marker\"","typeGuard":null,"tryCatchPattern":"try:\n    w = sanitize(weights)\nexcept ValueError as e:\n    if \"already fused\" in str(e):\n        cfg[\"muse_glimmer_mlx_format\"] = VERSION; w = sanitize(weights)","preventionTips":["Keep the packaged artifact's config intact with its weights","Detect fused width 2*H*D early and branch to the packaged path"],"tags":["shape-mismatch","fused-gate","packaging"],"backgroundTag":"checkpoint-format-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}