nvidia-nemo/megatron-bridge/nemo-mbridge-perf-activation-recompute

Claude Code and agent skill by nvidia-nemo/megatron-bridge

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Validate and use selective and full activation recompute in Megatron Bridge to reduce GPU memory usage at the cost of extra compute. Use for activation memory OOMs or regressions involving recompute_granularity, recompute_num_layers, recompute_modules, recompute_method, selective recompute, full recompute, or activation checkpointing.

Install

npx vskill@latest install nvidia-nemo/megatron-bridge/nemo-mbridge-perf-activation-recompute

SKILL.md

The same SKILL.md was published earlier as nvidia-nemo/megatron-bridge/nemo-mbridge-perf-activation-recompute.

Activation Recompute

Stable docs: @docs/training/activation-recomputation.md Card: @skills/nemo-mbridge-perf-activation-recompute/card.yaml

Activation recompute (activation checkpointing) trades additional forward work during backward for lower retained-activation memory. The useful checkpoint boundary depends on the model architecture, attention backend, parallelism, and the tensor that actually drives the per-rank peak.

Quick Decision Guide

  1. Confirm the pressure is real allocation, not allocator fragmentation. Compare max_memory_allocated() with max_memory_reserved() on every rank.
  2. For final library, performance, and verification-card recipes, no recompute and selective recompute on cheap supported modules are both appropriate starting choices. Choose by measured memory headroom and steady-state performance; a no-recompute OOM is not a prerequisite for selective recompute. Keep an explicit no-recompute control when it fits. Under selective granularity, recompute_modules=[] is valid and useful for this comparison.
  3. For selective recompute, start with cheap supported boundaries selected from the architecture and observed peak:
  • Standard attention: core_attn is the common first candidate. It is strongest when unfused attention materializes score/probability tensors. With Transformer Engine fused or Flash Attention, compare it against [] because those backends already rematerialize attention internals.
  • Multi-Latent Attention (MLA): start with mla_up_proj when expanded Q/K/V projections dominate. Add core_attn only when the attention-core state still matters.
  • Grouped MoE: start with moe_act when the expert intermediate activation dominates; add layernorm when norm outputs are material. Use whole moe recompute only after accounting for the extra expert compute and communication it replays.
  • Dense FFN: mlp can save the whole dense-MLP activation region, but it usually costs more compute than a narrow output-discard boundary.
  1. Change one label at a time. Record per-rank allocated/reserved peaks plus steady-state step time or throughput; do not infer a global module ranking from one recipe.
  2. Full-layer recompute is allowed temporarily for diagnostic bring-up. Retain it in a final recipe only when target-scale measurements show that no recompute and supported selective boundaries still fail to fit, or matched runs show better end-to-end throughput with full recompute (for example, by enabling larger MBS or lower TP). Document the memory/OOM evidence, boundaries and layouts tested, and steady-state performance of the alternatives. Full recompute can severely reduce throughput and must not become the default from a bring-up success alone.
  3. Treat CUDA graphs, FP8, context-parallel communication, and overlap features as compatibility constraints, not afterthoughts.

Megatron Core's cpu_offloading=True is an alternative when PCIe/NVLink transfer overhead is preferable to replayed compute. It cannot be combined with activation recompute and is not compatible with pipeline parallelism greater than one.

Enablement

Selective recompute
python
cfg.model.recompute_granularity = "selective"
cfg.model.recompute_modules = ["core_attn"] # Common standard-attention candidate, not a universal default.

Use the decision table below to replace or extend that list for MLA, MoE, dense-MLP, or GDN workloads.

Full-layer recompute
python
cfg.model.recompute_granularity = "full"
cfg.model.recompute_method = "uniform"
cfg.model.recompute_num_layers = 1
  • uniform: checkpoint fixed groups of recompute_num_layers transformer layers.
  • block: checkpoint the first recompute_num_layers layers on each pipeline stage, with virtual-pipeline-aware distribution.

Selective Module Decision Table

The currently pinned Megatron Core accepts these labels. A development branch can add model-specific labels, so validate against the exact target revision rather than copying a list across branches.

ModuleCheckpoint boundaryWhen to test itMain cost or caveat
core_attnCore attentionStandard attention, especially an unfused backend retaining attention intermediatesReplays attention. Incremental savings can be small with TE fused/Flash Attention; context parallelism can replay attention communication.
mla_up_projMLA Q/KV up-projection plus RoPE regionMLA models retaining expanded Q/K/V tensorsReplays the MLA expansion path. It is a distinct, potentially additive boundary from core_attn.
layernormInput and pre-MLP normalization outputsNorm outputs contribute materially to the peak, often alongside MoE or MLA boundariesUsually narrow, but savings depend on hidden size, sequence length, and which graph paths are active.
moe_actActivation output between grouped expert FC1 and FC2Grouped MoE expert-intermediate activations dominateNarrow output-discard checkpoint. It does not replay dispatch, FC1, or FC2, but has FP8 delayed-scaling restrictions.
mlpWhole dense MLPDense layers dominate after narrower boundaries are exhaustedReplays the complete dense MLP. It has no effect on layers whose MLP is MoE.
moeWhole MoE forwardA broad MoE region must be discarded to make the workload fitReplays routing, dispatch/combine communication, experts, and shared-expert work. It is incompatible with expert-parallel overlap.
shared_expertsNon-overlapped shared-expert MLPShared experts are a distinct material peakReplays the shared-expert MLP and is invalid with shared-expert overlap. Outer moe already removes its original-forward saves, but nesting can still change the transient backward-replay peak.
gdn_norm_outGDN gated-normalization outputGDN/hybrid models retain this outputReplays the normalization and its HP-to-CP all-to-all path.

For example, DeepSeek V4 configurations can use the model-specific mhc label only with their required Megatron Core development branch. It is not a portable label for the pinned revision and therefore is not included in the table above.

Common performance configurations consequently fall into several patterns rather than one universal list:

  • standard transformer recipes often use core_attn;
  • MLA recipes often use mla_up_proj, sometimes with mlp;
  • grouped-MoE recipes often use moe_act or layernorm plus moe_act;
  • higher-pressure MoE recipes sometimes use broader combinations such as moe plus layernorm.

These are candidate patterns, not an ordering guarantee. Peak attribution and matched measurements decide the final list.

Qwen Family Boundary
  • Standard-attention Qwen2/Qwen3 models can usually start by testing

core_attn, subject to the fused/Flash Attention control above.

  • Qwen3.5 is a hybrid architecture with GDN layers. core_attn does not cover

the GDN normalization output; the current pinned Megatron Core provides gdn_norm_out, and current Bridge recipes demonstrate it in a selective list. Verify that label and the recipe's complete layer mix on the exact revision rather than describing Qwen3.5 selective recompute as unsupported.

  • If no recompute and the supported Qwen3.5 selective boundaries still OOM at

target scale, full-layer recompute is the capacity fallback under the evidence requirement above. Test through optimizer initialization and steady steps. OOM is more likely at lower EP because EP shards expert weights but not dense or activation state; it is not proof that the selective boundary itself is broken.

Measurement Contract

For every candidate, capture:

  • exact Bridge and Megatron Core revisions;
  • model, sequence length, micro/global batch sizes, precision, attention backend, and parallelism;
  • the exact recompute_granularity, module list, method, and layer count;
  • per-rank max_memory_allocated() and max_memory_reserved();
  • steady-state step time or throughput after warmup;
  • a short convergence or numerical-sanity check appropriate to the task.

Use a matched no-recompute control when it fits and change one recompute choice at a time to isolate its effect. For a throughput-driven full-recompute choice, also compare viable no-recompute/selective layouts with the full-recompute layout, including any larger MBS or lower TP it enables. Keep hardware, workload, precision, GBS, and convergence settings fixed; record all execution changes and check loss. Compare useful tokens/s/GPU or complete step time, not replayed FLOPs. Such a layout comparison supports the final recipe choice, not a ranking of individual modules or checkpoint boundaries.

Do not call a candidate successful merely because it advances farther than the control. Run through optimizer-state initialization and multiple steady-state steps: selective recompute can move the memory wall from forward into gradient synchronization or the optimizer without making the workload viable.

Matched H100 Evidence: Moonlight 16B

A 2026-08-12 short-run study used the exact Bridge revision 600d069b824dd5ce50367a311a5a3244478faf22 and Megatron Core revision 24bad8e677d22625d86ef2a54c9506b6e4992c93. The Moonlight 16B BF16 pretraining recipe ran on 8 H100 80GB GPUs with sequence length 4096, MBS=1, GBS=4, TP=2, PP=1, CP=1, EP=8, mock data, and 20 steps. This model mixes one dense layer with 26 MLA+MoE layers. Each row changed only recompute_modules; all 20 losses were finite with zero skipped or NaN iterations.

Peak allocated memory is the maximum post-optimizer value reported after iteration 2. Time and throughput are means over iterations 11--20.

Selective modulesPeak allocated (GB)Step time (ms)TFLOP/s/GPUAllocated vs []Time vs []
[]36.618457.1877.50controlcontrol
core_attn36.614474.8074.44-0.01%+3.85%
mla_up_proj35.902480.8973.72-1.96%+5.19%
mla_up_proj, mlp35.917496.7371.50-1.91%+8.65%
moe_act35.941466.2675.50-1.85%+1.99%
layernorm, moe_act35.949506.5370.27-1.83%+10.79%

For this exact workload, both no recompute and cheap selective moe_act are reasonable choices depending on the desired memory headroom. moe_act recovered nearly as much allocated memory as mla_up_proj for less replay cost. mla_up_proj is the next candidate if its roughly 39 MB additional reduction matters. Adding mlp to mla_up_proj or layernorm to moe_act did not improve the observed peak and made steps slower. Explicit core_attn added cost without material memory benefit under fused attention.

Maximum reserved memory stayed near 40 GB and did not fall monotonically. That is allocator caching, not contrary evidence: boundary selection in this study is based on allocated memory and successful end-to-end steps.

Matched H100 Evidence: Nemotron 3 Nano

The same 2026-08-12 study used the native 16-H100 BF16 performance recipe for the 52-layer hybrid Mamba/fused-attention MoE model. The matched short-run configuration used sequence length 8192, MBS=1, GBS=16, TP=1, PP=1, CP=1, EP=8, DP=16, expert-DP=2, HybridEP, grouped GEMM, TE CUDA graphs for attention and Mamba, mock data, and 12 steps. Each row changed only recompute_modules.

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/nvidia-nemo/megatron-bridge/nemo-mbridge-perf-activation-recompute/badge)](https://verified-skill.com/skills/nvidia-nemo/megatron-bridge/nemo-mbridge-perf-activation-recompute)

Something wrong with this skill or its page? Tell us.