perf-cuda-graphs

Capture and replay CUDA graphs in Megatron Bridge to reduce training step latency.

Updated May 23, 2026
One-click install
npx skills add https://github.com/yo-steven/skills-exploration-20260522 --skill perf-cuda-graphs-yo-steven
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: perf-cuda-graphs
Source: https://github.com/yo-steven/skills-exploration-20260522/tree/main/skills/Megatron-Bridge/perf-cuda-graphs
Command: npx skills add https://github.com/yo-steven/skills-exploration-20260522 --skill perf-cuda-graphs-yo-steven

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

CUDA graph capture can substantially reduce host-driver overhead, but it is easy to misconfigure in Megatron Bridge and TE-scoped setups due to strict constraints (static shapes, RNG tracker requirements, scope/impl compatibility, and environment limitations).

Core Features & Use Cases

  • CUDA graph capture with two implementations: choose "local" for full fwd+bwd full_iteration capture, or "transformer_engine" for TE-scoped graphs per layer scope such as attn, mlp, and MoE-related modules.
  • Bring-up guidance for performance tuning: select the narrowest useful scope first, validate replay timing vs eager after warmup, and only then widen scope or combine with overlap features.
  • Safety checks and failure-mode awareness: enforces TE RNG tracker requirements, validates NaN-check constraints for full_iteration, and documents known blockers like packed-sequence incompatibility and scope restrictions for MoE.

Quick Start

Enable TE-scoped CUDA graphs by setting model.cuda_graph_impl to transformer_engine and model.cuda_graph_scope to attn,moe_router,moe_preprocess, while also turning on model.use_te_rng_tracker and rng.te_rng_tracker.

Frequently Asked Questions about perf-cuda-graphs

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce GPU launch overhead during distributed training?

To reduce GPU launch overhead during distributed training, capture and replay CUDA graphs in Megatron Bridge to minimize host-driver overhead for static-shape pretrain and fine-tune workloads. This applies to dense models and dropless MoE models.

Does CUDA graph capture work with dropless MoE training in Transformer Engine?

Yes, CUDA graph capture supports dropless MoE training in Transformer Engine by targeting the attn, moe_router, and moe_preprocess scopes. You must use the local full_iteration capture or TE-scoped implementations while enforcing mandatory MoE scope composition constraints.

How do I enable TE-scoped CUDA graphs for Megatron Bridge?

To enable TE-scoped CUDA graphs in Megatron Bridge, set model.cuda_graph_impl to transformer_engine and model.cuda_graph_scope to attn,moe_router,moe_preprocess. You must also enable model.use_te_rng_tracker and rng.te_rng_tracker to satisfy strict TE RNG tracker requirements.

When should I not use CUDA graphs for MoE training?

You should not use CUDA graphs for MoE training when dealing with packed-sequence incompatibility or dynamic shapes. CUDA graphs require static shapes and specific NaN-check constraints for full_iteration capture, making dynamic workloads unsuitable.

What is the best way to validate CUDA graph performance tuning?

The best way to validate CUDA graph performance tuning is to select the narrowest useful scope first, then compare replay timing against eager execution after warmup. Only widen the scope or combine with overlap features after confirming the initial performance gains.