{"record":{"id":"d0357e5ae44a11bd","repo":"sgl-project/sglang","slug":"attention-head-dim-must-be-positive","errorCode":null,"errorMessage":"attention_head_dim must be positive.","messagePattern":"attention_head_dim must be positive\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py","lineNumber":1811,"sourceCode":"            and get_tp_world_size() > 1\n            and not torch.compiler.is_compiling()\n            and not envs.SGLANG_CACHE_DIT_ENABLED\n            and not hasattr(self, \"_sglang_cache_dit_adapter\")\n            and not is_layerwise_offloaded_module(self)\n            and all(type(block) is MiniMaxH3DiTBlock for block in self.blocks)\n        )\n\n    def _validate_tp_config(\n        self, *, arch: MiniMaxH3DiTArchConfig, tp_size: int\n    ) -> None:\n        if tp_size <= 0:\n            raise ValueError(\"TP size must be positive.\")\n        if arch.num_attention_heads <= 0:\n            raise ValueError(\"num_attention_heads must be positive.\")\n        if arch.hidden_size <= 0:\n            raise ValueError(\"hidden_size must be positive.\")\n        if arch.attention_head_dim <= 0:\n            raise ValueError(\"attention_head_dim must be positive.\")\n        if arch.ffn_hidden_size <= 0:\n            raise ValueError(\"ffn_hidden_size must be positive.\")\n        for name, value in (\n            (\"num_attention_heads\", arch.num_attention_heads),\n            (\"hidden_size\", arch.hidden_size),\n            (\"ffn_hidden_size\", arch.ffn_hidden_size),\n            (\"time_embed_hidden_size\", arch.time_embed_hidden_size),\n            (\"adaln_out_features\", arch.adaln_out_features),\n            (\"final_adaln_out_features\", arch.final_adaln_out_features),\n            (\"video_patch_output_dim\", arch.latents_dim * math.prod(arch.patch_size)),\n            (\"audio_patch_output_dim\", arch.audio_latents_dim),\n        ):\n            if value % tp_size:\n                raise ValueError(\n                    f\"MiniMax H3 {name}={value} must be divisible by \"\n                    f\"TP size {tp_size}.\"\n                )\n","sourceCodeStart":1793,"sourceCodeEnd":1829,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py#L1793-L1829","documentation":"attention_head_dim must be positive because per-head projection sizes and the TP head split depend on it. The DiT validates this in _validate_tp_config at construction time and aborts on malformed configs.","triggerScenarios":"Constructing with an arch config whose attention_head_dim is 0/negative — typically a hand-written config or a bad checkpoint conversion (e.g. head_dim not derived from hidden_size/num_heads).","commonSituations":"Forgetting to set head_dim when authoring a config; computing head_dim = hidden_size // num_attention_heads with mismatched values that yield a remainder/zero; renamed JSON keys during conversion.","solutions":["Check attention_head_dim in the config and set it to hidden_size // num_attention_heads when the model uses equal head widths","Verify against the upstream checkpoint's expected value","Validate the whole arch config with a lint pass before model construction"],"exampleFix":"# before\nMiniMaxH3DiTArchConfig(..., attention_head_dim=0)\n# after\nMiniMaxH3DiTArchConfig(..., attention_head_dim=hidden_size // num_attention_heads)","handlingStrategy":"validation","validationCode":"assert arch.attention_head_dim > 0\nassert arch.hidden_size % arch.num_attention_heads == 0","typeGuard":"def head_dim_ok(arch) -> bool:\n    return getattr(arch, \"attention_head_dim\", 0) > 0","tryCatchPattern":null,"preventionTips":["Derive head_dim from hidden_size//heads when applicable","Diff converted configs against upstream"],"tags":["config","model-architecture","validation","minimax-h3"],"backgroundTag":"invalid-model-config","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}