Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions megatron/core/transformer/transformer_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1722,13 +1722,13 @@ def _get_submodules_under_cudagraphs(self):
"""
submodules = super()._get_submodules_under_cudagraphs()

if not self.config.cuda_graph_scope:
if not self.config.cuda_graph_modules:
return submodules

if CudaGraphScope.attn in self.config.cuda_graph_scope:
if CudaGraphModule.attn in self.config.cuda_graph_modules:
submodules.append(self.self_attention_hyper_connection)
# HC layer rejects MoE MLPs in __init__, so only the dense (mlp) scope applies.
if CudaGraphScope.mlp in self.config.cuda_graph_scope:
if CudaGraphModule.mlp in self.config.cuda_graph_modules:
submodules.append(self.mlp_hyper_connection)
return submodules

Expand Down
16 changes: 6 additions & 10 deletions tests/unit_tests/transformer/test_transformer_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
model_parallel_cuda_manual_seed,
)
from megatron.core.transformer.cuda_graphs import CudaGraphManager, _CudagraphGlobalRecord
from megatron.core.transformer.enums import InferenceCudaGraphScope
from megatron.core.transformer.enums import CudaGraphModule, InferenceCudaGraphScope
from megatron.core.transformer.transformer_config import TransformerConfig
from megatron.core.transformer.transformer_layer import (
HyperConnectionTransformerLayer,
Expand Down Expand Up @@ -794,18 +794,14 @@ def test_submodules_under_cudagraphs_includes_hyper_connection(self):
(mapping_proj, alpha_*, bias) will not get proper pre-forward hooks during
graph replay, leading to stale parameter values.
"""
layer, config = self._create_mhc_layer()
layer, config = self._create_mhc_layer(
cuda_graph_modules=[CudaGraphModule.attn, CudaGraphModule.mlp]
)

submodules = layer._get_submodules_under_cudagraphs()

hc_modules_found = any(
hasattr(m, 'mapping_proj') for submod in submodules for m in submod.modules()
)
assert hc_modules_found, (
"_get_submodules_under_cudagraphs does not include HyperConnectionModule. "
"Parameters like mapping_proj, alpha_pre/post/res will not be updated "
"during CUDA graph replay."
)
assert layer.self_attention_hyper_connection in submodules
assert layer.mlp_hyper_connection in submodules

def test_forward_through_te_cuda_graph_capture_path(self):
"""_te_cuda_graph_capture must produce correct output shapes for mHC.
Expand Down
Loading