Skip to main content
skill CX Codex

nemo-mbridge-perf-megatron-fsdp — Claude Code skill: setup

Configures Megatron FSDP in Megatron-Bridge to replace standard DDP, helping resolve out-of-memory errors and verify training checkpoints.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add NVIDIA/skills --skill nemo-mbridge-perf-megatron-fsdp -a claude-code
Open on GitHub

What nemo-mbridge-perf-megatron-fsdp does

This skill guides developers through enabling Megatron Fully Sharded Data Parallel in Megatron-Bridge. It details the required configuration flags, including cfg.dist.use_megatron_fsdp = True, data_parallel_sharding_strategy = "optim_grads_params", and setting average_in_collective = False. It also points to code anchors in src/megatron/bridge/training/config.py and benchmark harness flags.

Checkpoint configuration is a frequent failure point. Default training recipes fall back to torch_dist, while Megatron FSDP requires fsdp_dtensor. Megatron FSDP cannot run alongside use_torch_fsdp2 or use_tp_pp_dp_mapping. CPU offloading is permitted only when pipeline_model_parallel_size == 1 and activation recomputation is turned off.

Verification relies on a 2-GPU functional smoke test executed via PyTorch distributed run and Pytest. A clean run finishes with finite loss on the final step and encounters zero checkpoint assertions.

What it helps with

  • switch from standard DDP to Megatron FSDP in Megatron-Bridge
  • resolve checkpoint assertions by configuring fsdp_dtensor
  • avoid out-of-memory errors during large language model pretraining
  • verify multi-GPU FSDP runs with the built-in Pytest smoke test

Example prompts for the agent

  • Configure my Megatron-Bridge training recipe to use Megatron FSDP
  • Fix checkpoint format assertion errors when saving Megatron FSDP weights
  • Run the 2-GPU functional verification test for Megatron FSDP

How to install nemo-mbridge-perf-megatron-fsdp

1Skills CLI (Vercel)

npx skills add NVIDIA/skills --skill nemo-mbridge-perf-megatron-fsdp -a claude-code

2Manually: put the files in place

~/.claude/skills/nemo-mbridge-perf-megatron-fsdp/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/nemo-mbridge-perf-megatron-fsdp/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about nemo-mbridge-perf-megatron-fsdp

How do I install nemo-mbridge-perf-megatron-fsdp in Claude Code?

Run npx skills add NVIDIA/skills --skill nemo-mbridge-perf-megatron-fsdp -a claude-code in your terminal.

What checkpoint format does Megatron FSDP require?

It strictly requires cfg.checkpoint.ckpt_format = "fsdp_dtensor". If recipes keep torch_dist, saving or loading weights raises an assertion error.

Can I run Megatron FSDP together with PyTorch FSDP2?

No, use_megatron_fsdp and use_torch_fsdp2 are mutually exclusive. Bridge validation raises a ValueError if both flags are enabled.

Source text

SKILL.md · Apache-2.0
---
name: nemo-mbridge-perf-megatron-fsdp
description: Operational guide for enabling Megatron FSDP in Megatron-Bridge, including config knobs, code anchors, pitfalls, and verification.
license: Apache-2.0
when_to_use: Using FSDP-based data parallelism instead of DDP, or tracing an OOM or regression to a FSDP config change; 'use_megatron_fsdp', 'data_parallel_sharding_strategy', 'sharded data parallel', 'Megatron FSDP'.
---

# 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:

```python
cfg.dist.use_megatron_fsdp = True
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:

```python
cfg = llama3_8b_pretrain_config()
cfg.dist.use_megatron_fsdp = True
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 = None
```

Performance harness note:

```bash
python scripts/performance/launch.py --use_megatron_fsdp true
```

## Code Anchors

Bridge config definition:

```148:154:src/megatron/bridge/training/config.py
use_megatron_fsdp: bool = False
"""Use Megatron's Fully Sharded Data Parallel. Cannot be used together with use_torch_fsdp2."""

use_torch_fsdp2: bool = False
"""Use the torch FSDP2 implementation. FSDP2 is not currently working with Pipeline Parallel.
It is still not in a stable release stage, and may therefore contain bugs or other
potential issues."""
```

Bridge validation:

```1533:1578:src/megatron/bridge/training/config.py
if self.dist.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:

```217:243:src/megatron/bridge/models/common/unimodal.py
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:

```74:98:scripts/performance/utils/overrides.py
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 = None
```

## Pitfalls

1. Public recipes often expose `use_megatron_fsdp` but still default to `ckpt_format="torch_dist"`. If save/load is enabled, switch to `fsdp_dtensor`.
2. `use_torch_fsdp2` exists, but on the validated branch Bridge still fails before training because `_ddp_wrap` passes `pg_collection`.
3. CPU offloading is only valid when `pipeline_model_parallel_size == 1` and activation recomputation is disabled.
4. Upstream warns that FSDP and TP/CP can want different `CUDA_DEVICE_MAX_CONNECTIONS` settings on Hopper and earlier.
5. Megatron FSDP and FSDP2 are mutually exclusive.

## Verification

Use the existing 2-GPU functional smoke test:

```bash
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 -s
```

Success criteria:

- Pytest reports `1 passed`
- The log shows finite loss at the last iteration
- The run finishes without a checkpoint format assertion

© NVIDIA · Apache-2.0 · NVIDIA/skills

Similar skills

Everything for AI and ML →

From the same set178

nemo-rl-brev-etiquette A skill that tells the agent where files belong on a Brev box: code stays in the repo, heavy run output goes to /ephemeral. CX Codex +1 1,800installs mcore-linting-and-formatting Sets up linting and code formatting for Megatron-LM projects. It helps fix ruff and mypy violations and sort imports before opening a pull request. CX Codex +1 1,800installs nemo-mbridge-perf-tp-dp-comm-overlap A skill that walks through enabling TP, DP and PP communication overlap in Megatron-Bridge: which knobs to turn, where the code gates it, how to verify. CX Codex +1 1,800installs nemo-mbridge-perf-moe-dispatcher-selection Picks between alltoall, DeepEP and HybridEP for MoE token dispatch based on your hardware, EP degree and optimization stage. CX Codex +1 1,800installs nemo-rl-docs This skill hands your agent the documentation rules for NeMo-RL: keeping docs/index.md current and writing docstrings in Google style. Useful when you touch the docs. CX Codex +1 1,800installs nemo-mbridge-resiliency A skill covering resiliency setup in Megatron Bridge: fault tolerance, straggler detection, preemption and re-run state machine. CX Codex +1 1,800installs nemo-mbridge-perf-hierarchical-context-parallel Configures hierarchical context parallelism in Megatron-Bridge. Useful for scaling long-sequence model training when context length exceeds KV head counts. CX Codex +1 1,800installs nemo-mbridge-perf-moe-hardware-configs A reference of MoE training starting configurations for H100, B200, GB200, and GB300. Use it when selecting a dispatcher, parallelism layout, or planning throughput checks. CX Codex +1 1,800installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor