{"record":{"id":"61ad60528640012c","repo":"sgl-project/sglang","slug":"qkv-proj-weight-name-unexpected-shape-tuple-lo","errorCode":null,"errorMessage":"qkv_proj weight {name}: unexpected shape {tuple(loaded_weight.shape)}; expected sharded {tuple(param.shape)}","messagePattern":"qkv_proj weight (.+?): unexpected shape (.+?); expected sharded (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/mimo_v2.py","lineNumber":129,"sourceCode":"        raise ValueError(\n            f\"MiMoV2 fused qkv_proj checkpoint is TP={expected_fused_tp_size}-\"\n            f\"interleaved; got attention tp_size={tp_size} while loading {name}.\"\n        )\n\n    is_scale_inv = \"weight_scale_inv\" in name\n\n    if is_scale_inv and ckpt_tp != tp_size:\n        if deferred_scale_inv is not None:\n            deferred_scale_inv[name] = loaded_weight.clone()\n            return\n        raise ValueError(\n            f\"qkv_proj scale_inv {name}: shape mismatch \"\n            f\"{tuple(loaded_weight.shape)} vs {tuple(param.shape)} \"\n            f\"due to block quantization ceiling; pass deferred_scale_inv dict\"\n        )\n\n    if loaded_weight.ndim != param.ndim or loaded_weight.shape[1:] != param.shape[1:]:\n        raise ValueError(\n            f\"qkv_proj weight {name}: unexpected shape {tuple(loaded_weight.shape)}; \"\n            f\"expected sharded {tuple(param.shape)}\"\n        )\n\n    if tp_size == ckpt_tp:\n        fused_shape = (param.shape[0] * tp_size, *param.shape[1:])\n        if tuple(loaded_weight.shape) != fused_shape:\n            raise ValueError(\n                f\"qkv_proj weight {name}: unexpected shape \"\n                f\"{tuple(loaded_weight.shape)}; expected fused {fused_shape} \"\n                f\"or sharded {tuple(param.shape)}\"\n            )\n        default_weight_loader(param, loaded_weight.chunk(tp_size, dim=0)[tp_rank])\n    else:\n        shards_per_rank = ckpt_tp // tp_size\n        shards = loaded_weight.chunk(ckpt_tp, dim=0)\n        merged = torch.cat(\n            shards[tp_rank * shards_per_rank : (tp_rank + 1) * shards_per_rank],","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/mimo_v2.py#L111-L147","documentation":"The qkv_proj weight tensor loaded from the checkpoint has a different number of dimensions or trailing dimensions than the target parameter after accounting for TP sharding. The loader cannot map such a tensor onto the fused-qkv parameter.","triggerScenarios":"loaded_weight.ndim != param.ndim or loaded_weight.shape[1:] != param.shape[1:] in load_mimo_v2_qkv_proj_weight — e.g. a 3-D/transposed checkpoint tensor, or a checkpoint whose hidden dimension differs from config hidden_size.","commonSituations":"Loading a checkpoint fine-tuned or converted for a different config (hidden_size mismatch), corrupted safetensors, or a non-fused q/k/v layout fed into the fused-qkv loader.","solutions":["Verify checkpoint hidden_size matches the model config","Re-convert/re-export the checkpoint so q/k/v weights are fused in the qkv_proj layout the model expects","If the tensor is transposed/reshaped, fix the conversion script so ndim and trailing dims match param.shape[1:]"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"w = checkpoints[name]\nif w.ndim != param.ndim or w.shape[1:] != param.shape[1:]:\n    raise SystemExit(f'bad tensor {name}: {tuple(w.shape)} vs {tuple(param.shape)}')","typeGuard":"def tensor_fits(w: torch.Tensor, param: torch.Tensor) -> bool:\n    return w.ndim == param.ndim and w.shape[1:] == param.shape[1:]","tryCatchPattern":null,"preventionTips":["Dry-run shape comparison against params_dict before loading","Validate hidden_size in config vs checkpoint before launch"],"tags":["weight-loading","shape-mismatch","checkpoint","tensor-parallel"],"backgroundTag":"weight-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}