{"record":{"id":"3c45ac0437455630","repo":"sgl-project/sglang","slug":"h3-conditioning-projection-w-has-shape-tuple-self","errorCode":null,"errorMessage":"H3 conditioning projection W has shape {tuple(self.weight.shape)}, expected ({self.input_dim}, {self.output_dim})","messagePattern":"H3 conditioning projection W has shape (.+?), expected \\((.+?), (.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"python/sglang/multimodal_gen/runtime/models/encoders/minimax_h3_qwen3vl.py","lineNumber":162,"sourceCode":"            layers.append(_FrozenLinear(weight, bias))\n            layer_input_dim = int(weight.shape[0])\n        if tensors:\n            raise ValueError(\n                \"H3 conditioning projection contains unsupported tensors: \"\n                f\"{sorted(tensors)}\"\n            )\n        if self.weight is None and not layers:\n            raise ValueError(\"H3 conditioning projection has neither W nor an MLP\")\n        if layers and layer_input_dim != self.output_dim:\n            raise ValueError(\n                f\"H3 conditioning projection MLP outputs width {layer_input_dim}, \"\n                f\"expected {self.output_dim}\"\n            )\n        if self.weight is not None and tuple(self.weight.shape) != (\n            self.input_dim,\n            self.output_dim,\n        ):\n            raise ValueError(\n                \"H3 conditioning projection W has shape \"\n                f\"{tuple(self.weight.shape)}, expected \"\n                f\"({self.input_dim}, {self.output_dim})\"\n            )\n        self.layers = nn.ModuleList(layers)\n\n    def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:\n        if int(hidden_states.shape[-1]) != self.input_dim:\n            raise ValueError(\n                f\"H3 conditioning projection expects width {self.input_dim}, \"\n                f\"got {int(hidden_states.shape[-1])}\"\n            )\n        normalized = (hidden_states.float() - self.mean_in) / self.std_in\n        projected = normalized @ self.weight if self.weight is not None else None\n        if self.layers:\n            residual = normalized.to(self.layers[0].weight.dtype)\n            for index, layer in enumerate(self.layers):\n                residual = layer(residual)","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/encoders/minimax_h3_qwen3vl.py#L144-L180","documentation":"The direct W matrix in the conditioning projection does not have shape (input_dim, output_dim). Since the projection maps encoder hidden states to the target width, any other shape makes the matmul impossible or wrong.","triggerScenarios":"MiniMaxH3ConditioningProjection constructed with a W tensor whose shape is not exactly (input_dim, output_dim) — commonly transposed weights or wrong-dimension checkpoint.","commonSituations":"See trigger scenarios.","solutions":["Print tuple(W.shape) and compare to (input_dim, output_dim); transpose if the checkpoint stores (output_dim, input_dim)","Re-export W in the expected orientation from the source model"],"exampleFix":"# before\nproj = MiniMaxH3ConditioningProjection({\"weight\": W.T}, input_dim=2048, output_dim=4096)\n# after\nsd = {\"weight\": W}  # ensure W.shape == (input_dim, output_dim)\nproj = MiniMaxH3ConditioningProjection(sd, input_dim=2048, output_dim=4096)","handlingStrategy":"validation","validationCode":"w = sd.get(\"weight\") or sd.get(\"W\")\nif w is not None:\n    assert tuple(w.shape) == (input_dim, output_dim), f\"W is {tuple(w.shape)}, want {(input_dim, output_dim)}; maybe transpose\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Document the expected orientation (input_dim, output_dim) in export scripts","Add a transpose fallback in your export tooling if the source stores the transpose"],"tags":["minimax-h3","conditioning-projection","shape-mismatch","transposed-weight"],"backgroundTag":"weight-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}