Skip to content

[DEV] fix(megatron-fsdp): compute SWiGLU/GDN split in item coordinates for non-DTensor optimizer states#4424

Closed
xuwchen wants to merge 2 commits into
NVIDIA:devfrom
xuwchen:fix_mfsdp_ckpt_save_dev
Closed

[DEV] fix(megatron-fsdp): compute SWiGLU/GDN split in item coordinates for non-DTensor optimizer states#4424
xuwchen wants to merge 2 commits into
NVIDIA:devfrom
xuwchen:fix_mfsdp_ckpt_save_dev

Conversation

@xuwchen

@xuwchen xuwchen commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

main PR: #4423

What does this PR do ?

split_swiglu_linear_fc1 and split_gdn_fused originally used data.numel() // tp_mesh.mesh.numel() to compute component slices (w_slice/v_slice for SWiGLU, comp_slice for GDN), then intersected them with fsdp_slice to determine each rank's portion. When data is a DTensor, data.numel() returns the global element count (=param.numel()), so component slices and fsdp_slice are both in item coordinates and the intersection is valid. However, when data is a plain Tensor (optimizer states created by FusedAdam), data.numel() returns the local shard size on this rank, making the component slices's range far smaller than the item coordinate space and resulting in an intersection across incompatible coordinate systems.

The fix replaces data.numel() with dist_param.numel() (dist_param is always a DTensor and therefore reflects the global element count), ensuring fsdp_slice and all component slices are in item coordinates.

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

Code review

Feel free to message or comment the @mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!

All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.

Step 1: Mark PR as "Ready for Review"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
Final Review might get declined if these requirements are not fulfilled.

Step 2: Final Review

For PRs that change megatron/core, once all expert reviewers have approved, the Final Review label is applied automatically and final reviewers are assigned.

For PRs outside megatron/core, this step is skipped.

Step 3: Approved

Once all required reviewers have approved, the Approved label is applied automatically.

Merge

Any member of mcore-engineers will be able to merge your PR.

For MRs into `dev` branch The proposed review process for `dev` branch is under active discussion.

MRs are mergable after one approval by either eharper@nvidia.com or zijiey@nvidia.com.

@xuwchen xuwchen requested review from a team as code owners April 22, 2026 14:00
@copy-pr-bot

copy-pr-bot Bot commented Apr 22, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@xuwchen

xuwchen commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 7ec906c

@xuwchen

xuwchen commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

The changes here have been incorporated into #4748, which is now merged. Closing this PR.

@xuwchen xuwchen closed this May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants