Trait burn::tensor::backend::AutodiffBackend
pub trait AutodiffBackend: Backend {
type InnerBackend: Backend<Device = Self::Device, FloatElem = Self::FloatElem, IntElem = Self::IntElem>;
type Gradients: Send;
// Required methods
fn backward<const D: usize>(
tensor: Self::FloatTensorPrimitive<D>,
) -> Self::Gradients;
fn grad<const D: usize>(
tensor: &Self::FloatTensorPrimitive<D>,
grads: &Self::Gradients,
) -> Option<<Self::InnerBackend as Backend>::FloatTensorPrimitive<D>>;
fn grad_remove<const D: usize>(
tensor: &Self::FloatTensorPrimitive<D>,
grads: &mut Self::Gradients,
) -> Option<<Self::InnerBackend as Backend>::FloatTensorPrimitive<D>>;
fn grad_replace<const D: usize>(
tensor: &Self::FloatTensorPrimitive<D>,
grads: &mut Self::Gradients,
grad: <Self::InnerBackend as Backend>::FloatTensorPrimitive<D>,
);
fn inner<const D: usize>(
tensor: Self::FloatTensorPrimitive<D>,
) -> <Self::InnerBackend as Backend>::FloatTensorPrimitive<D>;
fn int_inner<const D: usize>(
tensor: Self::IntTensorPrimitive<D>,
) -> <Self::InnerBackend as Backend>::IntTensorPrimitive<D>;
fn bool_inner<const D: usize>(
tensor: Self::BoolTensorPrimitive<D>,
) -> <Self::InnerBackend as Backend>::BoolTensorPrimitive<D>;
fn q_inner<const D: usize>(
tensor: Self::QuantizedTensorPrimitive<D>,
) -> <Self::InnerBackend as Backend>::QuantizedTensorPrimitive<D>;
fn from_inner<const D: usize>(
tensor: <Self::InnerBackend as Backend>::FloatTensorPrimitive<D>,
) -> Self::FloatTensorPrimitive<D>;
fn int_from_inner<const D: usize>(
tensor: <Self::InnerBackend as Backend>::IntTensorPrimitive<D>,
) -> Self::IntTensorPrimitive<D>;
fn bool_from_inner<const D: usize>(
tensor: <Self::InnerBackend as Backend>::BoolTensorPrimitive<D>,
) -> Self::BoolTensorPrimitive<D>;
fn q_from_inner<const D: usize>(
tensor: <Self::InnerBackend as Backend>::QuantizedTensorPrimitive<D>,
) -> Self::QuantizedTensorPrimitive<D>;
}
Expand description
Trait that allows a backend to support autodiff.
Required Associated Types§
type InnerBackend: Backend<Device = Self::Device, FloatElem = Self::FloatElem, IntElem = Self::IntElem>
type InnerBackend: Backend<Device = Self::Device, FloatElem = Self::FloatElem, IntElem = Self::IntElem>
The inner backend type.
Required Methods§
fn backward<const D: usize>(
tensor: Self::FloatTensorPrimitive<D>,
) -> Self::Gradients
fn backward<const D: usize>( tensor: Self::FloatTensorPrimitive<D>, ) -> Self::Gradients
fn grad<const D: usize>(
tensor: &Self::FloatTensorPrimitive<D>,
grads: &Self::Gradients,
) -> Option<<Self::InnerBackend as Backend>::FloatTensorPrimitive<D>>
fn grad<const D: usize>( tensor: &Self::FloatTensorPrimitive<D>, grads: &Self::Gradients, ) -> Option<<Self::InnerBackend as Backend>::FloatTensorPrimitive<D>>
fn grad_remove<const D: usize>(
tensor: &Self::FloatTensorPrimitive<D>,
grads: &mut Self::Gradients,
) -> Option<<Self::InnerBackend as Backend>::FloatTensorPrimitive<D>>
fn grad_remove<const D: usize>( tensor: &Self::FloatTensorPrimitive<D>, grads: &mut Self::Gradients, ) -> Option<<Self::InnerBackend as Backend>::FloatTensorPrimitive<D>>
fn grad_replace<const D: usize>(
tensor: &Self::FloatTensorPrimitive<D>,
grads: &mut Self::Gradients,
grad: <Self::InnerBackend as Backend>::FloatTensorPrimitive<D>,
)
fn grad_replace<const D: usize>( tensor: &Self::FloatTensorPrimitive<D>, grads: &mut Self::Gradients, grad: <Self::InnerBackend as Backend>::FloatTensorPrimitive<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.
fn inner<const D: usize>(
tensor: Self::FloatTensorPrimitive<D>,
) -> <Self::InnerBackend as Backend>::FloatTensorPrimitive<D>
fn inner<const D: usize>( tensor: Self::FloatTensorPrimitive<D>, ) -> <Self::InnerBackend as Backend>::FloatTensorPrimitive<D>
fn int_inner<const D: usize>(
tensor: Self::IntTensorPrimitive<D>,
) -> <Self::InnerBackend as Backend>::IntTensorPrimitive<D>
fn int_inner<const D: usize>( tensor: Self::IntTensorPrimitive<D>, ) -> <Self::InnerBackend as Backend>::IntTensorPrimitive<D>
fn bool_inner<const D: usize>(
tensor: Self::BoolTensorPrimitive<D>,
) -> <Self::InnerBackend as Backend>::BoolTensorPrimitive<D>
fn bool_inner<const D: usize>( tensor: Self::BoolTensorPrimitive<D>, ) -> <Self::InnerBackend as Backend>::BoolTensorPrimitive<D>
fn q_inner<const D: usize>(
tensor: Self::QuantizedTensorPrimitive<D>,
) -> <Self::InnerBackend as Backend>::QuantizedTensorPrimitive<D>
fn q_inner<const D: usize>( tensor: Self::QuantizedTensorPrimitive<D>, ) -> <Self::InnerBackend as Backend>::QuantizedTensorPrimitive<D>
fn from_inner<const D: usize>(
tensor: <Self::InnerBackend as Backend>::FloatTensorPrimitive<D>,
) -> Self::FloatTensorPrimitive<D>
fn from_inner<const D: usize>( tensor: <Self::InnerBackend as Backend>::FloatTensorPrimitive<D>, ) -> Self::FloatTensorPrimitive<D>
fn int_from_inner<const D: usize>(
tensor: <Self::InnerBackend as Backend>::IntTensorPrimitive<D>,
) -> Self::IntTensorPrimitive<D>
fn int_from_inner<const D: usize>( tensor: <Self::InnerBackend as Backend>::IntTensorPrimitive<D>, ) -> Self::IntTensorPrimitive<D>
fn bool_from_inner<const D: usize>(
tensor: <Self::InnerBackend as Backend>::BoolTensorPrimitive<D>,
) -> Self::BoolTensorPrimitive<D>
fn bool_from_inner<const D: usize>( tensor: <Self::InnerBackend as Backend>::BoolTensorPrimitive<D>, ) -> Self::BoolTensorPrimitive<D>
fn q_from_inner<const D: usize>(
tensor: <Self::InnerBackend as Backend>::QuantizedTensorPrimitive<D>,
) -> Self::QuantizedTensorPrimitive<D>
fn q_from_inner<const D: usize>( tensor: <Self::InnerBackend as Backend>::QuantizedTensorPrimitive<D>, ) -> Self::QuantizedTensorPrimitive<D>
Object Safety§
This trait is not object safe.