Validate num_attention_heads is divisible by num_query_groups in TransformerConfig - #5756
Validate num_attention_heads is divisible by num_query_groups in TransformerConfig#5756huthvincent wants to merge 1 commit into
Conversation
|
@huthvincent Want me to run CI/CD? |
|
/ok to test f6f5f53 |
f6f5f53 to
dd8db01
Compare
|
@cspades Sorry for the extra round. Right after your |
|
/ok to test dd8db01 |
|
@cspades Update on this one. CI caught a real regression in my earlier commit: the |
|
/ok to test 87ebbf1 |
|
Thanks for the fix. The divisibility check looks good. I think one blocking edge case remains. |
…sformerConfig An invalid grouped-query-attention configuration (for example num_attention_heads=32 with num_query_groups=5) previously passed config validation and crashed much later during the first forward pass with a cryptic view() shape error in attention.py. Raise a clear ValueError from TransformerConfig.__post_init__ instead. num_query_groups == 0 is now normalized to num_attention_heads, the same as None. This keeps minimal configs valid (num_attention_heads itself defaults to 0) and prevents a real attention config with an explicit num_query_groups=0 from reaching attention initialization with a zero query-group divisor. num_query_groups is then required to be a positive divisor of num_attention_heads whenever attention heads are present, so zero and negative values are rejected at construction time. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Rui Zhu <rui.zhu.rz399@yale.edu>
87ebbf1 to
15a230d
Compare
|
@guihong-nv Great catch, thank you. You are right that |
|
@cspades Sorry to bother you again. I pushed |
|
/ok to test 15a230d |
|
@huthvincent You can ping @NVIDIA/mcore-oncall and they'll help you! |
What does this PR do?
Rejects invalid grouped-query-attention configurations at config-construction time instead of letting them crash with a cryptic
view()shape error deep insideattention.py.TransformerConfig.__post_init__now raises a clearValueErrorwhen:num_query_groupsis not positive (previouslynum_query_groups=0passed validation because0 % tp_size == 0), ornum_attention_headsis not divisible bynum_query_groups(hard GQA requirement; the per-group head count is computed with floor division).Without this check, e.g.
num_attention_heads=32, num_query_groups=5constructs fine and then fails on the first forward pass with:Also updates one existing unit test (
test_trtllm_single_device_converter.py) that usednum_query_groups=0as a placeholder; it now usesnum_query_groups=num_attn_heads(plain MHA, matching the mocked weight layout).All existing in-tree configs and tests satisfy the new check (verified by grepping every
num_query_groupsusage inmegatron/andtests/).Issue tracking
Linked issue: Fixes #5755
Contribution process
Pre-checks
tests/unit_tests/transformer/test_transformer_config.py, 5 cases: valid GQA, default groups, non-divisible, groups > heads, non-positive)Local verification (single GPU):