[megatron] fix: update patch for MLA flashattn forward#6005
[megatron] fix: update patch for MLA flashattn forward#6005wuxibin89 merged 1 commit intoverl-project:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Megatron mcore MLA (MultiLatentAttention) forward patch logic so it is only applied for mcore versions older than 0.16.2, aligning with the upstream fix merged into Megatron-LM.
Changes:
- Add an mcore version gate (
>= 0.16.2) to skip applying the localMultiLatentAttention.forwardpatch. - Refine THD packed-sequence handling by padding/slicing V only when Q/V head dims differ, tracking the original V dim for output slicing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request updates the Megatron-Core patching logic to support versions 0.16.2 and later, while refactoring the patch_forward method to handle cases where query and value head dimensions differ in THD packed sequences. The review feedback identifies a potential AttributeError when accessing configuration attributes and a logic regression where the DSA attention variant might incorrectly trigger post-attention reshaping. Suggestions were provided to use getattr for safer attribute access and to restore the exclusion of the DSA variant in the affected block.
Now NVIDIA/Megatron-LM@5dcda19 has already been merged into main, so the patch becomes optional when mcore version is greater than 0.16.2 Signed-off-by: Hollow Man <hollowman@opensuse.org>
What does this PR do?
Now NVIDIA/Megatron-LM@5dcda19 has already been merged into main, so the patch becomes optional when mcore version is greater or equal than 0.16.2
Checklist Before Starting
[{modules}] {type}: {description}(This will be checked by the CI){modules}includefsdp,megatron,veomni,sglang,vllm,rollout,trainer,ci,training_utils,recipe,hardware,deployment,ray,worker,single_controller,misc,perf,model,algo,env,tool,ckpt,doc,data,cfg,reward,fully_async,one_step_off,like[megatron, fsdp, doc]{type}is infeat,fix,refactor,chore,test[BREAKING]to the beginning of the title.[BREAKING][fsdp, megatron] feat: dynamic batchingTest
API and Usage Example
# Add code snippet or script demonstrating how to use thisDesign & Code Changes
Checklist Before Submitting
Important
Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.
pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=alwaysci-requestchannel in theverlSlack workspace. (If not accessible, please try the Feishu group (飞书群).)recipesubmodule, please also update the reference to the submodule commit viagit submodule update --remoteorcd recipe && git pull origin main.