Trait AutodiffBackend
pub trait AutodiffBackend: Backend {
type InnerBackend: Backend<Device = Self::Device>;
type Gradients: Send;
Show 15 methods
// Required methods
fn backward(tensor: Self::FloatTensorPrimitive) -> Self::Gradients;
fn grad(
tensor: &Self::FloatTensorPrimitive,
grads: &Self::Gradients,
) -> Option<<Self::InnerBackend as BackendTypes>::FloatTensorPrimitive>;
fn grad_remove(
tensor: &Self::FloatTensorPrimitive,
grads: &mut Self::Gradients,
) -> Option<<Self::InnerBackend as BackendTypes>::FloatTensorPrimitive>;
fn grad_replace(
tensor: &Self::FloatTensorPrimitive,
grads: &mut Self::Gradients,
grad: <Self::InnerBackend as BackendTypes>::FloatTensorPrimitive,
);
fn inner(
tensor: Self::FloatTensorPrimitive,
) -> <Self::InnerBackend as BackendTypes>::FloatTensorPrimitive;
fn int_inner(
tensor: Self::IntTensorPrimitive,
) -> <Self::InnerBackend as BackendTypes>::IntTensorPrimitive;
fn bool_inner(
tensor: Self::BoolTensorPrimitive,
) -> <Self::InnerBackend as BackendTypes>::BoolTensorPrimitive;
fn q_inner(
tensor: Self::QuantizedTensorPrimitive,
) -> <Self::InnerBackend as BackendTypes>::QuantizedTensorPrimitive;
fn from_inner(
tensor: <Self::InnerBackend as BackendTypes>::FloatTensorPrimitive,
) -> Self::FloatTensorPrimitive;
fn int_from_inner(
tensor: <Self::InnerBackend as BackendTypes>::IntTensorPrimitive,
) -> Self::IntTensorPrimitive;
fn bool_from_inner(
tensor: <Self::InnerBackend as BackendTypes>::BoolTensorPrimitive,
) -> Self::BoolTensorPrimitive;
fn q_from_inner(
tensor: <Self::InnerBackend as BackendTypes>::QuantizedTensorPrimitive,
) -> Self::QuantizedTensorPrimitive;
// Provided methods
fn set_distributed_params(
tensor: Self::FloatTensorPrimitive,
_param_id: ParamId,
) -> Self::FloatTensorPrimitive { ... }
fn distributed_params(
_tensor: &Self::FloatTensorPrimitive,
) -> Option<DistributedParams> { ... }
fn is_distributed(_tensor: &Self::FloatTensorPrimitive) -> bool { ... }
}Expand description
Trait that allows a backend to support autodiff.
Required Associated Types§
type InnerBackend: Backend<Device = Self::Device>
type InnerBackend: Backend<Device = Self::Device>
The inner backend type.
Required Methods§
fn backward(tensor: Self::FloatTensorPrimitive) -> Self::Gradients
fn backward(tensor: Self::FloatTensorPrimitive) -> Self::Gradients
fn grad(
tensor: &Self::FloatTensorPrimitive,
grads: &Self::Gradients,
) -> Option<<Self::InnerBackend as BackendTypes>::FloatTensorPrimitive>
fn grad( tensor: &Self::FloatTensorPrimitive, grads: &Self::Gradients, ) -> Option<<Self::InnerBackend as BackendTypes>::FloatTensorPrimitive>
fn grad_remove(
tensor: &Self::FloatTensorPrimitive,
grads: &mut Self::Gradients,
) -> Option<<Self::InnerBackend as BackendTypes>::FloatTensorPrimitive>
fn grad_remove( tensor: &Self::FloatTensorPrimitive, grads: &mut Self::Gradients, ) -> Option<<Self::InnerBackend as BackendTypes>::FloatTensorPrimitive>
fn grad_replace(
tensor: &Self::FloatTensorPrimitive,
grads: &mut Self::Gradients,
grad: <Self::InnerBackend as BackendTypes>::FloatTensorPrimitive,
)
fn grad_replace( tensor: &Self::FloatTensorPrimitive, grads: &mut Self::Gradients, grad: <Self::InnerBackend as BackendTypes>::FloatTensorPrimitive, )
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(
tensor: Self::FloatTensorPrimitive,
) -> <Self::InnerBackend as BackendTypes>::FloatTensorPrimitive
fn inner( tensor: Self::FloatTensorPrimitive, ) -> <Self::InnerBackend as BackendTypes>::FloatTensorPrimitive
fn int_inner(
tensor: Self::IntTensorPrimitive,
) -> <Self::InnerBackend as BackendTypes>::IntTensorPrimitive
fn int_inner( tensor: Self::IntTensorPrimitive, ) -> <Self::InnerBackend as BackendTypes>::IntTensorPrimitive
fn bool_inner(
tensor: Self::BoolTensorPrimitive,
) -> <Self::InnerBackend as BackendTypes>::BoolTensorPrimitive
fn bool_inner( tensor: Self::BoolTensorPrimitive, ) -> <Self::InnerBackend as BackendTypes>::BoolTensorPrimitive
fn q_inner(
tensor: Self::QuantizedTensorPrimitive,
) -> <Self::InnerBackend as BackendTypes>::QuantizedTensorPrimitive
fn q_inner( tensor: Self::QuantizedTensorPrimitive, ) -> <Self::InnerBackend as BackendTypes>::QuantizedTensorPrimitive
fn from_inner(
tensor: <Self::InnerBackend as BackendTypes>::FloatTensorPrimitive,
) -> Self::FloatTensorPrimitive
fn from_inner( tensor: <Self::InnerBackend as BackendTypes>::FloatTensorPrimitive, ) -> Self::FloatTensorPrimitive
fn int_from_inner(
tensor: <Self::InnerBackend as BackendTypes>::IntTensorPrimitive,
) -> Self::IntTensorPrimitive
fn int_from_inner( tensor: <Self::InnerBackend as BackendTypes>::IntTensorPrimitive, ) -> Self::IntTensorPrimitive
fn bool_from_inner(
tensor: <Self::InnerBackend as BackendTypes>::BoolTensorPrimitive,
) -> Self::BoolTensorPrimitive
fn bool_from_inner( tensor: <Self::InnerBackend as BackendTypes>::BoolTensorPrimitive, ) -> Self::BoolTensorPrimitive
fn q_from_inner(
tensor: <Self::InnerBackend as BackendTypes>::QuantizedTensorPrimitive,
) -> Self::QuantizedTensorPrimitive
fn q_from_inner( tensor: <Self::InnerBackend as BackendTypes>::QuantizedTensorPrimitive, ) -> Self::QuantizedTensorPrimitive
Provided Methods§
fn set_distributed_params(
tensor: Self::FloatTensorPrimitive,
_param_id: ParamId,
) -> Self::FloatTensorPrimitive
fn set_distributed_params( tensor: Self::FloatTensorPrimitive, _param_id: ParamId, ) -> Self::FloatTensorPrimitive
Mark the tensor as distributed across multiple devices. The gradients will be aggregated during the backward pass.
This function does nothing when distributed training is not available.
fn distributed_params(
_tensor: &Self::FloatTensorPrimitive,
) -> Option<DistributedParams>
fn distributed_params( _tensor: &Self::FloatTensorPrimitive, ) -> Option<DistributedParams>
Returns the distributed parameters if the tensor was marked as distributed.
fn is_distributed(_tensor: &Self::FloatTensorPrimitive) -> bool
fn is_distributed(_tensor: &Self::FloatTensorPrimitive) -> bool
Returns true if the tensor was marked as distributed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
§impl AutodiffBackend for Dispatch
Available on crate feature autodiff only.
impl AutodiffBackend for Dispatch
Available on crate feature
autodiff only.