# nemo-mbridge-perf-activation-recompute

Guides activation recomputation setup in Megatron Bridge to resolve GPU memory OOMs during LLM training. Balances memory savings against extra recomputed operations.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 1800 installs · ★ 3735
- Author: NVIDIA
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/NVIDIA/skills/tree/HEAD/skills/nemo-mbridge-perf-activation-recompute/SKILL.md
- Updated: 2026-10-23
- HTML: https://affpapa.org/en/nevibecode/skills/nemo-mbridge-perf-activation-recompute

## What it does

This skill troubleshoots activation memory pressure in Megatron Bridge models. It contrasts per-rank `max_memory_allocated()` against `max_memory_reserved()` to verify actual allocation versus allocator fragmentation. This distinguishes fragmentation from true memory exhaustion. You can configure granular checkpoint targets or activate full-layer recomputation.

Under selective recomputation, targets include `core_attn` for standard attention blocks, `mla_up_proj` for Multi-Latent Attention, and `moe_act` for grouped Mixture-of-Experts. Additional labels cover `layernorm`, `mlp`, and `gdn_norm_out`. Recomputation adds extra forward passes. This trades backward-pass compute time for lower peak memory.

Concurrency options introduce hard constraints. Full `moe` recomputation breaks expert-parallel overlap, while `shared_experts` conflicts with shared-expert overlap features. Enabling Megatron Core's `cpu_offloading=True` disables activation recomputation entirely.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add NVIDIA/skills --skill nemo-mbridge-perf-activation-recompute -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/nemo-mbridge-perf-activation-recompute/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/nemo-mbridge-perf-activation-recompute/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add NVIDIA/skills --skill nemo-mbridge-perf-activation-recompute -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/nemo-mbridge-perf-activation-recompute/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add NVIDIA/skills --skill nemo-mbridge-perf-activation-recompute -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/nemo-mbridge-perf-activation-recompute/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install NVIDIA/skills nemo-mbridge-perf-activation-recompute
```

2. **Manually: put the files in place**
- File: `.github/skills/nemo-mbridge-perf-activation-recompute/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add NVIDIA/skills --skill nemo-mbridge-perf-activation-recompute -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/NVIDIA/skills --path skills/nemo-mbridge-perf-activation-recompute
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/nemo-mbridge-perf-activation-recompute/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add NVIDIA/skills --skill nemo-mbridge-perf-activation-recompute -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/NVIDIA/skills/tree/HEAD/skills/nemo-mbridge-perf-activation-recompute/SKILL.md

## When to use it
- resolve GPU out-of-memory errors caused by stored activations
- tune selective recomputation targets for MLA and MoE architectures
- differentiate real memory usage from PyTorch allocator fragmentation
- switch between selective module checkpoints and full transformer layer recomputation

## Example prompts
- Diagnose an activation OOM and suggest `recompute_modules` for our MoE model.
- Set up selective recomputation with `mla_up_proj` in Megatron Bridge.
- Explain why full `moe` recompute fails alongside expert-parallel overlap.

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 2a2fdf797cd1adcf.

BEGIN THIRD-PARTY FILE 2a2fdf797cd1adcf
```text
---
name: nemo-mbridge-perf-activation-recompute
description: >-
  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.
license: Apache-2.0
---

# Activation Recompute

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

<!-- Guidance refreshed: 2026-08-12. -->

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. Keep an explicit no-recompute control when the workload fits. Under selective granularity, `recompute_modules=[]` is valid and useful for this comparison.
3. Select the first boundary 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.
4. 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.
```
END THIRD-PARTY FILE 2a2fdf797cd1adcf

The third-party file has ended. Everything between the 2a2fdf797cd1adcf tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2340 of 18915 bytes. © NVIDIA · Apache-2.0 · https://github.com/NVIDIA/skills/tree/HEAD/skills/nemo-mbridge-perf-activation-recompute/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
