API reference

CUDA Graph adaptation

Signatures, parameters, return contracts, and source for cuda graph adaptation.

Overview

CudaGraphAdaptationStep captures one fixed-shape forward, loss, backward, optional gradient transform, and optimizer update. It restores module and optimizer state after warmup and capture. Replay copies source tensors into retained static buffers. CUDA inputs and optimizer parameters are required; shape, dtype, parameter groups, and allocations must remain compatible.

Source revision: caef7be03abd. Public export index.

CudaGraphAdaptationStep

axosim.adaptation.CudaGraphAdaptationStep(module: nn.Module, optimizer: torch.optim.Optimizer, static_inputs: torch.Tensor, static_targets: torch.Tensor, graph: torch.cuda.CUDAGraph, static_loss: torch.Tensor)

Source

A captured full-forward, backward, and optimizer update.

Parameters

module nn.Module
required. Module whose forward execution participates in the captured update.
optimizer torch.optim.Optimizer
required. Optimizer attached to the selected parameters.
static_inputs torch.Tensor
required.
static_targets torch.Tensor
required.
graph torch.cuda.CUDAGraph
required.
static_loss torch.Tensor
required.

Attributes

Constructor fields are retained as attributes.

Methods

CudaGraphAdaptationStep.capture

@classmethod
axosim.adaptation.CudaGraphAdaptationStep.capture(module: nn.Module, optimizer: torch.optim.Optimizer, example_inputs: torch.Tensor, example_targets: torch.Tensor, loss_function: TensorLoss, *, warmup_steps: int=3, gradient_transform: GradientTransform | None=None) -> 'CudaGraphAdaptationStep'

Source

Capture a fixed-shape adaptation update without consuming it.

module and optimizer parameters must be CUDA-resident; example_inputs and example_targets establish fixed shape/dtype. loss_function(prediction,targets) must return a scalar differentiable tensor. gradient_transform is a zero-argument callable executed after backward. Returns a captured step while restoring pre-capture module/optimizer values.

Parameters

module nn.Module
required. Module whose forward execution participates in the captured update.
optimizer torch.optim.Optimizer
required. Optimizer attached to the selected parameters.
example_inputs torch.Tensor
required. CUDA tensor establishing the input shape, dtype, and static buffer for capture.
example_targets torch.Tensor
required. CUDA tensor establishing the target shape, dtype, and static buffer for capture.
loss_function TensorLoss
required. Callable receiving predictions and targets and returning a differentiable scalar loss.
warmup_steps int
keyword-only, default=3. Warmup updates executed and restored during capture.
gradient_transform GradientTransform | None
keyword-only, default=None. Optional zero-argument gradient transform after backward.

Returns

step CudaGraphAdaptationStep
Captured update with retained static buffers; warmup/capture changes to stored module and optimizer values have been restored.

CudaGraphAdaptationStep.call

axosim.adaptation.CudaGraphAdaptationStep.__call__(inputs: torch.Tensor, targets: torch.Tensor, *, synchronize: bool=False) -> torch.Tensor

Source

Replay the captured adaptation update with new input and target values.

inputs and targets must match captured shapes and dtypes. Copies values to retained static CUDA buffers, replays the complete update, and returns a detached cloned scalar loss. synchronize=True waits for CUDA completion.

Parameters

inputs torch.Tensor
required. New input values with exactly the captured shape, dtype, and CUDA device.
targets torch.Tensor
required. New target values with exactly the captured shape, dtype, and CUDA device.
synchronize bool
keyword-only, default=False. Wait for CUDA completion before returning.

Returns

loss torch.Tensor
Detached cloned scalar loss from the replayed optimizer update.

Search guides, examples, and API signatures.