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)
A captured full-forward, backward, and optimizer update.
Parameters
modulenn.Module- required. Module whose forward execution participates in the captured update.
optimizertorch.optim.Optimizer- required. Optimizer attached to the selected parameters.
static_inputstorch.Tensor- required.
static_targetstorch.Tensor- required.
graphtorch.cuda.CUDAGraph- required.
static_losstorch.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'
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
modulenn.Module- required. Module whose forward execution participates in the captured update.
optimizertorch.optim.Optimizer- required. Optimizer attached to the selected parameters.
example_inputstorch.Tensor- required. CUDA tensor establishing the input shape, dtype, and static buffer for capture.
example_targetstorch.Tensor- required. CUDA tensor establishing the target shape, dtype, and static buffer for capture.
loss_functionTensorLoss- required. Callable receiving predictions and targets and returning a differentiable scalar loss.
warmup_stepsint- keyword-only, default=3. Warmup updates executed and restored during capture.
gradient_transformGradientTransform | None- keyword-only, default=None. Optional zero-argument gradient transform after backward.
Returns
stepCudaGraphAdaptationStep- 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
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
inputstorch.Tensor- required. New input values with exactly the captured shape, dtype, and CUDA device.
targetstorch.Tensor- required. New target values with exactly the captured shape, dtype, and CUDA device.
synchronizebool- keyword-only, default=False. Wait for CUDA completion before returning.
Returns
losstorch.Tensor- Detached cloned scalar loss from the replayed optimizer update.