Trait burn_tensor::backend::ADBackend
source · pub trait ADBackend: Backend {
type InnerBackend: Backend<Device = Self::Device, FloatElem = Self::FloatElem>;
type Gradients: Send + Sync;
// Required methods
fn backward<const D: usize>(
tensor: Self::TensorPrimitive<D>
) -> Self::Gradients;
fn grad<const D: usize>(
tensor: &Self::TensorPrimitive<D>,
grads: &Self::Gradients
) -> Option<<<Self as ADBackend>::InnerBackend as Backend>::TensorPrimitive<D>>;
fn grad_remove<const D: usize>(
tensor: &Self::TensorPrimitive<D>,
grads: &mut Self::Gradients
) -> Option<<<Self as ADBackend>::InnerBackend as Backend>::TensorPrimitive<D>>;
fn grad_replace<const D: usize>(
tensor: &Self::TensorPrimitive<D>,
grads: &mut Self::Gradients,
grad: <<Self as ADBackend>::InnerBackend as Backend>::TensorPrimitive<D>
);
fn inner<const D: usize>(
tensor: Self::TensorPrimitive<D>
) -> <Self::InnerBackend as Backend>::TensorPrimitive<D>;
fn from_inner<const D: usize>(
tensor: <Self::InnerBackend as Backend>::TensorPrimitive<D>
) -> Self::TensorPrimitive<D>;
}Expand description
Trait that allows a backend to support autodiff.
Required Associated Types§
sourcetype InnerBackend: Backend<Device = Self::Device, FloatElem = Self::FloatElem>
type InnerBackend: Backend<Device = Self::Device, FloatElem = Self::FloatElem>
The inner backend type.
Required Methods§
sourcefn backward<const D: usize>(tensor: Self::TensorPrimitive<D>) -> Self::Gradients
fn backward<const D: usize>(tensor: Self::TensorPrimitive<D>) -> Self::Gradients
sourcefn grad<const D: usize>(
tensor: &Self::TensorPrimitive<D>,
grads: &Self::Gradients
) -> Option<<<Self as ADBackend>::InnerBackend as Backend>::TensorPrimitive<D>>
fn grad<const D: usize>( tensor: &Self::TensorPrimitive<D>, grads: &Self::Gradients ) -> Option<<<Self as ADBackend>::InnerBackend as Backend>::TensorPrimitive<D>>
sourcefn grad_remove<const D: usize>(
tensor: &Self::TensorPrimitive<D>,
grads: &mut Self::Gradients
) -> Option<<<Self as ADBackend>::InnerBackend as Backend>::TensorPrimitive<D>>
fn grad_remove<const D: usize>( tensor: &Self::TensorPrimitive<D>, grads: &mut Self::Gradients ) -> Option<<<Self as ADBackend>::InnerBackend as Backend>::TensorPrimitive<D>>
sourcefn grad_replace<const D: usize>(
tensor: &Self::TensorPrimitive<D>,
grads: &mut Self::Gradients,
grad: <<Self as ADBackend>::InnerBackend as Backend>::TensorPrimitive<D>
)
fn grad_replace<const D: usize>( tensor: &Self::TensorPrimitive<D>, grads: &mut Self::Gradients, grad: <<Self as ADBackend>::InnerBackend as Backend>::TensorPrimitive<D> )
Replace the gradients of a tensor with the one provided.
If no gradient existed for the provided tensor, register it.
Arguments
tensor- The tensor to pop the gradients from.grads- The gradients.grad- The updated grad tensor.