nemo-mbridge-perf-megatron-fsdp — скилл для Claude Code
Скилл помогает настроить Megatron FSDP в Megatron-Bridge для распределённого обучения вместо стандартного DDP, избежать падений по OOM и проверить чекпоинты.
npx skills add NVIDIA/skills --skill nemo-mbridge-perf-megatron-fsdp -a claude-codeЧто делает nemo-mbridge-perf-megatron-fsdp
Скилл содержит инструкции по переводу пайплайна Megatron-Bridge на параллелизм данных Megatron FSDP. Он задаёт обязательные флаги конфигурации: cfg.dist.use_megatron_fsdp = True, стратегию шардирования optim_grads_params и отключение average_in_collective. Внутри есть привязки к коду в src/megatron/bridge/training/config.py и параметры запуска через scripts/performance/launch.py.
Главная ловушка при переходе — формат чекпоинтов. Стандартные рецепты оставляют ckpt_format="torch_dist", но Megatron FSDP требует исключительно fsdp_dtensor, иначе сохранение завершится ошибкой утверждения. Megatron FSDP нельзя включать одновременно с use_torch_fsdp2 или use_tp_pp_dp_mapping. CPU offloading допустим только при pipeline_model_parallel_size == 1 и выключенном activation recomputation.
Для проверки корректности настройки скилл предлагает запустить двухпроцессный функциональный смоук-тест через pytest tests/functional_tests/training/test_megatron_fsdp.py. Успешный прогон подтверждается конечным значением лосса на последней итерации и отсутствием ошибок валидации чекпоинта.
Какие задачи решает
- включить шардирование параметров и градиентов Megatron FSDP вместо DDP
- настроить сохранение весов в формате fsdp_dtensor
- устранить падения по памяти OOM при обучении моделей
- запустить смоук-тест на двух GPU для проверки шарда
Примеры запросов агенту
- Настрой рецепт llama3_8b_pretrain_config на использование Megatron FSDP
- Исправь ошибку формата чекпоинта при переходе на Megatron FSDP в Megatron-Bridge
- Запусти функциональный тест test_megatron_fsdp.py на двух GPU через pytest
Как установить nemo-mbridge-perf-megatron-fsdp
1Через Skills CLI (Vercel)
npx skills add NVIDIA/skills --skill nemo-mbridge-perf-megatron-fsdp -a claude-code2Вручную: положить файлы
~/.claude/skills/nemo-mbridge-perf-megatron-fsdp/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/nemo-mbridge-perf-megatron-fsdp/
1Через Skills CLI (Vercel)
npx skills add NVIDIA/skills --skill nemo-mbridge-perf-megatron-fsdp -a codex2Вручную: положить файлы
.agents/skills/nemo-mbridge-perf-megatron-fsdp/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add NVIDIA/skills --skill nemo-mbridge-perf-megatron-fsdp -a cursor2Вручную: положить файлы
.cursor/skills/nemo-mbridge-perf-megatron-fsdp/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install NVIDIA/skills nemo-mbridge-perf-megatron-fsdp2Вручную: положить файлы
.github/skills/nemo-mbridge-perf-megatron-fsdp/SKILL.md1Через Skills CLI (Vercel)
npx skills add NVIDIA/skills --skill nemo-mbridge-perf-megatron-fsdp -a gemini-cli2Командой платформы
gemini skills install https://github.com/NVIDIA/skills --path skills/nemo-mbridge-perf-megatron-fsdpВручную: положить файлы
.devin/skills/nemo-mbridge-perf-megatron-fsdp/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add NVIDIA/skills --skill nemo-mbridge-perf-megatron-fsdp -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о nemo-mbridge-perf-megatron-fsdp
Как установить nemo-mbridge-perf-megatron-fsdp в Claude Code?
Выполните команду npx skills add NVIDIA/skills --skill nemo-mbridge-perf-megatron-fsdp -a claude-code.
Какой формат чекпоинтов требует Megatron FSDP?
Требуется только cfg.checkpoint.ckpt_format = "fsdp_dtensor". Значение по умолчанию torch_dist приведёт к ошибке assertion при сохранении или загрузке весов.
Можно ли использовать Megatron FSDP вместе с PyTorch FSDP2?
Нет, флаги use_megatron_fsdp и use_torch_fsdp2 взаимоисключающие. При их одновременном включении валидатор Bridge вызывает ValueError.
Исходный текст
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