[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6PH51JR0RP9X4E1AS3VBD37":3,"skill-same:01M6PH51JR0RP9X4E1AS3VBD37":90},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":45,"commitSha":46,"skillDirectory":47,"forksCount":14,"repositoryHtmlUrl":48,"repositoryHomepageUrl":6,"ownerHtmlUrl":49,"ownerBlogUrl":50,"ownerDescription":6,"updatedAt":51,"install":52,"resources":65},"01M6PH51JR0RP9X4E1AS3VBD37","nemo-mbridge-perf-cuda-graphs",null,"Validate and use CUDA graph capture in Megatron Bridge, including local full-iteration graphs and Transformer Engine scoped graphs for attention, MLP, and MoE modules.","headmktlucca-ui\u002Fneuroads-lp","headmktlucca-ui","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F247379838?v=4","01M6PDVAV6M1W96D1SR1PDF8CS","NeuroAds","01M6PDVAZ4P281GNDKD45CYTF5",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp\u002Fblob\u002Fmain\u002F.agent\u002Fskills\u002Fnemo-mbridge-perf-cuda-graphs\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"nemo mbridge perf cuda graphs","perf","NeMo","graphs","cuda","local","overhead","megatron","host","impl","iteration","full","attention","change","modules","bridge","regression","tracing","graph","config","2026-11-10 10:12:30",false,"---\nname: nemo-mbridge-perf-cuda-graphs\ndescription: Validate and use CUDA graph capture in Megatron Bridge, including local full-iteration graphs and Transformer Engine scoped graphs for attention, MLP, and MoE modules.\nlicense: Apache-2.0\nwhen_to_use: Reducing host-driver overhead via CUDA graphs, or tracing a crash or regression to a CUDA graph config change; 'cuda_graph_impl', 'full iteration graph', 'TE scoped graph', 'graphed callables', 'CUDA graph capture'.\n---\n\n# CUDA Graphs\n\nStable documentation: @docs\u002Ftraining\u002Fcuda-graphs.md\nCard: @skills\u002Fnemo-mbridge-perf-cuda-graphs\u002Fcard.yaml\n\n\u003C!-- NVSkills CI refresh: 2026-06-15. No instruction changes. -->\n\n## What It Is\n\nCUDA graphs capture GPU operations once and replay them with minimal\nhost-driver overhead. Bridge supports two implementations:\n\n| `cuda_graph_impl` | Mechanism | Scope support |\n|---|---|---|\n| `\"local\"` | MCore `FullCudaGraphWrapper` wrapping entire fwd+bwd | `full_iteration` |\n| `\"transformer_engine\"` | TE `make_graphed_callables()` per layer | `attn`, `mlp`, `moe`, `moe_router`, `moe_preprocess`, `mamba` |\n\n## Quick Decision\n\nStart with TE-scoped graphs for most training workloads, then verify replay\ntiming against eager on the same dispatcher, layout, and container:\n\n- dense models: `attn`, then optionally `mlp`\n- dropless MoE: `attn moe_router moe_preprocess`\n- VLMs: the same dropless-MoE scope, but only after the real-data path is stable\n\nUse `local` + `full_iteration` only when you specifically want full-iteration\ncapture and can satisfy the tighter constraints.\n\nFor recompute-heavy workloads:\n\n- TE-scoped graphs pair naturally with selective recompute\n- full recompute usually pushes you toward `local` full-iteration graphs or away\n  from graphs entirely\n\nRelated docs:\n\n- @docs\u002Ftraining\u002Fcuda-graphs.md\n- @docs\u002Ftraining\u002Factivation-recomputation.md\n\n## Enablement\n\n### Local full-iteration graph\n\n```python\ncfg.model.cuda_graph_impl = \"local\"\ncfg.model.cuda_graph_scope = [\"full_iteration\"]\ncfg.model.cuda_graph_warmup_steps = 3\ncfg.model.use_te_rng_tracker = True\ncfg.rng.te_rng_tracker = True\ncfg.rerun_state_machine.check_for_nan_in_loss = False\ncfg.ddp.check_for_nan_in_grad = False\n```\n\n### TE scoped graph (dense model)\n\n```python\ncfg.model.cuda_graph_impl = \"transformer_engine\"\ncfg.model.cuda_graph_scope = [\"attn\"]           # or [\"attn\", \"mlp\"]\ncfg.model.cuda_graph_warmup_steps = 3\ncfg.model.use_te_rng_tracker = True\ncfg.rng.te_rng_tracker = True\n```\n\n### TE scoped graph (MoE model)\n\n```python\ncfg.model.cuda_graph_impl = \"transformer_engine\"\ncfg.model.cuda_graph_scope = [\"attn\", \"moe_router\", \"moe_preprocess\"]\ncfg.model.cuda_graph_warmup_steps = 3\ncfg.model.use_te_rng_tracker = True\ncfg.rng.te_rng_tracker = True\n```\n\n### Performance harness CLI\n\n```bash\nuv run python scripts\u002Fperformance\u002Frun_script.py \\\n  -m qwen \\\n  -mr qwen3_30b_a3b \\\n  --task pretrain \\\n  -g h100 \\\n  -c bf16 \\\n  -ng 16 \\\n  --cuda_graph_impl transformer_engine \\\n  --cuda_graph_scope attn,moe_router,moe_preprocess \\\n  ...\n```\n\nValid CLI values live in `scripts\u002Fperformance\u002Fargument_parser.py`:\n- `VALID_CUDA_GRAPH_IMPLS`: `[\"none\", \"local\", \"transformer_engine\"]`\n- `VALID_CUDA_GRAPH_SCOPES`: `[\"full_iteration\", \"attn\", \"mlp\", \"moe\", \"moe_router\", \"moe_preprocess\", \"mamba\"]`\n\nThe performance harness uses a comma-separated `--cuda_graph_scope` value and\nauto-enables `model.use_te_rng_tracker` plus `rng.te_rng_tracker` when\n`--cuda_graph_impl` is not `none`.\n\n### Required constraints\n\n- `use_te_rng_tracker = True` (enforced in `gpt_provider.py`)\n- `full_iteration` scope only with `cuda_graph_impl = \"local\"`\n- `full_iteration` scope requires `check_for_nan_in_loss = False`\n- Do not combine `moe` scope and `moe_router` scope\n- Tensor shapes must be static (fixed seq_length, fixed micro_batch_size)\n- MoE token-dropless routing limits graphable scope to dense modules\n- With `PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True`, set\n  `NCCL_GRAPH_REGISTER=0` (MCore enforces for local impl on arch \u003C sm_100;\n  TE impl asserts unconditionally)\n- CPU offloading is incompatible with CUDA graphs\n- `moe_preprocess` scope requires `moe_router` scope to also be set\n\n### Practical bring-up order\n\n1. Stabilize the eager run first.\n2. Fix sequence length and micro-batch size.\n3. Enable the narrowest useful graph scope.\n4. Confirm replay is active and memory is still acceptable.\n5. Compare eager against graph replay iterations after warmup and capture; do\n   not include the capture step in steady-state timing.\n6. Only then widen scope or combine with overlap features.\n\n## Code Anchors\n\n### Bridge config and validation\n\n```1524:1531:src\u002Fmegatron\u002Fbridge\u002Ftraining\u002Fconfig.py\n        # CUDA graph scope validation: check_for_nan_in_loss must be disabled with full_iteration graph\n        if self.model.cuda_graph_impl == \"local\" and CudaGraphScope.full_iteration in self.model.cuda_graph_scope:\n            assert not self.rerun_state_machine.check_for_nan_in_loss, (\n                \"check_for_nan_in_loss must be disabled when using full_iteration CUDA graph. \"\n                \"Set rerun_state_machine.check_for_nan_in_loss=False.\"\n            )\n        if self.model.cuda_graph_impl == \"none\":\n            self.model.cuda_graph_scope = []\n```\n\n### TE RNG tracker requirement\n\n```213:216:src\u002Fmegatron\u002Fbridge\u002Fmodels\u002Fgpt_provider.py\n        if self.cuda_graph_impl != \"none\":\n            assert getattr(self, \"use_te_rng_tracker\", False), (\n                \"Transformer engine's RNG tracker is required for cudagraphs, it can be \"\n                \"enabled with use_te_rng_tracker=True'.\"\n```\n\n### Graph creation and capture in training loop\n\n```231:255:src\u002Fmegatron\u002Fbridge\u002Ftraining\u002Ftrain.py\n    # Capture CUDA Graphs.\n    cuda_graph_helper = None\n    if model_config.cuda_graph_impl == \"transformer_engine\":\n        cuda_graph_helper = TECudaGraphHelper(...)\n    # ...\n    if config.model.cuda_graph_impl == \"local\" and CudaGraphScope.full_iteration in config.model.cuda_graph_scope:\n        forward_backward_func = FullCudaGraphWrapper(\n            forward_backward_func, cuda_graph_warmup_steps=config.model.cuda_graph_warmup_steps\n        )\n```\n\n### TE graph capture after warmup\n\n```338:350:src\u002Fmegatron\u002Fbridge\u002Ftraining\u002Ftrain.py\n        # Capture CUDA Graphs after warmup.\n        if (\n            model_config.cuda_graph_impl == \"transformer_engine\"\n            and cuda_graph_helper is not None\n            and not cuda_graph_helper.graphs_created()\n            and global_state.train_state.step - start_iteration == model_config.cuda_graph_warmup_steps\n        ):\n            if model_config.cuda_graph_warmup_steps > 0 and should_toggle_forward_pre_hook:\n                disable_forward_pre_hook(model, param_sync=False)\n            cuda_graph_helper.create_cudagraphs()\n            if model_config.cuda_graph_warmup_steps > 0 and should_toggle_forward_pre_hook:\n                enable_forward_pre_hook(model)\n                cuda_graph_helper.cuda_graph_set_manual_hooks()\n```\n\n### RNG initialization\n\n```199:206:src\u002Fmegatron\u002Fbridge\u002Ftraining\u002Finitialize.py\n        _set_random_seed(\n            rng_config.seed,\n            rng_config.data_parallel_random_init,\n            rng_config.te_rng_tracker,\n            rng_config.inference_rng_tracker,\n            use_cudagraphable_rng=(model_config.cuda_graph_impl != \"none\"),\n            pg_collection=pg_collection,\n        )\n```\n\n### Delayed wgrad + CUDA graph interaction\n\n```522:555:src\u002Fmegatron\u002Fbridge\u002Ftraining\u002Fcomm_overlap.py\n            cuda_graph_scope = getattr(model_cfg, \"cuda_graph_scope\", []) or []\n            # ... scope parsing ...\n            if wgrad_in_graph_scope:\n                assert is_te_min_version(\"2.12.0\"), ...\n                assert model_cfg.gradient_accumulation_fusion, ...\n                if attn_scope_enabled:\n                    assert not model_cfg.add_bias_linear and not model_cfg.add_qkv_bias, ...\n```\n\n### Perf harness override helper\n\n```102:124:scripts\u002Fperformance\u002Futils\u002Foverrides.py\ndef _set_cuda_graph_overrides(\n    recipe, cuda_graph_impl=None, cuda_graph_scope=None\n):\n    # Sets impl, scope, and auto-enables te_rng_tracker\n```\n\n### Graph cleanup\n\n```1414:1441:src\u002Fmegatron\u002Fbridge\u002Ftraining\u002Ftrain.py\ndef _delete_cuda_graphs(cuda_graph_helper):\n    # Deletes FullCudaGraphWrapper and TE graph objects to free NCCL buffers\n```\n\n### MCore classes (in 3rdparty\u002FMegatron-LM)\n\n- `CudaGraphManager`: `megatron\u002Fcore\u002Ftransformer\u002Fcuda_graphs.py`\n- `TECudaGraphHelper`: `megatron\u002Fcore\u002Ftransformer\u002Fcuda_graphs.py`\n- `FullCudaGraphWrapper`: `megatron\u002Fcore\u002Ffull_cuda_graph.py`\n- `CudaGraphScope` enum: `megatron\u002Fcore\u002Ftransformer\u002Fenums.py`\n\n### Positive recipe anchors\n\n- `scripts\u002Fperformance\u002Fconfigs\u002Fdeepseek\u002Fdeepseek_workload_base_configs.py`\n- `scripts\u002Fperformance\u002Fconfigs\u002Fqwen\u002Fqwen3_workload_base_configs.py`\n- `scripts\u002Fperformance\u002Fconfigs\u002Fgpt_oss\u002Fgpt_oss_workload_base_configs.py`\n\n### Tests\n\n| File | Coverage |\n|---|---|\n| `tests\u002Funit_tests\u002Ftraining\u002Ftest_config.py` | `full_iteration` NaN-check constraint |\n| `tests\u002Funit_tests\u002Ftraining\u002Ftest_comm_overlap.py` | `delay_wgrad` + CUDA graph interaction |\n| `tests\u002Funit_tests\u002Fmodels\u002Ftest_gpt_full_te_layer_autocast_spec.py` | TE autocast with CUDA graphs |\n| `tests\u002Ffunctional_tests\u002Ftest_groups\u002Frecipes\u002Ftest_llama_recipes_pretrain_cuda_graphs.py` | End-to-end local and TE graph smoke tests |\n| `tests\u002Funit_tests\u002Frecipes\u002Fkimi\u002Ftest_kimi_k2.py` | TE + CUDA graph recipe config |\n| `tests\u002Funit_tests\u002Frecipes\u002Fgpt\u002Ftest_gpt3_175b.py` | TE + CUDA graph recipe config |\n| `tests\u002Funit_tests\u002Frecipes\u002Fqwen_vl\u002Ftest_qwen25_vl_recipes.py` | VLM CUDA graph settings |\n\n## Pitfalls\n\n1. **TE RNG tracker is mandatory**: Setting `cuda_graph_impl` without\n   `use_te_rng_tracker=True` and `rng.te_rng_tracker=True` will assert\n   in the provider.\n\n2. **`full_iteration` requires NaN checks disabled**: The entire fwd+bwd is\n   captured, so loss-NaN checking cannot inspect intermediate values.\n\n3. **MoE scope restrictions**: `moe` scope and `moe_router` scope are\n   mutually exclusive. Token-dropless MoE can only graph `moe_router` and\n   `moe_preprocess`, not the full expert dispatch.\n\n4. **Memory overhead**: CUDA graphs pin all intermediate buffers for the\n   graph's lifetime (no memory reuse). TE scoped graphs add a few GB;\n   full-iteration graphs can increase peak memory by 1.5–2×. `PP > 1`\n   compounds overhead since each stage holds its own graph.\n\n5. **Delayed wgrad interaction**: When `delay_wgrad_compute=True` and\n   attention or MoE router is in `cuda_graph_scope`, additional constraints\n   apply: TE >= 2.12.0, `gradient_accumulation_fusion=True`, and no\n   attention bias.\n\n6. **Variable-length sequences break graphs**: Sequence lengths must be\n   constant across steps. Use padded packed sequences if packing is needed.\n\n7. **Graph cleanup is required**: CUDA graph objects hold NCCL buffer\n   references. Bridge handles this in `_delete_cuda_graphs()` at the end\n   of training, but early exits must call it explicitly.\n\n8. **Older GPU architectures**: On GPUs with compute capability \u003C 10.0\n   (pre-Blackwell), set `NCCL_GRAPH_REGISTER=0` when using\n   `PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True`. Enforced in MCore\n   `CudaGraphManager` (cuda_graphs.py:1428) and `TECudaGraphHelper`\n   (cuda_graphs.py:1697). The TE impl asserts unconditionally regardless\n   of arch.\n\n9. **CPU offloading incompatible**: CUDA graphs cannot be used with CPU\n   offloading. Enforced in MCore `transformer_config.py:1907`.\n\n10. **MoE recompute + moe_router scope**: MoE recompute is not supported\n    with `moe_router` CUDA graph scope when using `cuda_graph_impl =\n    \"transformer_engine\"`. Enforced in MCore `transformer_config.py:1977`.\n\n11. **Layer-level recompute requires `full_iteration` scope**: Using\n    `recompute_granularity=\"full\"` with `recompute_num_layers` (recompute N\n    whole transformer layers) is incompatible with TE-scoped graphs. MCore\n    calls this \"full\" granularity even though you're selecting how many\n    layers — the name refers to recomputing the full layer, not full model.\n    Any TE-scoped scope (`attn`, `mlp`, `moe_router`, etc.) will assert:\n    `AssertionError: full recompute is only supported with full iteration CUDA graph.`\n    This commonly hits FP8 configs that default to TE-scoped graphs (e.g.\n    `LLAMA3_70B_SFT_CONFIG_H100_FP8_CS_V1` uses `cuda_graph_impl=\n    \"transformer_engine\"`, `cuda_graph_scope=\"mlp\"`). Fix: use submodule\n    recompute (`recompute_granularity=\"selective\"` + `recompute_modules`),\n    disable CUDA graphs, or switch to `local` + `full_iteration`. Enforced\n    in MCore `transformer_config.py:2001-2005`. See also\n    @skills\u002Fnemo-mbridge-perf-activation-recompute\u002FSKILL.md.\n\n12. **Benchmark numbers are workload-specific**: graph wins are usually real\n    when host overhead is visible, but the exact gain depends on batch shape,\n    PP depth, recompute, dispatcher backend, and whether the eager baseline was\n    already optimized.\n\n13. **A successful capture is not a speedup guarantee**: On 2026-05-18,\n    Qwen3 30B A3B H100 BF16 pretrain with the all-to-all dispatcher captured\n    TE-scoped `attn,moe_router,moe_preprocess` graphs successfully (`48`\n    graphable layers, about `6.9 s` capture time on rank 0), but replay\n    iterations 5-8 averaged `42.00 s` versus `41.36 s` for eager. Treat\n    scoped graphs as a bring-up candidate and validate on the target stack.\n\n## Verification\n\n### Unit tests\n\n```bash\nuv run python -m pytest \\\n  tests\u002Funit_tests\u002Ftraining\u002Ftest_config.py -k \"cuda_graph\" \\\n  tests\u002Funit_tests\u002Ftraining\u002Ftest_comm_overlap.py -k \"cuda_graph\" \\\n  tests\u002Funit_tests\u002Fmodels\u002Ftest_gpt_full_te_layer_autocast_spec.py -k \"cuda_graph\" -q\n```\n\n### Functional smoke test (requires GPU)\n\n```bash\nuv run python -m pytest \\\n  tests\u002Ffunctional_tests\u002Ftest_groups\u002Frecipes\u002Ftest_llama_recipes_pretrain_cuda_graphs.py -q\n```\n\n### Success criteria\n\n- Unit tests pass, covering config validation for both `local` and\n  `transformer_engine` implementations.\n- Functional test completes training steps with both CUDA graph\n  implementations.\n- No NCCL errors or illegal memory access in logs.\n","# CUDA Graphs\n\nStable documentation: @docs\u002Ftraining\u002Fcuda-graphs.md\nCard: @skills\u002Fnemo-mbridge-perf-cuda-graphs\u002Fcard.yaml\n\n\u003C!-- NVSkills CI refresh: 2026-06-15. No instruction changes. -->\n\n## What It Is\n\nCUDA graphs capture GPU operations once and replay them with minimal\nhost-driver overhead. Bridge supports two implementations:\n\n| `cuda_graph_impl` | Mechanism | Scope support |\n|---|---|---|\n| `\"local\"` | MCore `FullCudaGraphWrapper` wrapping entire fwd+bwd | `full_iteration` |\n| `\"transformer_engine\"` | TE `make_graphed_callables()` per layer | `attn`, `mlp`, `moe`, `moe_router`, `moe_preprocess`, `mamba` |\n\n## Quick Decision\n\nStart with TE-scoped graphs for most training workloads, then verify replay\ntiming against eager on the same dispatcher, layout, and container:\n\n- dense models: `attn`, then optionally `mlp`\n- dropless MoE: `attn moe_router moe_preprocess`\n- VLMs: the same dropless-MoE scope, but only after the real-data path is stable\n\nUse `local` + `full_iteration` only when you specifically want full-iteration\ncapture and can satisfy the tighter constraints.\n\nFor recompute-heavy workloads:\n\n- TE-scoped graphs pair naturally with selective recompute\n- full recompute usually pushes you toward `local` full-iteration graphs or away\n  from graphs entirely\n\nRelated docs:\n\n- @docs\u002Ftraining\u002Fcuda-graphs.md\n- @docs\u002Ftraining\u002Factivation-recomputation.md\n\n## Enablement\n\n### Local full-iteration graph\n\n```python\ncfg.model.cuda_graph_impl = \"local\"\ncfg.model.cuda_graph_scope = [\"full_iteration\"]\ncfg.model.cuda_graph_warmup_steps = 3\ncfg.model.use_te_rng_tracker = True\ncfg.rng.te_rng_tracker = True\ncfg.rerun_state_machine.check_for_nan_in_loss = False\ncfg.ddp.check_for_nan_in_grad = False\n```\n\n### TE scoped graph (dense model)\n\n```python\ncfg.model.cuda_graph_impl = \"transformer_engine\"\ncfg.model.cuda_graph_scope = [\"attn\"]           # or [\"attn\", \"mlp\"]\ncfg.model.cuda_graph_warmup_steps = 3\ncfg.model.use_te_rng_tracker = True\ncfg.rng.te_rng_tracker = True\n```\n\n### TE scoped graph (MoE model)\n\n```python\ncfg.model.cuda_graph_impl = \"transformer_engine\"\ncfg.model.cuda_graph_scope = [\"attn\", \"moe_router\", \"moe_preprocess\"]\ncfg.model.cuda_graph_warmup_steps = 3\ncfg.model.use_te_rng_tracker = True\ncfg.rng.te_rng_tracker = True\n```\n\n### Performance harness CLI\n\n```bash\nuv run python scripts\u002Fperformance\u002Frun_script.py \\\n  -m qwen \\\n  -mr qwen3_30b_a3b \\\n  --task pretrain \\\n  -g h100 \\\n  -c bf16 \\\n  -ng 16 \\\n  --cuda_graph_impl transformer_engine \\\n  --cuda_graph_scope attn,moe_router,moe_preprocess \\\n  ...\n```\n\nValid CLI values live in `scripts\u002Fperformance\u002Fargument_parser.py`:\n- `VALID_CUDA_GRAPH_IMPLS`: `[\"none\", \"local\", \"transformer_engine\"]`\n- `VALID_CUDA_GRAPH_SCOPES`: `[\"full_iteration\", \"attn\", \"mlp\", \"moe\", \"moe_router\", \"moe_preprocess\", \"mamba\"]`\n\nThe performance harness uses a comma-separated `--cuda_graph_scope` value and\nauto-enables `model.use_te_rng_tracker` plus `rng.te_rng_tracker` when\n`--cuda_graph_impl` is not `none`.\n\n### Required constraints\n\n- `use_te_rng_tracker = True` (enforced in `gpt_provider.py`)\n- `full_iteration` scope only with `cuda_graph_impl = \"local\"`\n- `full_iteration` scope requires `check_for_nan_in_loss = False`\n- Do not combine `moe` scope and `moe_router` scope\n- Tensor shapes must be static (fixed seq_length, fixed micro_batch_size)\n- MoE token-dropless routing limits graphable scope to dense modules\n- With `PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True`, set\n  `NCCL_GRAPH_REGISTER=0` (MCore enforces for local impl on arch \u003C sm_100;\n  TE impl asserts unconditionally)\n- CPU offloading is incompatible with CUDA graphs\n- `moe_preprocess` scope requires `moe_router` scope to also be set\n\n### Practical bring-up order\n\n1. Stabilize the eager run first.\n2. Fix sequence length and micro-batch size.\n3. Enable the narrowest useful graph scope.\n4. Confirm replay is active and memory is still acceptable.\n5. Compare eager against graph replay iterations after warmup and capture; do\n   not include the capture step in steady-state timing.\n6. Only then widen scope or combine with overlap features.\n\n## Code Anchors\n\n### Bridge config and validation\n\n```1524:1531:src\u002Fmegatron\u002Fbridge\u002Ftraining\u002Fconfig.py\n        # CUDA graph scope validation: check_for_nan_in_loss must be disabled with full_iteration graph\n        if self.model.cuda_graph_impl == \"local\" and CudaGraphScope.full_iteration in self.model.cuda_graph_scope:\n            assert not self.rerun_state_machine.check_for_nan_in_loss, (\n                \"check_for_nan_in_loss must be disabled when using full_iteration CUDA graph. \"\n                \"Set rerun_state_machine.check_for_nan_in_loss=False.\"\n            )\n        if self.model.cuda_graph_impl == \"none\":\n            self.model.cuda_graph_scope = []\n```\n\n### TE RNG tracker requirement\n\n```213:216:src\u002Fmegatron\u002Fbridge\u002Fmodels\u002Fgpt_provider.py\n        if self.cuda_graph_impl != \"none\":\n            assert getattr(self, \"use_te_rng_tracker\", False), (\n                \"Transformer engine's RNG tracker is required for cudagraphs, it can be \"\n                \"enabled with use_te_rng_tracker=True'.\"\n```\n\n### Graph creation and capture in training loop\n\n```231:255:src\u002Fmegatron\u002Fbridge\u002Ftraining\u002Ftrain.py\n    # Capture CUDA Graphs.\n    cuda_graph_helper = None\n    if model_config.cuda_graph_impl == \"transformer_engine\":\n        cuda_graph_helper = TECudaGraphHelper(...)\n    # ...\n    if config.model.cuda_graph_impl == \"local\" and CudaGraphScope.full_iteration in config.model.cuda_graph_scope:\n        forward_backward_func = FullCudaGraphWrapper(\n            forward_backward_func, cuda_graph_warmup_steps=config.model.cuda_graph_warmup_steps\n        )\n```\n\n### TE graph capture after warmup\n\n```338:350:src\u002Fmegatron\u002Fbridge\u002Ftraining\u002Ftrain.py\n        # Capture CUDA Graphs after warmup.\n        if (\n            model_config.cuda_graph_impl == \"transformer_engine\"\n            and cuda_graph_helper is not None\n            and not cuda_graph_helper.graphs_created()\n            and global_state.train_state.step - start_iteration == model_config.cuda_graph_warmup_steps\n        ):\n            if model_config.cuda_graph_warmup_steps > 0 and should_toggle_forward_pre_hook:\n                disable_forward_pre_hook(model, param_sync=False)\n            cuda_graph_helper.create_cudagraphs()\n            if model_config.cuda_graph_warmup_steps > 0 and should_toggle_forward_pre_hook:\n                enable_forward_pre_hook(model)\n                cuda_graph_helper.cuda_graph_set_manual_hooks()\n```\n\n### RNG initialization\n\n```199:206:src\u002Fmegatron\u002Fbridge\u002Ftraining\u002Finitialize.py\n        _set_random_seed(\n            rng_config.seed,\n            rng_config.data_parallel_random_init,\n            rng_config.te_rng_tracker,\n            rng_config.inference_rng_tracker,\n            use_cudagraphable_rng=(model_config.cuda_graph_impl != \"none\"),\n            pg_collection=pg_collection,\n        )\n```\n\n### Delayed wgrad + CUDA graph interaction\n\n```522:555:src\u002Fmegatron\u002Fbridge\u002Ftraining\u002Fcomm_overlap.py\n            cuda_graph_scope = getattr(model_cfg, \"cuda_graph_scope\", []) or []\n            # ... scope parsing ...\n            if wgrad_in_graph_scope:\n                assert is_te_min_version(\"2.12.0\"), ...\n                assert model_cfg.gradient_accumulation_fusion, ...\n                if attn_scope_enabled:\n                    assert not model_cfg.add_bias_linear and not model_cfg.add_qkv_bias, ...\n```\n\n### Perf harness override helper\n\n```102:124:scripts\u002Fperformance\u002Futils\u002Foverrides.py\ndef _set_cuda_graph_overrides(\n    recipe, cuda_graph_impl=None, cuda_graph_scope=None\n):\n    # Sets impl, scope, and auto-enables te_rng_tracker\n```\n\n### Graph cleanup\n\n```1414:1441:src\u002Fmegatron\u002Fbridge\u002Ftraining\u002Ftrain.py\ndef _delete_cuda_graphs(cuda_graph_helper):\n    # Deletes FullCudaGraphWrapper and TE graph objects to free NCCL buffers\n```\n\n### MCore classes (in 3rdparty\u002FMegatron-LM)\n\n- `CudaGraphManager`: `megatron\u002Fcore\u002Ftransformer\u002Fcuda_graphs.py`\n- `TECudaGraphHelper`: `megatron\u002Fcore\u002Ftransformer\u002Fcuda_graphs.py`\n- `FullCudaGraphWrapper`: `megatron\u002Fcore\u002Ffull_cuda_graph.py`\n- `CudaGraphScope` enum: `megatron\u002Fcore\u002Ftransformer\u002Fenums.py`\n\n### Positive recipe anchors\n\n- `scripts\u002Fperformance\u002Fconfigs\u002Fdeepseek\u002Fdeepseek_workload_base_configs.py`\n- `scripts\u002Fperformance\u002Fconfigs\u002Fqwen\u002Fqwen3_workload_base_configs.py`\n- `scripts\u002Fperformance\u002Fconfigs\u002Fgpt_oss\u002Fgpt_oss_workload_base_configs.py`\n\n### Tests\n\n| File | Coverage |\n|---|---|\n| `tests\u002Funit_tests\u002Ftraining\u002Ftest_config.py` | `full_iteration` NaN-check constraint |\n| `tests\u002Funit_tests\u002Ftraining\u002Ftest_comm_overlap.py` | `delay_wgrad` + CUDA graph interaction |\n| `tests\u002Funit_tests\u002Fmodels\u002Ftest_gpt_full_te_layer_autocast_spec.py` | TE autocast with CUDA graphs |\n| `tests\u002Ffunctional_tests\u002Ftest_groups\u002Frecipes\u002Ftest_llama_recipes_pretrain_cuda_graphs.py` | End-to-end local and TE graph smoke tests |\n| `tests\u002Funit_tests\u002Frecipes\u002Fkimi\u002Ftest_kimi_k2.py` | TE + CUDA graph recipe config |\n| `tests\u002Funit_tests\u002Frecipes\u002Fgpt\u002Ftest_gpt3_175b.py` | TE + CUDA graph recipe config |\n| `tests\u002Funit_tests\u002Frecipes\u002Fqwen_vl\u002Ftest_qwen25_vl_recipes.py` | VLM CUDA graph settings |\n\n## Pitfalls\n\n1. **TE RNG tracker is mandatory**: Setting `cuda_graph_impl` without\n   `use_te_rng_tracker=True` and `rng.te_rng_tracker=True` will assert\n   in the provider.\n\n2. **`full_iteration` requires NaN checks disabled**: The entire fwd+bwd is\n   captured, so loss-NaN checking cannot inspect intermediate values.\n\n3. **MoE scope restrictions**: `moe` scope and `moe_router` scope are\n   mutually exclusive. Token-dropless MoE can only graph `moe_router` and\n   `moe_preprocess`, not the full expert dispatch.\n\n4. **Memory overhead**: CUDA graphs pin all intermediate buffers for the\n   graph's lifetime (no memory reuse). TE scoped graphs add a few GB;\n   full-iteration graphs can increase peak memory by 1.5–2×. `PP > 1`\n   compounds overhead since each stage holds its own graph.\n\n5. **Delayed wgrad interaction**: When `delay_wgrad_compute=True` and\n   attention or MoE router is in `cuda_graph_scope`, additional constraints\n   apply: TE >= 2.12.0, `gradient_accumulation_fusion=True`, and no\n   attention bias.\n\n6. **Variable-length sequences break graphs**: Sequence lengths must be\n   constant across steps. Use padded packed sequences if packing is needed.\n\n7. **Graph cleanup is required**: CUDA graph objects hold NCCL buffer\n   references. Bridge handles this in `_delete_cuda_graphs()` at the end\n   of training, but early exits must call it explicitly.\n\n8. **Older GPU architectures**: On GPUs with compute capability \u003C 10.0\n   (pre-Blackwell), set `NCCL_GRAPH_REGISTER=0` when using\n   `PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True`. Enforced in MCore\n   `CudaGraphManager` (cuda_graphs.py:1428) and `TECudaGraphHelper`\n   (cuda_graphs.py:1697). The TE impl asserts unconditionally regardless\n   of arch.\n\n9. **CPU offloading incompatible**: CUDA graphs cannot be used with CPU\n   offloading. Enforced in MCore `transformer_config.py:1907`.\n\n10. **MoE recompute + moe_router scope**: MoE recompute is not supported\n    with `moe_router` CUDA graph scope when using `cuda_graph_impl =\n    \"transformer_engine\"`. Enforced in MCore `transformer_config.py:1977`.\n\n11. **Layer-level recompute requires `full_iteration` scope**: Using\n    `recompute_granularity=\"full\"` with `recompute_num_layers` (recompute N\n    whole transformer layers) is incompatible with TE-scoped graphs. MCore\n    calls this \"full\" granularity even though you're selecting how many\n    layers — the name refers to recomputing the full layer, not full model.\n    Any TE-scoped scope (`attn`, `mlp`, `moe_router`, etc.) will assert:\n    `AssertionError: full recompute is only supported with full iteration CUDA graph.`\n    This commonly hits FP8 configs that default to TE-scoped graphs (e.g.\n    `LLAMA3_70B_SFT_CONFIG_H100_FP8_CS_V1` uses `cuda_graph_impl=\n    \"transformer_engine\"`, `cuda_graph_scope=\"mlp\"`). Fix: use submodule\n    recompute (`recompute_granularity=\"selective\"` + `recompute_modules`),\n    disable CUDA graphs, or switch to `local` + `full_iteration`. Enforced\n    in MCore `transformer_config.py:2001-2005`. See also\n    @skills\u002Fnemo-mbridge-perf-activation-recompute\u002FSKILL.md.\n\n12. **Benchmark numbers are workload-specific**: graph wins are usually real\n    when host overhead is visible, but the exact gain depends on batch shape,\n    PP depth, recompute, dispatcher backend, and whether the eager baseline was\n    already optimized.\n\n13. **A successful capture is not a speedup guarantee**: On 2026-05-18,\n    Qwen3 30B A3B H100 BF16 pretrain with the all-to-all dispatcher captured\n    TE-scoped `attn,moe_router,moe_preprocess` graphs successfully (`48`\n    graphable layers, about `6.9 s` capture time on rank 0), but replay\n    iterations 5-8 averaged `42.00 s` versus `41.36 s` for eager. Treat\n    scoped graphs as a bring-up candidate and validate on the target stack.\n\n## Verification\n\n### Unit tests\n\n```bash\nuv run python -m pytest \\\n  tests\u002Funit_tests\u002Ftraining\u002Ftest_config.py -k \"cuda_graph\" \\\n  tests\u002Funit_tests\u002Ftraining\u002Ftest_comm_overlap.py -k \"cuda_graph\" \\\n  tests\u002Funit_tests\u002Fmodels\u002Ftest_gpt_full_te_layer_autocast_spec.py -k \"cuda_graph\" -q\n```\n\n### Functional smoke test (requires GPU)\n\n```bash\nuv run python -m pytest \\\n  tests\u002Ffunctional_tests\u002Ftest_groups\u002Frecipes\u002Ftest_llama_recipes_pretrain_cuda_graphs.py -q\n```\n\n### Success criteria\n\n- Unit tests pass, covering config validation for both `local` and\n  `transformer_engine` implementations.\n- Functional test completes training steps with both CUDA graph\n  implementations.\n- No NCCL errors or illegal memory access in logs.\n",{"name":5,"license":15,"description":7,"when_to_use":44},"Reducing host-driver overhead via CUDA graphs, or tracing a crash or regression to a CUDA graph config change; 'cuda_graph_impl', 'full iteration graph', 'TE scoped graph', 'graphed callables', 'CUDA graph capture'.","main","7a940b8e5af16c95e5c190a524421d32fc7445a9",".agent\u002Fskills\u002Fnemo-mbridge-perf-cuda-graphs","https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp","https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui","https:\u002F\u002Fneuroads.com.br","2026-08-12 00:42:44",{"source":8,"skillName":5,"commands":53,"prompt":63,"zipAvailable":64},[54,57,60],{"tool":55,"command":56},"npx","npx skills add headmktlucca-ui\u002Fneuroads-lp --skill nemo-mbridge-perf-cuda-graphs",{"tool":58,"command":59},"bunx","bunx skills add headmktlucca-ui\u002Fneuroads-lp --skill nemo-mbridge-perf-cuda-graphs",{"tool":61,"command":62},"pnpm","pnpm dlx skills add headmktlucca-ui\u002Fneuroads-lp --skill nemo-mbridge-perf-cuda-graphs","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp\u002Fblob\u002Fmain\u002F.agent\u002Fskills\u002Fnemo-mbridge-perf-cuda-graphs\u002FSKILL.md",true,[66,72,76,80,84],{"path":67,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":70,"sourceHtmlUrl":71},"BENCHMARK.md","REFERENCE","参考文档",3984,"https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp\u002Fblob\u002Fmain\u002F.agent\u002Fskills\u002Fnemo-mbridge-perf-cuda-graphs\u002FBENCHMARK.md",{"path":73,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":74,"sourceHtmlUrl":75},"card.yaml",13862,"https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp\u002Fblob\u002Fmain\u002F.agent\u002Fskills\u002Fnemo-mbridge-perf-cuda-graphs\u002Fcard.yaml",{"path":77,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":78,"sourceHtmlUrl":79},"evals\u002Fevals.json",1400,"https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp\u002Fblob\u002Fmain\u002F.agent\u002Fskills\u002Fnemo-mbridge-perf-cuda-graphs\u002Fevals\u002Fevals.json",{"path":81,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":82,"sourceHtmlUrl":83},"skill-card.md",3978,"https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp\u002Fblob\u002Fmain\u002F.agent\u002Fskills\u002Fnemo-mbridge-perf-cuda-graphs\u002Fskill-card.md",{"path":85,"resourceType":86,"resourceTypeDesc":87,"sizeBytes":88,"sourceHtmlUrl":89},"skill.oms.sig","OTHER","其他",4821,"https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp\u002Fblob\u002Fmain\u002F.agent\u002Fskills\u002Fnemo-mbridge-perf-cuda-graphs\u002Fskill.oms.sig",[91,118,142,168,186,221],{"skillNo":92,"name":93,"nameZh":6,"description":94,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":95,"licenseFileUrl":6,"sourceHtmlUrl":96,"categories":97,"keywords":106,"publishedAt":39},"01M6PTDCZTXTGSTX4RFK901YSZ","xunit-skill","Generates xUnit.net tests in C#. Covers Fact\u002FTheory, constructor injection, IClassFixture, and FluentAssertions. Use when user mentions \"xUnit\", \"[Fact]\", \"[Theory]\", \"Assert.Equal\", \"C# xUnit\". Triggers on: \"xUnit\", \"[Fact]\", \"[Theory]\", \"Assert.Equal C#\", \"xUnit.net\".","MIT","https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fxunit-skill\u002FSKILL.md",[98,103],{"categoryNo":99,"categoryName":100,"taxonomyType":101,"taxonomyTypeDesc":102},"01JBSEEDCAT000000000000008","测试与质量","SCENARIO","使用场景",{"categoryNo":104,"categoryName":105,"taxonomyType":101,"taxonomyTypeDesc":102},"01JBSEEDCAT000000000000023","Skill与智能体开发",[107,108,109,110,111,112,113,114,115,116,117],"xunit","xunit skill","testing","injection","user","use","tests","triggers","unit","unit-testing","C#",{"skillNo":119,"name":120,"nameZh":6,"description":121,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":95,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":126,"publishedAt":39},"01M6PTCB59ZTG5FTMWGPYEMMBP","xcuitest-skill","Generates XCUITest UI tests for iOS\u002FiPadOS apps in Swift. Apple's native testing framework for reliable, fast UI automation. Supports local simulators and TestMu AI cloud real devices. Use when user mentions \"XCUITest\", \"XCTest\", \"iOS UI test\", \"Swift test\", \"XCUIApplication\". Triggers on: \"XCUITest\", \"XCTest UI\", \"iOS UI test\", \"Swift UI test\", \"XCUIApplication\", \"TestMu\".","https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fxcuitest-skill\u002FSKILL.md",[124,125],{"categoryNo":99,"categoryName":100,"taxonomyType":101,"taxonomyTypeDesc":102},{"categoryNo":104,"categoryName":105,"taxonomyType":101,"taxonomyTypeDesc":102},[127,128,109,129,130,131,132,133,112,134,135,136,24,137,113,114,138,139,140,141],"xcuitest","xcuitest skill","automation","test","testing framework","ios","devices","mobile","mobile-testing","ui test","apple","apps","native","for","objective",{"skillNo":143,"name":144,"nameZh":6,"description":145,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":95,"licenseFileUrl":6,"sourceHtmlUrl":146,"categories":147,"keywords":152,"publishedAt":39},"01M6PTATMNTY9NF4J7KSR76YK6","world-builder","Create and manage generative game zones for Dorothy's Pokemon-style world. Use this skill when creating, updating, or designing game worlds via MCP tools.","https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fworld-builder\u002FSKILL.md",[148,151],{"categoryNo":149,"categoryName":150,"taxonomyType":101,"taxonomyTypeDesc":102},"01JBSEEDCAT000000000000015","视觉设计",{"categoryNo":104,"categoryName":105,"taxonomyType":101,"taxonomyTypeDesc":102},[153,154,155,156,157,158,159,160,112,161,162,163,164,165,166,140,167],"builder","world","world builder","MCP","create","mcp tools","Tools","game","pokemon","manage","style","via","theme","zone","generative",{"skillNo":169,"name":170,"nameZh":6,"description":171,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":95,"licenseFileUrl":6,"sourceHtmlUrl":172,"categories":173,"keywords":176,"publishedAt":39},"01M6PT9Z92JTSQEHE1QR0NNW5F","webdriverio-skill","Generates WebdriverIO (WDIO) automation tests in JavaScript or TypeScript. Supports local and TestMu AI cloud. Use when user mentions \"WebdriverIO\", \"WDIO\", \"wdio.conf\", \"browser.url\", \"$\", \"$$\". Triggers on: \"WebdriverIO\", \"WDIO\", \"wdio\", \"browser.$\".","https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fwebdriverio-skill\u002FSKILL.md",[174,175],{"categoryNo":99,"categoryName":100,"taxonomyType":101,"taxonomyTypeDesc":102},{"categoryNo":104,"categoryName":105,"taxonomyType":101,"taxonomyTypeDesc":102},[177,109,178,129,179,180,181,182,111,112,183,24,113,114,184,185],"webdriverio skill","typescript","javascript","browser","cloud","e2e","e2e-testing","URL","conf",{"skillNo":187,"name":188,"nameZh":6,"description":189,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":95,"licenseFileUrl":6,"sourceHtmlUrl":190,"categories":191,"keywords":201,"publishedAt":39},"01M6PT9NVK36ZWCQ69YXK3FR4K","web-design-guidelines","Web platform design and accessibility guidelines. Use when building web interfaces, auditing accessibility, implementing responsive layouts, or reviewing web UI code. Triggers on tasks involving HTML, CSS, web components, WCAG compliance, responsive design, or web performance.","https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fweb\u002FSKILL.md",[192,195,196],{"categoryNo":193,"categoryName":194,"taxonomyType":101,"taxonomyTypeDesc":102},"01JBSEEDCAT000000000000009","前端开发",{"categoryNo":149,"categoryName":150,"taxonomyType":101,"taxonomyTypeDesc":102},{"categoryNo":197,"categoryName":198,"taxonomyType":199,"taxonomyTypeDesc":200},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,114,220],"design","web","guidelines","web design guidelines","web design","css","performance","components","web components","tasks","code","web performance","ui","platform design","html","responsive design","responsive","platform","implementing",{"skillNo":222,"name":223,"nameZh":6,"description":224,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":95,"licenseFileUrl":6,"sourceHtmlUrl":225,"categories":226,"keywords":229,"publishedAt":39},"01M6PT9A3JKRE3X34276F2FW5R","watchos-design-guidelines","Apple Human Interface Guidelines for Apple Watch. Use when building watchOS apps, complications, or workout features. Triggers on tasks involving Watch UI, Digital Crown, glanceable interfaces, or wrist-based interactions.","https:\u002F\u002Fgithub.com\u002Fheadmktlucca-ui\u002Fneuroads-lp\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fwatchos\u002FSKILL.md",[227,228],{"categoryNo":149,"categoryName":150,"taxonomyType":101,"taxonomyTypeDesc":102},{"categoryNo":197,"categoryName":198,"taxonomyType":199,"taxonomyTypeDesc":200},[202,204,230,211,214,112,231,232,137,219,233,114,138,234,140,235,236],"watchos design guidelines","workout","human","watch","interface","platform-design","features"]