Skip to content

Unify and refactor Megatron-FSDP documentation.#4418

Merged
ericharper merged 10 commits into
NVIDIA:mainfrom
cspades:cye/mfsdp-doc-unify
Apr 29, 2026
Merged

Unify and refactor Megatron-FSDP documentation.#4418
ericharper merged 10 commits into
NVIDIA:mainfrom
cspades:cye/mfsdp-doc-unify

Conversation

@cspades

@cspades cspades commented Apr 21, 2026

Copy link
Copy Markdown
Member

What does this PR do ?

  • Unify the documentation for Megatron-FSDP.

Usage

To build the docs:

SKIP_AUTODOC=true SKIP_PUBLIC_DOCS_FEATURES=true uv run --only-group docs sphinx-autobuild . _build/html --port 8080 --host 127.0.0.1

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.

@cspades cspades self-assigned this Apr 21, 2026
@cspades cspades requested review from a team as code owners April 21, 2026 22:51
@svcnvidia-nemo-ci svcnvidia-nemo-ci marked this pull request as draft April 21, 2026 22:51
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically converted to draft because all PRs must start as drafts.

When you are ready for review, click Ready for Review to begin the review process. This will:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@copy-pr-bot

copy-pr-bot Bot commented Apr 21, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added this to the Core 0.16 milestone Apr 21, 2026
@cspades cspades added module: documentation Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. docs-only documentation only (docs or docstrings) module: megatron-fsdp labels Apr 21, 2026
@cspades cspades marked this pull request as ready for review April 21, 2026 22:57
@svcnvidia-nemo-ci svcnvidia-nemo-ci requested a review from a team April 21, 2026 22:57
@cspades cspades force-pushed the cye/mfsdp-doc-unify branch from 8a3395c to 6cdf25c Compare April 21, 2026 22:58
@svcnvidia-nemo-ci svcnvidia-nemo-ci added complexity: medium and removed docs-only documentation only (docs or docstrings) labels Apr 21, 2026
Comment thread examples/megatron_fsdp/README.md

@wujingyue wujingyue 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 in general. Thanks for consolidating the docs!

Comment thread megatron/core/distributed/fsdp/src/README.md
Comment thread docs/user-guide/features/megatron_fsdp.md

## Megatron-FSDP Feature Guide & API

| Optimization | Description | Config |

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.

I'm not so sure about the purpose of this table.

If it's for developers, it misses many key optimizations such as double buffering.

If it's for the user, do you expect users to proactively tune these configs? Many if not all of them should be by default on.

@cspades cspades Apr 22, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These are MLM arguments, they should definitely not be turned on by default. Default should be DDP.

These are the bare minimum arguments someone would want to turn on to use Megatron-FSDP.

Technically, very recent PR's make it so that the following are optional:

  • --ckpt-format fsdp_dtensor
  • --use-distributed-optimizer
  • --fsdp-manual-registration

but I need to let them stew for a bit before I document this. Plus, they are informative. We should be able to soon reduce the number of configs needed to use FSDP.

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.

Got it.

To make sure I understood you, there are three mutually exclusive ways to enable MFSDP:

  1. MLM
  2. FullyShardedDataParallel
  3. fully_shard
    Here you are listing the flags for just the first way. Correct?

@cspades cspades Apr 22, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, except it's more like:

  • MLM / FullyShardedDataParallel (Adapter, equivalent to MCore's DDP wrapper.)
    • We might still need an adapter like this, even after the rewrite, though we simultaneously want something more modular with MiMo, so we need to code it out and see what it looks like.
  • fully_shard

Both initialize MegatronFSDP.

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.

Could the doc somehow reflect that? To a new user or developer like me, it's not immediately clear that there are two disjoint ways of using MFSDP and which configs are for which way. Maybe the doc can have an API section where we talk about FullyShardedDataParallel (including its configs) and fully_shard (including its configs) in separate subsections. Then, the doc can talk about optimizations and implementation details.

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.

This will also clarify my other question, which might not be obvious to a new user. I think FullyShardedDataParallel is deeply integrated to MCore but fully_shard is not (in fact designed not to be).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I'll add another column to our tables that clarifies fully-shard vs. MCore arguments, I really want this current design where the explanation is very close to the arguments, and the arguments are at the beginning of every section.

Comment thread docs/user-guide/features/megatron_fsdp.md Outdated
Comment thread megatron/core/distributed/fsdp/src/README.md
@sbhavani

Copy link
Copy Markdown
Contributor

CC @megnvidia for technical documentation review

Comment thread docs/discussions/README.md Outdated
Comment thread docs/user-guide/parallelism-guide.md Outdated
Comment thread examples/megatron_fsdp/README.md
Comment thread megatron/core/distributed/README.md Outdated
Comment thread docs/user-guide/parallelism-guide.md Outdated
Signed-off-by: Cory Ye <cye@nvidia.com>
Comment thread docs/user-guide/parallelism-guide.md Outdated
- **Buffer Management**: Efficient use of storage and [user buffer registration with NCCL](https://docs.nvidia.com/deeplearning/nccl/user-guide/docs/usage/bufferreg.html#user-buffer-registration) allows Megatron-FSDP to leverage **NCCL Symmetric Memory**, introduced in NCCL `v2.27`, which enables switch offloading for **Multi-Node NVLink (MNNVL)** systems such as `GB200` / `GB300`, as well as other optimizations such as high-precision reduction collectives and zero-`COPY`.
- **Communication Overlap**: `All-Gather` (AG) and `Reduce-Scatter` (RS) collectives are optimized to be precisely overlapped with compute using various CUDA streams.
- **[TransformerEngine](https://github.com/NVIDIA/TransformerEngine) Mixed-Precision & Fused Kernels**: Native performance- and memory-optimal compatibility with MXFP8, NVFP4, and various other quantization recipes and fused kernels provided by TransformerEngine.
- **Optimized Communication & SM Utilization via SHARP**: Leverages [**SHARP** (Scalable Hierarchical Aggregation and Reduction Protocol)](https://docs.nvidia.com/networking/display/sharpv3130) to offload FSDP collectives to network switches (InfiniBand or NVLink-Switch) and significantly reduce utilization of GPU streaming multi-processors (SM) from 16-32 to 1-6, which lowers communication latency in large scaled-out workloads and frees up GPU-hosted processors for overlapped compute (GEMM) kernels. When FSDP sharding domains span both NVLink and InfiniBand, **hierarchical SHARP collectives** (NVL-SHARP and IB-SHARP) optimize communication paths across the entire system topology.

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.

I think we should document the following zero-copy optimizations we implement:

  1. Eliminate Parameter Copies Around Communication: Avoid redundant parameter copies before and after collectives, while remaining compatible with selected DTensor features such as torch distributed. checkpointing (Add to the Advanced Bucketing section.)
  2. Zero-Copy Communication via NCCL-UBR: Enable direct communication into NCCL-managed memory through NCCL User Buffer Registration (NCCL-UBR), achieving true zero-copy data movement. (Add to the Optimized Communication & SM Utilization via SHARP section.)
  3. Gradient Copy Avoidance with TransformerEngine: Leverage TransformerEngine’s fuse_wgrad_accumulation to eliminate intermediate gradient copies during backward pass. (to be documented under the TransformerEngine section.)

Could we also add support for Hybrid FSDP + outer-dp operates in ZeRO-1 mode? This would provide a more flexible and efficient trade-off between memory footprint and communication overhead.

Note on Communication Overlap: AG/RS overlap with compute does not demonstrate a clear advantage over other ZeRO-DP approaches in practice. This feature may be omitted unless further differentiation is demonstrated.

Comment thread docs/user-guide/features/megatron_fsdp.md
Signed-off-by: Cory Ye <cye@nvidia.com>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Apr 29, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added Approved All necessary approvals have been made and removed Final Review PR is in the "final review" stage labels Apr 29, 2026
@ericharper ericharper enabled auto-merge April 29, 2026 04:15
@ericharper ericharper added this pull request to the merge queue Apr 29, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/25132181038

Merged via the queue into NVIDIA:main with commit b23aa3f Apr 29, 2026
66 of 67 checks passed
yangbofun pushed a commit to xlm-research/Megatron-LM that referenced this pull request May 22, 2026
Signed-off-by: Cory Ye <cye@nvidia.com>
Co-authored-by: megnvidia <mmiranda@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made complexity: medium Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. module: documentation module: megatron-fsdp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants