torch.AutogradConfig
export interface AutogradConfig<Op extends OpName> {
/**
* The operation name.
*/
readonly op: Op;
/**
* Optional dtype restriction.
* If specified, this autograd only applies to the given dtype.
* Use '*' for wildcard to match any dtype.
* If omitted, applies to all dtypes.
*/
readonly dtype?: AutogradDType;
/**
* Device restriction.
* Use '*' for wildcard to match any device.
* This is useful for composed backwards that use tensor operations
* which auto-dispatch to the correct kernel.
*/
readonly device: AutogradDevice;
/**
* Setup context during forward pass.
* Called after forward computation to save tensors for backward.
*
* @param ctx - The gradient context
* @param inputs - The input tensors
* @param output - The output tensor
* @param meta - Optional metadata from forward pass
*/
setup_context?(
ctx: GradContext<Op>,
inputs: InputsFor<Op>,
output: TensorLike,
meta?: unknown
): void;
/**
* Compute gradients during backward pass.
*
* @param ctx - The gradient context with saved tensors
* @param grad_output - Gradient of the loss with respect to output
* @returns Gradients for each input
*/
backward(ctx: GradContext<Op>, grad_output: TensorLike): GradientsFor<Op>;
}Opextends OpName- readonly
op(Op) - – The operation name.
- readonly
dtype(AutogradDType)optional - – Optional dtype restriction. If specified, this autograd only applies to the given dtype. Use '*' for wildcard to match any dtype. If omitted, applies to all dtypes.
- readonly
device(AutogradDevice) - – Device restriction. Use '*' for wildcard to match any device. This is useful for composed backwards that use tensor operations which auto-dispatch to the correct kernel.
setup_context((ctx: GradContext<Op>, inputs: InputsFor<Op>, output: TensorLike, meta?: unknown) => void)optional- – Setup context during forward pass. Called after forward computation to save tensors for backward.
backward((ctx: GradContext<Op>, grad_output: TensorLike) => GradientsFor<Op>)- – Compute gradients during backward pass.
Autograd configuration for an operation.