Skip to main content

GradientTransformation

Trait GradientTransformation 

Source
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§

Source

type State<B: Backend, T: Float>: Tree<B> + Clone

The state, for leaves of type T on backend B.

Required Methods§

Source

fn init<B: Backend, T: Float>( &self, params: &[Array<B, T>], ) -> Self::State<B, T>

The initial state for parameters with the leaves params.

Source

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>)

Transforms the updates (one per leaf of the parameters) and returns the new state.

Provided Methods§

Source

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.

Source

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".

Implementors§