[Fix] Fix FLOPs accounting for non-MLA attention - #1980
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix FLOPs accounting so MLA projection/attention formulas are gated by
args.multi_latent_attention, not by Megatron's MLA argument defaults.Megatron registers MLA args globally, so non-MLA models can still have values such as
kv_lora_rank=32,qk_pos_emb_head_dim=64, andv_head_dim=128. The previous FLOPs utility treated those non-None/default values as proof that MLA was active, which caused regular MHA/GQA models to use MLA-style accounting.Evidence
A local
scripts/run-qwen3-4B.shrun with temporary branch logging showed a non-MLA GQA model entering MLA-style FLOPs branches:qwen3-4B.shconfigures GQA (--group-query-attention,--num-query-groups 8,--kv-channels 128) and does not enable--multi-latent-attention, so this is a metrics-only bug, not a model forward bug.Changes
multi_latent_attentiongate inslime/utils/flops_utils.py.Validation
Local-only validation, no test files added: