pub trait GradientTransformation {
type State<B: Backend, T: Float>: Tree<B> + Clone;
// Required methods
fn init<B: Backend, T: Float>(
&self,
params: &[Array<B, T>],
) -> Self::State<B, T>;
fn update<B: Backend, T: Float>(
&self,
updates: Vec<Array<B, T>>,
state: Self::State<B, T>,
) -> (Vec<Array<B, T>>, Self::State<B, T>);
// Provided methods
fn init_tree<B: Backend, T: Float, P: Tree<B>>(
&self,
params: &P,
) -> Self::State<B, T> { ... }
fn update_tree<B: Backend, T: Float, P: Tree<B>>(
&self,
grads: &P,
state: Self::State<B, T>,
) -> (P, Self::State<B, T>) { ... }
}Expand description
A transformation of updates (optax.GradientTransformation), applied
to the leaves of the parameters, all of type T.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn init_tree<B: Backend, T: Float, P: Tree<B>>(
&self,
params: &P,
) -> Self::State<B, T>
fn init_tree<B: Backend, T: Float, P: Tree<B>>( &self, params: &P, ) -> Self::State<B, T>
The initial state for the parameters params (any pytree whose
leaves are of type T).
§Panics
Panics if a leaf has another type.
Sourcefn update_tree<B: Backend, T: Float, P: Tree<B>>(
&self,
grads: &P,
state: Self::State<B, T>,
) -> (P, Self::State<B, T>)
fn update_tree<B: Backend, T: Float, P: Tree<B>>( &self, grads: &P, state: Self::State<B, T>, ) -> (P, Self::State<B, T>)
Transforms the gradient grads (a pytree like the parameters) and
returns the updates, to add to the parameters with
apply_updates, and the new state.
§Panics
Panics if a leaf has another type.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".