Skip to main content
skill CX Codex

nemo-mbridge-perf-moe-long-context — Claude Code skill

Guides context parallelism sizing and selective recompute for long-context MoE training in Megatron Bridge.

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

What nemo-mbridge-perf-moe-long-context does

This skill provides concrete tuning patterns for training MoE models beyond the 4K sequence limit in Megatron Bridge. When context grows, activation memory quickly becomes the primary bottleneck. The guide starts from a baseline heuristic of CP ~= seq_len / 4096, rounded to a power of two. It favors selective recomputation on norm, mlp, or moe blocks over full attention recompute.

Recipes derive from tested DSV3 setups on H100 up to 256K and Qwen3 235B runs on GB200 using DeepEP and HybridEP dispatchers. The true constraint quickly becomes cluster size. Higher context parallelism rapidly drains the data parallelism budget, forcing a reduction in global batch size.

CUDA graphs require fixed micro-batch sizes and static shapes. If a training pipeline relies on variable-length batches or opportunistic padding, CUDA graphs fail and eager execution is preferred.

What it helps with

  • size context parallelism for sequences up to 256K
  • resolve long-context MoE out-of-memory errors
  • configure selective recomputation without recomputing attention internals
  • set up DeepEP and HybridEP dispatchers on H100 and GB200

Example prompts for the agent

  • Calculate CP and recompute strategy for DSV3 at 128K context on H100
  • How should I configure HybridEP and parallelism for Qwen3 235B on GB200?
  • Debug long-context MoE OOM errors in Megatron Bridge

How to install nemo-mbridge-perf-moe-long-context

1Skills CLI (Vercel)

npx skills add NVIDIA/skills --skill nemo-mbridge-perf-moe-long-context -a claude-code

2Manually: put the files in place

~/.claude/skills/nemo-mbridge-perf-moe-long-context/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/nemo-mbridge-perf-moe-long-context/

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

Questions about nemo-mbridge-perf-moe-long-context

How to install nemo-mbridge-perf-moe-long-context in Claude Code?

Run npx skills add NVIDIA/skills --skill nemo-mbridge-perf-moe-long-context -a claude-code in your terminal.

What does nemo-mbridge-perf-moe-long-context do?

It provides hardware-tested guidelines for context parallelism, memory management, and dispatcher layouts for MoE models at long sequence lengths.

Why do CUDA graphs fail on long-context MoE runs?

CUDA graphs require strictly static sequence lengths and fixed micro-batch sizes. Variable batch lengths or dynamic padding break graph capture, requiring eager execution instead.

Source text

SKILL.md · Apache-2.0
---
name: nemo-mbridge-perf-moe-long-context
description: Long-context MoE training guidance for Megatron Bridge. Covers CP sizing, selective recompute, dispatcher choices, and practical patterns from DSV3, Qwen3, and Qwen3-Next long-context experiments.
license: Apache-2.0
when_to_use: Training MoE at long sequence lengths, or investigating a commit that caused long-context MoE OOM or degraded throughput; 'long context MoE', '128k tokens', 'CP sizing for long sequences', 'selective recompute long context', 'MoE long-context OOM'.
---

# MoE Long-Context Training

Stable docs: @docs/training/moe-optimization.md
Card: @skills/nemo-mbridge-perf-moe-long-context/card.yaml

## What Changes At Long Context

Once sequence length moves well past the 4K-class regime, attention memory and
activation residency become the dominant constraints. For MoE models, that
usually means you need some combination of:

- context parallelism
- selective recompute
- lower precision
- CPU offload for optimizer state
- a dispatcher and PP layout that do not waste the smaller remaining DP budget

## Rounded Scaling Patterns

### DSV3 on H100

The DSV3 long-context runs show a stable pattern:

- selective recompute works better than full recompute once you move past the
  shortest contexts
- throughput stays in a fairly narrow band from mid-length through very long
  contexts if CP is increased appropriately
- the trade shifts from "memory fit" to "GPU-count feasibility" as CP grows

In other words, long context does not immediately collapse utilization if the
layout is chosen well, but it does consume the DP budget very quickly.

### Qwen3-Next on GB200

Qwen3-Next behaves more like a memory-sensitive medium-scale model:

- 8K and 32K remain practical with moderate CP
- 64K is possible, but the throughput drop is noticeable and memory becomes
  much tighter
- pipeline layout and grouped-GEMM improvements matter almost as much as CP

### Qwen3 235B on GB200

Qwen3 235B shows that long context can still be efficient on NVL72 systems when
TP, CP, and HybridEP are coordinated. The best 128K-class configurations are
not just "fit-only" recipes; they can remain highly efficient if routing,
parallelism, and recompute are balanced.

## CP Sizing Rules Of Thumb

1. **Start from a 4K shard target**: a good first guess is
   `CP ~= seq_len / 4096`, then round to a practical power-of-two layout.

2. **Keep DP alive if possible**: long-context scaling becomes brittle once CP,
   EP, TP, and PP together squeeze DP down to the floor.

3. **Prefer selective recompute**: recompute modules such as `up_proj`, `norm`,
   `moe`, `moe_act`, or `mlp` before reaching for full recompute.

4. **Avoid SDPA-heavy recompute at very long context**: recomputing attention
   internals can add a lot of work for less memory benefit than recomputing
   smaller MoE and MLP-side modules.

5. **Use TP as another lever on NVL72 systems**: GB200 and GB300 runs can
   sometimes trade some CP for TP while still staying efficient.

6. **Assume GBS will need to shrink**: as CP rises and DP falls, you may need
   to reduce global batch size or accept higher GA.

## Representative Config Families

### DSV3 at 128K on H100

```text
TP=1  CP=32  EP=32  PP=8  VPP=4
Precision: FP8-class
Dispatcher: DeepEP
Recompute: up_proj, norm, moe, mlp
Extra memory help: optimizer CPU offload
```

### DSV3 at 256K on H100

```text
TP=1  CP=64  EP=32  PP=8  EDP=2  VPP=4
Precision: FP8-class
Dispatcher: DeepEP
Recompute: up_proj, norm, moe, mlp
Extra memory help: optimizer CPU offload
```

### Qwen3 235B at 128K on GB200

```text
TP=4  CP=4  EP=32  PP=4  VPP=12
Precision: BF16 or MXFP8
Dispatcher: HybridEP
Recompute: moe_act, norm
CUDA Graph: attn + moe_router + moe_preprocess
```

## Recompute And CUDA Graph Guidance

For long-context MoE training:

- start with selective recompute
- add CUDA graphs only after the shapes and routing path are stable
- keep sequence length and MBS fixed when using CUDA graphs
- if the run depends on highly dynamic batches, prefer eager execution

Useful references:

- @docs/training/activation-recomputation.md
- @skills/nemo-mbridge-perf-cuda-graphs/SKILL.md

## Pitfalls

1. **CP does not replace EP or PP**: it adds another dimension; it does not make
   the others disappear.

2. **A good 4K baseline can still be a bad long-context baseline**: routing mode,
   recompute choice, and offload strategy often need to change.

3. **GPU-count feasibility becomes the real constraint**: very long context can
   look fine in a single recipe, then become impossible once EP and PP are added
   honestly across the full model.

4. **CUDA graphs need static shapes**: variable-length batches and opportunistic
   padding strategies can silently break the path.

5. **Container and kernel support matters more at 128K+**: long-context paths
   tend to rely on newer kernels and bug fixes than short-context bring-up does.

© NVIDIA · Apache-2.0 · NVIDIA/skills

Similar skills

Everything for AI and ML →

From the same set178

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 nemo-mbridge-perf-moe-comm-overlap A skill for MoE expert-parallel communication overlap in Megatron Bridge: dispatch/combine, flex dispatcher backends, expert wgrad scheduling. CX Codex +1 1,800installs nemo-mbridge-perf-expert-parallel-overlap A skill for enabling and validating MoE expert-parallel communication overlap in Megatron-Bridge, covering alltoall and flex dispatchers with DeepEP and HybridEP. CX Codex +1 1,800installs nemo-mbridge-perf-cpu-offloading A skill that validates and enables CPU offloading in Megatron Bridge: layer-level activation offloading and optimizer state offloading via HybridDeviceOptimizer. CX Codex +1 1,800installs nemo-mbridge-perf-moe-optimization-workflow Guides MoE throughput tuning and regression diagnosis in Megatron Bridge. Useful when diagnosing speed drops after commit or configuration changes. CX Codex +1 1,800installs nemo-mbridge-multi-node-slurm Converts single-node launches into multi-node Slurm jobs and helps investigate NCCL, launch, and memory failures. 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