
MoE Long-Context Training
OfficialFreeOptimized guidance for long-context MoE training.
Free · Opens the source repo
What MoE Long-Context Training does
The MoE Long-Context Training skill provides comprehensive guidance for optimizing long-context training in Mixture of Experts (MoE) models using the Megatron Bridge framework. This skill is designed for developers and researchers working with large-scale language models who need to navigate the complexities of training with extended sequence lengths beyond the 4K context limit. By addressing key constraints such as attention memory and activation residency, this skill helps users implement effective strategies for scaling their models.
Users will find detailed recommendations on essential techniques like context parallelism, selective recompute, and CPU offloading for optimizer states. The skill also includes practical patterns derived from experiments with models such as DSV3 and Qwen3, providing insights into how to maintain throughput and efficiency as context lengths increase. The guidance emphasizes the importance of balancing various parameters, including TP, CP, and EP, to ensure optimal performance without exceeding memory constraints.
This skill is particularly beneficial for those engaged in training large language models where long context is crucial, such as in natural language processing tasks that require understanding of extensive text passages. By following the provided rules of thumb and configuration examples, users can better navigate the challenges associated with long-context training and improve their model's performance.
In summary, the MoE Long-Context Training skill is a valuable resource for developers and researchers looking to enhance their understanding and implementation of long-context training techniques in MoE models, ensuring they can effectively leverage the capabilities of the Megatron Bridge framework.
When to use it
Use this skill when working with large language models that require training with sequence lengths exceeding 4K, particularly in a research or development context.
When not to use it
This skill may not be suitable for smaller models or applications that do not require long-context training optimizations.
What you can build with it
Training Large Language Models
Utilize this skill when configuring MoE models for tasks that require understanding long text inputs, ensuring optimal performance.
Experimenting with Context Lengths
Refer to the guidance when experimenting with various context lengths to find the most efficient training configurations.
Optimizing Resource Usage
Use the recommendations to balance memory and computational resources effectively while training large-scale models.
How to install MoE Long-Context Training
View source1. Install with the skills CLI
npx skills add nvidia/skills/nemo-mbridge-perf-moe-long-context --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by nvidiaMoE 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
-
Start from a 4K shard target: a good first guess is
CP ~= seq_len / 4096, then round to a practical power-of-two layout. -
Keep DP alive if possible: long-context scaling becomes brittle once CP, EP, TP, and PP together squeeze DP down to the floor.
-
Prefer selective recompute: recompute modules such as
up_proj,norm,moe,moe_act, ormlpbefore reaching for full recompute. -
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.
-
Use TP as another lever on NVL72 systems: GB200 and GB300 runs can sometimes trade some CP for TP while still staying efficient.
-
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
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
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
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
-
CP does not replace EP or PP: it adds another dimension; it does not make the others disappear.
-
A good 4K baseline can still be a bad long-context baseline: routing mode, recompute choice, and offload strategy often need to change.
-
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.
-
CUDA graphs need static shapes: variable-length batches and opportunistic padding strategies can silently break the path.
-
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.
Frequently asked questions about MoE Long-Context Training
Similar skills
Heap Snapshot Analysis
Investigate V8 heap snapshots for memory issues.
VS Code Performance Workflow
Automate performance investigations in VS Code.
Memory Leak Audit
Prevent memory leaks with effective coding patterns.
CPU Profile Analysis
Analyze V8 and Chrome performance profiles for optimization.
Chat Performance Testing
Benchmark and validate chat UI performance in VS Code.
Vercel React Best Practices
Optimize your React and Next.js applications for performance.
