core.tensor_parallel.gtp_cuda_graphs#

CUDA-graph lifecycle support for Generalized Tensor Parallelism (GTP).

This module owns state that exists only for local CUDA-graph capture and replay:

  • capture-local ownership of asynchronous GTP communication;

  • persistent wgrad ring buffers whose lifetime may cross graph boundaries;

  • routing graph-owned allocations into the shared CUDA-graph memory pool.

Module Contents#

Classes#

GraphWgradRingSlot

One persistent wgrad slot guarded by its reduce-scatter completion event.

GTPCaptureCommState

GTP work and parameter-readiness dependencies owned by one capture or warmup pass.

Functions#

preserve_gtp_prefetch_state

Preserve cross-graph AG handoffs while a local graph warms up.

register_capture_comm

Register communication with the active capture, if one exists.

register_capture_wgrad_finalize

Record one GRAPHED GTP wgrad-finalization occurrence with the active capture.

register_capture_params_to_ensure_ready

Record GTP parameter reads that need publication before graph replay.

register_capture_wgrad_ring_slot

Register a ring slot with the active capture, if one exists.

track_gtp_capture_comms

Track asynchronous GTP work issued during one capture or warmup pass.

allocate_graph_wgrad_rings

Allocate bounded persistent inputs for cross-graph asynchronous reduce-scatter.

clear_graph_wgrad_rings

Drop every ring slot so a rebuilt model reallocates them.

set_cuda_graph_mempool

Register the shared memory pool used for graph-owned GTP allocations.

cuda_graph_pool_allocation

Route allocations in this context into the registered CUDA-graph pool.

Data#

API#

core.tensor_parallel.gtp_cuda_graphs.logger#

‘getLogger(…)’

core.tensor_parallel.gtp_cuda_graphs.preserve_gtp_prefetch_state(
params: Iterable[torch.nn.Parameter],
)#

Preserve cross-graph AG handoffs while a local graph warms up.

A local graph’s first GTP weight can be prefetched and drained by the preceding forward or backward graph. Runner-local warmup consumes that readiness without rerunning the producer, and can create outgoing readiness of its own. Capture must therefore see the same forward and recompute-forward handoff state that existed before each warmup pass. Completed Work handles are intentionally not restored; the producer’s external event carries the device dependency.

class core.tensor_parallel.gtp_cuda_graphs.GraphWgradRingSlot#

One persistent wgrad slot guarded by its reduce-scatter completion event.

tensor: torch.Tensor#

None

ready_event: torch.cuda.Event#

None

key: tuple#

None

index: int#

None

class core.tensor_parallel.gtp_cuda_graphs.GTPCaptureCommState#

GTP work and parameter-readiness dependencies owned by one capture or warmup pass.

params: list#

‘field(…)’

params_to_ensure_ready: list#

‘field(…)’

ag_streams: list#

‘field(…)’

rs_streams: list#

‘field(…)’

wgrad_ring_slots: list#

‘field(…)’

finalized_params: list#

‘field(…)’

_param_ids: set#

‘field(…)’

_param_ids_to_ensure_ready: set#

‘field(…)’

_ag_stream_ids: set#

‘field(…)’

_rs_stream_ids: set#

‘field(…)’

_wgrad_ring_slot_params: dict#

‘field(…)’

_comm_records: list[tuple[object, torch.cuda.Stream, bool]]#

‘field(…)’

register_comm(
param,
stream: torch.cuda.Stream,
*,
reduce_scatter: bool,
) → None#

Record a parameter and side stream owned by the active capture tracker.

register_params_to_ensure_ready(params: Iterable) → None#

Record parameters that must be published before this graph replays.

get_comms_for_chain(chain_id: str) → tuple[list, list, list]#

Return owned parameters, AG streams, and RS streams for one GTP chain.

register_wgrad_ring_slot(
slot: core.tensor_parallel.gtp_cuda_graphs.GraphWgradRingSlot,
param,
) → None#

Track slots used by this graph and reject unsafe intra-graph aliasing.

register_wgrad_finalize(param) → None#

Record one DDP grad-ready occurrence produced by GRAPHED GTP finalization.

core.tensor_parallel.gtp_cuda_graphs._ACTIVE_CAPTURE_COMM_STATE: Optional[core.tensor_parallel.gtp_cuda_graphs.GTPCaptureCommState]#

None

core.tensor_parallel.gtp_cuda_graphs.register_capture_comm(
param,
stream: torch.cuda.Stream,
*,
reduce_scatter: bool,
) → None#

Register communication with the active capture, if one exists.

core.tensor_parallel.gtp_cuda_graphs.register_capture_wgrad_finalize(param) → None#

Record one GRAPHED GTP wgrad-finalization occurrence with the active capture.

core.tensor_parallel.gtp_cuda_graphs.register_capture_params_to_ensure_ready(
params: Iterable,
) → None#

Record GTP parameter reads that need publication before graph replay.

core.tensor_parallel.gtp_cuda_graphs.register_capture_wgrad_ring_slot(
slot: core.tensor_parallel.gtp_cuda_graphs.GraphWgradRingSlot,
param,
) → None#

Register a ring slot with the active capture, if one exists.

core.tensor_parallel.gtp_cuda_graphs.track_gtp_capture_comms()#

Track asynchronous GTP work issued during one capture or warmup pass.

This context tracks ownership, not graph-chain membership. Nested modules can issue work for UNGRAPHED parameters while the context is active, so callers implementing the cross-graph handoff must explicitly select the GRAPHED parameters and their corresponding streams.

core.tensor_parallel.gtp_cuda_graphs._GRAPH_WGRAD_RINGS: dict[tuple, list[core.tensor_parallel.gtp_cuda_graphs.GraphWgradRingSlot]]#

None

core.tensor_parallel.gtp_cuda_graphs.allocate_graph_wgrad_rings(
params: Iterable,
*,
full_iteration: bool,
async_reduction: bool,
ring_size: int,
graphed_chain_id: str,
stream_key: Callable[[str, object], tuple],
) → None#

Allocate bounded persistent inputs for cross-graph asynchronous reduce-scatter.

Slots are shared across layers only within one communication scheduling domain. A two-slot ring retains one graph of overlap without allocating one full unsharded wgrad per layer.

core.tensor_parallel.gtp_cuda_graphs.clear_graph_wgrad_rings() → None#

Drop every ring slot so a rebuilt model reallocates them.

Without this, the stale non-empty dict makes allocate_graph_wgrad_rings a silent no-op on the next build, leaving slots keyed by the old model’s groups and shapes. GPU work must be idle (callers synchronize).

core.tensor_parallel.gtp_cuda_graphs._CG_MEMPOOL_DEVICE#

None

core.tensor_parallel.gtp_cuda_graphs._CG_MEMPOOL#

None

core.tensor_parallel.gtp_cuda_graphs.set_cuda_graph_mempool(device, mempool) → None#

Register the shared memory pool used for graph-owned GTP allocations.

core.tensor_parallel.gtp_cuda_graphs.cuda_graph_pool_allocation(enabled: bool)#

Route allocations in this context into the registered CUDA-graph pool.