Skip to content

[Megatron-FSDP] Fix segmentation fault when using precision-aware optimizers with the updated MCore. - #3510

Merged
cspades merged 4 commits into
NVIDIA-NeMo:mainfrom
cspades:cye/mfsdp-decoup-grad-argfix
Apr 25, 2026
Merged

[Megatron-FSDP] Fix segmentation fault when using precision-aware optimizers with the updated MCore.#3510
cspades merged 4 commits into
NVIDIA-NeMo:mainfrom
cspades:cye/mfsdp-decoup-grad-argfix

Conversation

@cspades

@cspades cspades commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

What does this PR do ?

# export PYTHONFAULTHANDLER=1
# export CUDA_LAUNCH_BLOCKING=1
Current thread 0x0000fffff7ff47a0 (most recent call first):
  File "/usr/local/lib/python3.12/dist-packages/transformer_engine/pytorch/optimizers/multi_tensor_apply.py", line 21 in __call__
  File "/workspace/Megatron-Bridge/3rdparty/Megatron-LM/megatron/core/optimizer/clip_grads.py", line 190 in clip_grad_by_total_norm_fp32
  File "/workspace/Megatron-Bridge/3rdparty/Megatron-LM/megatron/core/optimizer/optimizer.py", line 232 in clip_grad_norm
  File "/workspace/Megatron-Bridge/3rdparty/Megatron-LM/megatron/core/optimizer/optimizer.py", line 635 in step

Testing

  • Tested in MLPerf container on single-node, and removing the megatron_fsdp_use_decoupled_grad config causes the segfault.
  • Add test to make sure FusedAdam(use_decoupled_grad), MegatronFSDP.param_and_grad_buffer.use_decoupled_grad, and clip_grad_norm(use_decoupled_grad) are all consistent and produce non-zero gradients.
  • Deleted a redundant checkpointing test in favor of save and resume with loss parity validation.
  • Had to fork Megatron-FSDP tests due to OOM on downstream test.
    • Didn't add a GB200 version yet, there is currently zero reason to add it, will add it when I add MXFP8 tests.

GitHub Actions CI

See the CI sectionin the Contributing doc for how to trigger the CI. A Nvidia developer will need to approve and trigger the CI for external contributors.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

If you haven't finished some of the above items you can still open "Draft" PR.

Additional Information

  • Related to # (issue)

@cspades

cspades commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

Either some corrupt global state / config (test OOM'ing on FusedAdam, which shouldn't be used) or something else. Debugging that test...

cspades added 4 commits April 24, 2026 18:14
…led_grad when FusedAdam is used.

Signed-off-by: Cory Ye <cye@nvidia.com>
Signed-off-by: Cory Ye <cye@nvidia.com>
Signed-off-by: Cory Ye <cye@nvidia.com>
@cspades
cspades force-pushed the cye/mfsdp-decoup-grad-argfix branch from c264ef7 to 8594fb8 Compare April 25, 2026 01:25
@cspades
cspades enabled auto-merge (squash) April 25, 2026 02:09
@cuichenx cuichenx added bug Something isn't working area:training Training loop, callbacks, and runtime integration needs-review PR is ready for code review and waiting on a reviewer labels Apr 25, 2026

@cuichenx cuichenx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cspades
cspades merged commit a8f6ce3 into NVIDIA-NeMo:main Apr 25, 2026
85 checks passed
@cuichenx cuichenx removed the needs-review PR is ready for code review and waiting on a reviewer label Apr 25, 2026
@pruprakash

Copy link
Copy Markdown
Contributor

QA RCCA Analysis

1. Fix Reference

2. Root Cause

Segmentation fault caused by passing param.decoupled_grad = None into clip_grad_norm -> multi_tensor_apply. Megatron-FSDP always uses a decoupled gradient when using TE.FusedAdam, but the flag wasn't being set correctly.

3. Trigger Configuration

  • Using Megatron-FSDP with precision-aware optimizers (FusedAdam)
  • Updated MCore version

4. Nature of the Bug

Classification: CODE BUG - Incorrect optimizer configuration causing segfault

5. Existing Test Coverage

In Fix PR: YES - 2 test files added/modified:

  • tests/functional_tests/launch_scripts/h100/active/L0_Launch_megatron_fsdp.sh
  • tests/functional_tests/test_groups/megatron_fsdp/test_megatron_fsdp.py

In NMFW Tests: Not specifically covering this precision-aware optimizer scenario

6. Coverage Assessment

Test Type Exists Covers Bug
Fix PR functional tests YES YES
Fix PR unit tests YES YES
NMFW regression tests NO N/A

7. New Regression Test

NOT NEEDED - Fix PR includes functional tests for Megatron-FSDP with precision-aware optimizers.

8. Conclusion

Verdict: ADEQUATE COVERAGE - Fix PR includes comprehensive functional tests.

vasunvidia pushed a commit to vasunvidia/Megatron-Bridge that referenced this pull request Jun 10, 2026
…imizers with the updated MCore. (NVIDIA-NeMo#3510)

Signed-off-by: Cory Ye <cye@nvidia.com>
Signed-off-by: Vasudevan Rengasamy <vrengasamy@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:training Training loop, callbacks, and runtime integration bug Something isn't working qa_rcca_done

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants