bridge.utils.cuda_graph#

Module Contents#

Functions#

_as_list

_member_name

_member_name_list

_member_names

_supports_cuda_graph_modules

_module_value

cuda_graph_module_names

Return configured per-layer CUDA graph module names.

set_cuda_graph_modules

Set per-layer CUDA graph modules using the current MCore API when available.

clear_cuda_graph_modules

Clear per-layer CUDA graph modules using the active MCore API.

set_full_iteration_cuda_graph

Enable full-iteration CUDA graph capture using the current MCore API.

has_cuda_graph_module

Return whether a per-layer CUDA graph module is enabled.

is_full_iteration_cuda_graph

Return whether config enables full-iteration CUDA graph capture.

validate_cuda_graph_configuration

Validate Bridge-supported CUDA graph implementation/scope combinations.

uses_local_cuda_graph_manager

Return whether Bridge should create a local MCore CudaGraphManager.

enable_hybrid_cuda_graph_pairs

Capture each Hybrid mixer position and the feed-forward position after it as one TE CUDA graph.

API#

bridge.utils.cuda_graph._as_list(value: Any) → list[Any]#
bridge.utils.cuda_graph._member_name(value: Any) → str#
bridge.utils.cuda_graph._member_name_list(value: Any) → list[str]#
bridge.utils.cuda_graph._member_names(value: Any) → set[str]#
bridge.utils.cuda_graph._supports_cuda_graph_modules(config: Any) → bool#
bridge.utils.cuda_graph._module_value(name: str)#
bridge.utils.cuda_graph.cuda_graph_module_names(config: Any) → list[str]#

Return configured per-layer CUDA graph module names.

bridge.utils.cuda_graph.set_cuda_graph_modules(
config: Any,
modules: Any,
) → None#

Set per-layer CUDA graph modules using the current MCore API when available.

bridge.utils.cuda_graph.clear_cuda_graph_modules(config: Any) → None#

Clear per-layer CUDA graph modules using the active MCore API.

bridge.utils.cuda_graph.set_full_iteration_cuda_graph(config: Any) → None#

Enable full-iteration CUDA graph capture using the current MCore API.

bridge.utils.cuda_graph.has_cuda_graph_module(config: Any, module: Any) → bool#

Return whether a per-layer CUDA graph module is enabled.

Supports both the current MCore cuda_graph_modules API and the deprecated cuda_graph_scope values still present in older Bridge configs.

bridge.utils.cuda_graph.is_full_iteration_cuda_graph(config: Any) → bool#

Return whether config enables full-iteration CUDA graph capture.

bridge.utils.cuda_graph.validate_cuda_graph_configuration(
config: Any,
*,
config_name: str = 'model',
) → None#

Validate Bridge-supported CUDA graph implementation/scope combinations.

bridge.utils.cuda_graph.uses_local_cuda_graph_manager(config: Any) → bool#

Return whether Bridge should create a local MCore CudaGraphManager.

bridge.utils.cuda_graph.enable_hybrid_cuda_graph_pairs(config: Any) → bool#

Capture each Hybrid mixer position and the feed-forward position after it as one TE CUDA graph.

Hybrid models such as Qwen3.5 run each decoder block as two positions, the mixer (attention or Gated DeltaNet) and its MoE or MLP, so per-layer Transformer Engine graphs launch two forward and two backward graphs per block. Megatron-Core’s TransformerConfig.cuda_graph_pair_hybrid_layers captures each such pair as one graph, which halves the graph launches of the decoder blocks; Megatron-Core decides which adjacent positions it can pair. The same field also graphs the layers of Hybrid MTP blocks, which per-layer graphs leave eager, except with keep_mtp_in_bf16 in FP8/FP4 training or mtp_use_repeated_layer over more than one MTP depth. Losses and gradients stay bitwise identical. On a Megatron-Core without the field this changes nothing: depending on the config class, assigning an unknown field would raise or leave an unused attribute, so the assignment is guarded, as in _select_gdn_kernel_backend.

Parameters:

config – Model config or provider to update. A Hybrid model config forwards the field to its transformer config.

Returns:

Whether Megatron-Core has the field and it was set.