nvidia-nemo/megatron-bridge/nemo-mbridge-perf-cpu-offloading
Claude Code and agent skill by nvidia-nemo/megatron-bridge
- community
Checking that the SKILL.md file is still in the repository.
Validate and use CPU offloading in Megatron Bridge, including layer-level activation offloading and fractional optimizer state offloading with HybridDeviceOptimizer.
Install
npx vskill@latest install nvidia-nemo/megatron-bridge/nemo-mbridge-perf-cpu-offloadingSKILL.md
The same SKILL.md was published earlier as nvidia/skills/nemo-mbridge-perf-cpu-offloading.
CPU Offloading
References
- Stable docs: @docs/training/cpu-offloading.md
- Structured metadata: @skills/nemo-mbridge-perf-cpu-offloading/card.yaml
What It Is
Two independent mechanisms to move data from GPU to CPU memory:
| Mechanism | Config namespace | What gets offloaded | PP restriction | |
|---|---|---|---|---|
| Activation offloading | model.cpu_offloading* | Activations (and optionally weights) per transformer layer | PP must be 1 | |
| Optimizer offloading | optimizer.optimizer_cpu_offload | Adam optimizer states (momentum + variance) via HybridDeviceOptimizer | None |
Quick Decision
| Situation | Recommendation | |
|---|---|---|
| Large MoE model (30B+), needs PP > 1 | Optimizer offloading — activation offloading is blocked by PP=1 | |
| Small/medium model, PP=1 fits, activation memory dominates | Activation offloading | |
| Want tunable memory-speed tradeoff | Optimizer offloading with fractional optimizer_offload_fraction | |
| Throughput is top priority | Don't enable — offloading always adds overhead | |
| CUDA graphs are needed | Only optimizer offloading — activation offloading is incompatible | |
| Memory pressure is moderate | Optimizer offload at 25–50% fraction for best efficiency |
Enablement
Optimizer CPU offloading (recommended for large models)
CLI overrides:
Activation CPU offloading (small/medium models only)
Config Parameter Reference
Optimizer offloading
| Parameter | Default | Description | |
|---|---|---|---|
optimizer_cpu_offload | False | Master switch | |
optimizer_offload_fraction | 0.0 | Fraction of optimizer states on CPU (0.0–1.0) | |
overlap_cpu_optimizer_d2h_h2d | False | Overlap GPU↔CPU transfers with compute | |
use_torch_optimizer_for_cpu_offload | False | Use torch.optim instead of fused optimizer for CPU portion |
Activation offloading
| Parameter | Default | Description | |
|---|---|---|---|
cpu_offloading | False | Master switch | |
cpu_offloading_num_layers | 0 | Number of transformer layers to offload (0 to num_layers-1) | |
cpu_offloading_activations | True | Offload activations | |
cpu_offloading_weights | False | Offload weights | |
cpu_offloading_double_buffering | False | Double-buffer across layers while reloading |
Compatibility And Constraints
Activation offloading
pipeline_model_parallel_sizemust be 1recompute_granularitymust beNone- Cannot combine with
fine_grained_activation_offloading - Cannot combine with CUDA graphs
cpu_offloading_num_layersmust be in[0, num_layers-1)
Optimizer offloading
- Requires
use_distributed_optimizer = True(default in most recipes) - No PP, recompute, or CUDA graph restrictions
optimizer_offload_fractionmust be in[0.0, 1.0]
Practical: large MoE models
Activation offloading is blocked for Qwen3-30B-A3B and similar large MoE models. The PP=1 constraint means each GPU holds all 48 layers; model weights + optimizer states alone (~70 GB) exceed H100 80 GB capacity.
Minimal Runnable Command
Verification
Unit tests
Success criteria
- Config validation passes for the selected offloading mode
- Training completes without OOM or NCCL errors
- Loss matches the non-offloaded baseline (max delta < 0.001)
- Memory usage drops proportionally to offload fraction
Code Anchors
MCore activation offload constraints
MCore CUDA graph incompatibility
MCore fine-grained offloading mutual exclusion
MCore HybridDeviceOptimizer instantiation
Bridge CUDA graph guard
Bridge activation offloading in PEFT
Failure Diagnosis
| Symptom | Likely Cause | How To Confirm | Fix | |
|---|---|---|---|---|
Currently there is no support for Pipeline parallelism with CPU offloading | Activation offload + PP > 1 | Check pipeline_model_parallel_size | Set PP=1 or use optimizer offloading | |
CPU offloading does not work when activation recomputation is enabled | Activation offload + recompute | Check recompute_granularity | Set recompute_granularity=null | |
fine_grained_activation_offloading cannot be enabled with cpu_offloading | Both offloading modes enabled | Check both flags | Use one or the other | |
CUDA graphs not supported with CPU offloading | CUDA graphs + activation offload | Check cuda_graph_impl | Set cuda_graph_impl="none" | |
| OOM with activation offloading | Model too large for PP=1 | Check allocated memory vs 80 GB | Use optimizer offloading with PP > 1 | |
| Extreme slowdown (>4x) | 100% optimizer offload, CPU Adam bottleneck | Compare iter time at different fractions | Reduce fraction or enable overlap_cpu_optimizer_d2h_h2d | |
| OOM at partial optimizer offload | Insufficient offload for this config | Check memory at different fractions | Increase fraction or add PP |
Known Limitations
- Activation offloading requires PP=1, making it impractical for large models
(30B+ MoE) that need pipeline parallelism.
- Optimizer offloading throughput penalty scales linearly (~1.9x at 25%,
~4.2x at 100% for Qwen3-30B-A3B).
- D2H/H2D overlap provides only ~7% speedup because CPU Adam compute is
the dominant bottleneck.
fine_grained_activation_offloadingis a separate module-level approach
that works with PP > 1 but cannot be combined with layer-level cpu_offloading.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/nemo-mbridge-perf-cpu-offloading/SKILL.md
Popularity
- Repository stars
- 775
- Repository forks
- 401
- 7-day trend score
- 33
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/nvidia-nemo/megatron-bridge/nemo-mbridge-perf-cpu-offloading)