[Dev] Fix FSDP backward hooks for TE-fused experts#5636
Open
lhb8125 wants to merge 1 commit into
Open
Conversation
Signed-off-by: hongbinl <hongbinl@nvidia.com>
shjwudp
approved these changes
Jul 3, 2026
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
GroupedLinearpost-forward hooks to the TE op-fuser outputforward()callswith_kwargs=Truepost-forward hooks in the grouped-MLP unit testsRoot cause
The TE op-fuser path already forwards the original
GroupedLinearpre-forward hooks, but it bypasses their post-forward hooks. Megatron-FSDP uses those post-forward hooks to attach pre-backward all-gathers. Withoptim_grads_params, expert parameters released after forward could therefore remain unavailable when deferred grouped-wgrad ran, resulting in an illegal CUDA memory access.The non-op-fuser path continues to invoke
GroupedLinear.forward()normally and is unaffected.Test plan
CHECK_ONLY=true BASE_REF=dev bash tools/autoformat.sh(black, isort, pylint, and ruff passed)python tools/check_copyright.py megatron/core/transformer/moe/experts.py tests/unit_tests/transformer/moe/test_grouped_mlp.pyoptim_grads_params, paged stash, TE op fuser, and full-iteration CUDA graph: job20260702-082849-85c1completed 9 stable iterations with finite loss/grad norm, median 861.45 TFLOP/s/GPU, and 92,006 MB peak allocated memoryThe CI-faithful target unit-test launch did not reach pytest because the Lyris login node could not import
mcore-ci-dev:latestwithout registry/Enroot credentials; upstream CI should execute the added test.