sgl-project/sglang · critical · ValueError

attention_head_dim must be positive.

Error message

attention_head_dim must be positive.

What it means

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.

Source

Thrown at python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py:1811

            and get_tp_world_size() > 1
            and not torch.compiler.is_compiling()
            and not envs.SGLANG_CACHE_DIT_ENABLED
            and not hasattr(self, "_sglang_cache_dit_adapter")
            and not is_layerwise_offloaded_module(self)
            and all(type(block) is MiniMaxH3DiTBlock for block in self.blocks)
        )

    def _validate_tp_config(
        self, *, arch: MiniMaxH3DiTArchConfig, tp_size: int
    ) -> None:
        if tp_size <= 0:
            raise ValueError("TP size must be positive.")
        if arch.num_attention_heads <= 0:
            raise ValueError("num_attention_heads must be positive.")
        if arch.hidden_size <= 0:
            raise ValueError("hidden_size must be positive.")
        if arch.attention_head_dim <= 0:
            raise ValueError("attention_head_dim must be positive.")
        if arch.ffn_hidden_size <= 0:
            raise ValueError("ffn_hidden_size must be positive.")
        for name, value in (
            ("num_attention_heads", arch.num_attention_heads),
            ("hidden_size", arch.hidden_size),
            ("ffn_hidden_size", arch.ffn_hidden_size),
            ("time_embed_hidden_size", arch.time_embed_hidden_size),
            ("adaln_out_features", arch.adaln_out_features),
            ("final_adaln_out_features", arch.final_adaln_out_features),
            ("video_patch_output_dim", arch.latents_dim * math.prod(arch.patch_size)),
            ("audio_patch_output_dim", arch.audio_latents_dim),
        ):
            if value % tp_size:
                raise ValueError(
                    f"MiniMax H3 {name}={value} must be divisible by "
                    f"TP size {tp_size}."
                )

View on GitHub (pinned to 0132848349)

Solutions

  1. Check attention_head_dim in the config and set it to hidden_size // num_attention_heads when the model uses equal head widths
  2. Verify against the upstream checkpoint's expected value
  3. Validate the whole arch config with a lint pass before model construction

Example fix

# before
MiniMaxH3DiTArchConfig(..., attention_head_dim=0)
# after
MiniMaxH3DiTArchConfig(..., attention_head_dim=hidden_size // num_attention_heads)
Defensive patterns

Strategy: validation

Validate before calling

assert arch.attention_head_dim > 0
assert arch.hidden_size % arch.num_attention_heads == 0

Type guard

def head_dim_ok(arch) -> bool:
    return getattr(arch, "attention_head_dim", 0) > 0

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/d0357e5ae44a11bd. Report an issue: GitHub.