Nemo Mbridge Perf Megatron Fsdp
NVIDIAOfficialPublished by NVIDIA
- Skill
- Tool integration
- Software development
- Apache-2.0
- Medium risk
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a comprehensive reference for enabling and troubleshooting Megatron FSDP (Fully Sharded Data Parallel) in Megatron-Bridge. It covers essential configuration parameters, code migration paths, common pitfalls, and verification procedures to ensure stable training performance.
What it does
- Provides configuration snippets for enabling Megatron FSDP in training recipes.
- Details necessary adjustments for checkpoint formats and sharding strategies.
- Identifies code anchors for migrating legacy distributed configuration settings.
- Highlights common pitfalls regarding mutual exclusivity and hardware-specific settings.
- Outlines functional smoke testing procedures to verify successful implementation.
When to use it
- When transitioning from DDP to FSDP-based data parallelism.
- When debugging Out-of-Memory (OOM) errors related to data parallel configurations.
- When investigating performance regressions linked to FSDP settings.
- When setting up new training runs requiring specific sharding strategies.
Advantages
- Centralizes configuration requirements for Megatron FSDP.
- Reduces integration errors by highlighting mandatory checkpoint format changes.
- Provides clear validation steps to confirm correct deployment.
- Clarifies the relationship between different distributed training wrappers.
Usage examples
- “How do I enable Megatron FSDP in my Megatron-Bridge training config?”
- The agent provides the required configuration block, including setting use_megatron_fsdp to True, selecting the appropriate sharding strategy, and configuring the fsdp_dtensor checkpoint format.
- “I am getting an error when using Megatron FSDP, how do I verify my setup?”
- The agent directs you to run the functional smoke test using the provided pytest command and explains how to interpret the logs for finite loss and successful checkpointing.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/nvidia/nemo-mbridge-perf-megatron-fsdp/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip nemo-mbridge-perf-megatron-fsdp.zip -d .agents/skills
Documentation by NVIDIA
Megatron FSDP Skill
For stable background and recommendation level, see:
@docs/training/megatron-fsdp.md
@skills/nemo-mbridge-perf-megatron-fsdp/card.yaml
Enablement
Minimal Megatron FSDP override in Bridge:
cfg.ddp.use_megatron_fsdp = True
cfg.ddp.data_parallel_sharding_strategy = "optim_grads_params"
cfg.ddp.average_in_collective = False
cfg.checkpoint.ckpt_format = "fsdp_dtensor"Example recipe fixup:
cfg = llama3_8b_pretrain_config()
cfg.ddp.use_megatron_fsdp = True
cfg.ddp.data_parallel_sharding_strategy = "optim_grads_params"
cfg.ddp.average_in_collective = False
cfg.checkpoint.ckpt_format = "fsdp_dtensor"
cfg.checkpoint.save = "/tmp/fsdp_ckpts"
cfg.checkpoint.load = NonePerformance harness note:
python scripts/performance/launch.py --use_megatron_fsdp trueCode Anchors
Megatron-Core DDP configuration (exposed as cfg.ddp in Bridge):
from megatron.core.distributed import DistributedDataParallelConfig
ddp_config = DistributedDataParallelConfig(use_megatron_fsdp=True)DistributedInitConfig no longer accepts use_megatron_fsdp. Migrate existing
cfg.dist.use_megatron_fsdp overrides to cfg.ddp.use_megatron_fsdp.
Bridge validation:
if self.ddp.use_megatron_fsdp and self.dist.use_torch_fsdp2:
raise ValueError(...)
...
assert not self.dist.use_tp_pp_dp_mapping, "use_tp_pp_dp_mapping is not supported with Megatron FSDP"
...
assert self.checkpoint.ckpt_format == "fsdp_dtensor", (
"Megatron FSDP only supports fsdp_dtensor checkpoint format"
)Runtime wrapper selection:
if use_megatron_fsdp:
DP = FullyShardedDataParallel
elif use_torch_fsdp2:
DP = TorchFullyShardedDataParallel
else:
DP = DistributedDataParallel
...
DP(
config=get_model_config(model_chunk),
ddp_config=ddp_config,
module=model_chunk,
...
pg_collection=pg_collection,
)Perf harness overrides:
recipe.ddp.use_megatron_fsdp = True
recipe.ddp.data_parallel_sharding_strategy = "optim_grads_params"
recipe.ddp.keep_fp8_transpose_cache = False
recipe.ddp.average_in_collective = False
...
recipe.checkpoint.load = NonePitfalls
Public recipes often expose
use_megatron_fsdpbut still default tockpt_format="torch_dist". If save/load is enabled, switch tofsdp_dtensor.use_torch_fsdp2exists, but on the validated branch Bridge still fails before training because_ddp_wrappassespg_collection.CPU offloading is only valid when
pipeline_model_parallel_size == 1and activation recomputation is disabled.Upstream warns that FSDP and TP/CP can want different
CUDA_DEVICE_MAX_CONNECTIONSsettings on Hopper and earlier.Megatron FSDP and FSDP2 are mutually exclusive.
Verification
Use the existing 2-GPU functional smoke test:
CUDA_VISIBLE_DEVICES=0,1 uv run python -m torch.distributed.run --nproc_per_node=2 \
-m pytest tests/functional_tests/training/test_megatron_fsdp.py::TestMegatronFSDP::test_fsdp_pretrain_basic -v -sSuccess criteria:
Pytest reports
1 passedThe log shows finite loss at the last iteration
The run finishes without a checkpoint format assertion
Files
- ATTRIBUTION.mdAdded by AutoGineer861 B
- BENCHMARK.md9.3 KiB
- LICENSELicence file added by AutoGineer11.2 KiB
- SKILL.md3.7 KiB
- card.yaml2.0 KiB
- evals/evals.json1.4 KiB
- skill-card.md7.0 KiB
- skill.oms.sig4.7 KiB
card.yaml
title: megatron_fsdp
validated_on: "2026-03-14"
summary: >
Megatron FSDP is the practical FSDP path in Megatron-Bridge today. PyTorch
FSDP2 exists in code, but remains experimental and failed at runtime during
live validation on the current branch.
validation_status:
megatron_fsdp_core:
- code_verified
megatron_fsdp_runtime_smoke:
- code_verified
megatron_fsdp_recipe_defaults:
- unclear
megatron_fsdp_performance_claims:
- doc_only
torch_fsdp2_runtime:
- known_failure
feature_meaning:
megatron_fsdp: >
Megatron-Core custom FSDP path enabled through ddp.use_megatron_fsdp and
checkpointed through fsdp_dtensor.
torch_fsdp2: >
Megatron-Core wrapper around PyTorch fully_shard enabled through
use_torch_fsdp2.
recommended_path:
ddp.use_megatron_fsdp: true
ddp.data_parallel_sharding_strategy: optim_grads_params
checkpoint.ckpt_format: fsdp_dtensor
known_constraints:
- Megatron FSDP and Torch FSDP2 are mutually exclusive.
- Megatron FSDP save/load requires fsdp_dtensor.
- Megatron FSDP does not support use_tp_pp_dp_mapping.
- FSDP2 is upstream-blocked with PP, EP, distributed optimizer, and FP16.
- CPU offloading does not support PP>1 or activation recomputation.
known_limitations:
- Public recipes often expose use_megatron_fsdp but still default to torch_dist checkpoints.
- Bridge does not expose torch_dcp or the FSDP2 reshard_after_forward knob.
- Live validation of the current branch hit a Torch FSDP2 runtime TypeError from pg_collection.
evidence:
- src/megatron/bridge/training/config.py
- src/megatron/bridge/models/common/unimodal.py
- src/megatron/bridge/training/checkpointing.py
- tests/functional_tests/training/test_megatron_fsdp.py
- 3rdparty/Megatron-LM/megatron/training/arguments.py
follow_up_validation:
- Add a positive Bridge functional test for FSDP2.
- Fix recipe defaults to switch to fsdp_dtensor when Megatron FSDP is enabled.
- Benchmark DDP vs distributed optimizer vs Megatron FSDP.
- Validate TP / PP / CP / EP compatibility matrix explicitly.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Python
Security
What our scanner noticed· Medium risk
- Large base64-encoded blobs
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Published by
- NVIDIA
- Publisher
- NVIDIA (Official)
- Source
- NVIDIA/skills · skills/nemo-mbridge-perf-megatron-fsdp · commit fce3cca
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE-APACHE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by NVIDIA.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download nemo-mbridge-perf-megatron-fsdp.zip