Repository navigation
Keep the MLA linear_q_proj plain without Q-LoRA unless the spec fuses a norm - #7973
pushkar-sarvam wants to merge 5 commits into
Conversation
… a norm With qk_layernorm on and q_lora_rank unset, QKNormConfigResolver replaced the plain linear_q_proj of the spec with a fused norm+linear. That adds a Q norm that models without Q-LoRA (DeepSeek-V2-Lite, Sarvam 105B) do not have, so their Hugging Face checkpoints no longer import. Before the resolver was added, the Q projection was plain; it is again, and a spec that selects a fused norm+linear still gets the Q norm. Claude-Session: https://claude.ai/code/session_016nXbwaPk93a8gkzorBeph4 Signed-off-by: pushkar-sarvam <pushkar@sarvam.ai>
Claude-Session: https://claude.ai/code/session_016nXbwaPk93a8gkzorBeph4 Signed-off-by: pushkar-sarvam <pushkar@sarvam.ai>
Claude-Session: https://claude.ai/code/session_016nXbwaPk93a8gkzorBeph4 Signed-off-by: pushkar-sarvam <pushkar@sarvam.ai>
Signed-off-by: pushkar-sarvam <pushkar@sarvam.ai>
Claude-Session: https://claude.ai/code/session_016nXbwaPk93a8gkzorBeph4 Signed-off-by: pushkar-sarvam <pushkar@sarvam.ai>
|
Hi @guihong-nv @janEbert, could one of you |
|
hey @guihong-nv @janEbert, just bringing this to the top - can you have a look at the PR? |
|
I think this is quite difficult. On the one hand, it's correct that Q also gets a norm when a setting called I would argue that it's more correct to give a Q norm when it's asked for ( Unless there's a mathematical reason that having |
|
Feel free to let me know if you disagree. I'll close this for now so we don't accidentally merge. |
What does this PR do?
Keeps the MLA
linear_q_projthat the layer spec asks for whenq_lora_rankisNoneandqk_layernormis on, instead of always replacing it with a fused norm+linear.Since #4452,
QKNormConfigResolver._resolve_mla_qk_layernormswapslinear_q_projforbackend.column_parallel_layer_norm_linear()whenever there is no Q-LoRA, although the GPT layer specs passbackend.column_parallel_linear(). That adds an RMSNorm on the Q path (linear_q_proj.layer_norm_weight) that MLA models without Q-LoRA do not have; in DeepSeek-V2-Lite and Sarvam 105B the query isq_proj(hidden_states). Up tocore_r0.18.0the projection was plain. With the fused default, Megatron-Bridge cannot import such Hugging Face checkpoints (the norm has no source weight), and models trained from scratch get a Q norm that their inference implementations lack.A spec that selects the fused norm+linear for
linear_q_projstill gets the Q norm, as the message in_raise_unused_q_normalready suggests. The KV path is unchanged.Testing:
tests/unit_tests/transformer/test_mla_qk_norm_config.pyfails onmainand passes with this change.tests/unit_tests/transformer/test_multi_latent_attention.pygives the same results with and without this change on one GPU. A small Sarvam MLA model imported through Megatron-Bridge with a plainlinear_q_projmatches the Hugging Face logits (relative L2 difference 5e-4 in FP32).Issue tracking
Linked issue: related to NVIDIA-NeMo/Megatron-Bridge#5261. Megatron-Bridge works around this for DeepSeek with an
MLASelfAttentionsubclass (NVIDIA-NeMo/Megatron-Bridge#5262); other MLA models without Q-LoRA, such as Moonlight and Sarvam 105B, still get the extra Q norm.Contribution process
Pre-checks
jit_fuser/torch.compile, CUDA extension, TE or external-library dispatch, or a scatter/index accumulation), I have added or updated its bit-exact determinism test and registered it intests/unit_tests/determinism/kernels/manifest.py(guide)