{"record":{"id":"cdbac7afb3ef8367","repo":"sgl-project/sglang","slug":"expected-hidden-size-to-be-self-hidden-size-but","errorCode":null,"errorMessage":"Expected hidden_size to be {self.hidden_size}, but found: {hidden_size}","messagePattern":"Expected hidden_size to be (.+?), but found: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/layernorm.py","lineNumber":162,"sourceCode":"\n        return out\n\n    def forward_native(\n        self,\n        x: torch.Tensor,\n        residual: Optional[torch.Tensor] = None,\n    ) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:\n        if not x.is_contiguous():\n            x = x.contiguous()\n        orig_dtype = x.dtype\n        x = x.to(torch.float32)\n        if residual is not None:\n            x = x + residual.to(torch.float32)\n            residual = x.to(orig_dtype)\n\n        hidden_size = x.shape[-1]\n        if hidden_size != self.hidden_size:\n            raise ValueError(\n                \"Expected hidden_size to be \"\n                f\"{self.hidden_size}, but found: {hidden_size}\"\n            )\n\n        if self.variance_size_override is None:\n            x_var = x\n        else:\n            if hidden_size < self.variance_size_override:\n                raise ValueError(\n                    \"Expected hidden_size to be at least \"\n                    f\"{self.variance_size_override}, but found: {hidden_size}\"\n                )\n\n            x_var = x[..., : self.variance_size_override]\n\n        if x.device.type == \"mps\" and self.variance_size_override is None:\n            weight = self.weight.to(dtype=torch.float32)\n            x = F.rms_norm(","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/layernorm.py#L144-L180","documentation":"RMSNorm.forward_native validates that the last dimension of the (residual-added) input equals the hidden_size the norm was constructed with. A mismatch means the model wiring feeds tensors of the wrong width into this layer.","triggerScenarios":"Calling forward_native (or forward_cuda/cpu/hip which delegate to it) with x.shape[-1] != self.hidden_size; also triggered when residual addition broadcasts a residual of different width.","commonSituations":"Model config hidden_size changed but norm modules were built from stale config; a projection feeding the norm outputs the wrong dim; copy-paste layer config mixing widths.","solutions":["Verify x.shape[-1] matches the hidden_size passed to RMSNorm's constructor","Fix the upstream projection to output hidden_size","Rebuild the model from the corrected config so all layers agree"],"exampleFix":"# before\nnorm = RMSNorm(hidden_size=1152)\nout = norm(x_1024)\n# after\nnorm = RMSNorm(hidden_size=1024)\nout = norm(x_1024)","handlingStrategy":"validation","validationCode":"assert x.shape[-1] == norm.hidden_size, (x.shape[-1], norm.hidden_size)","typeGuard":"def dims_match(x: torch.Tensor, norm) -> bool:\\n    return x.shape[-1] == norm.hidden_size","tryCatchPattern":null,"preventionTips":["Build all layers from one config object","Assert hidden sizes at model build time","Add shape checks in unit tests for each norm layer"],"tags":["layernorm","shape-mismatch","hidden-size","model-config"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}