pub trait BackpropModule<X>: TracedModule<X> {
type SelfGrads;
// Required methods
fn backprop(
&self,
trace: &<Self as TracedModule<X>>::Trace,
grads_wrt_output: <Self as Module<X>>::Output,
) -> (X, Self::SelfGrads);
fn update(
&mut self,
applyer: &mut impl GradApplyer,
updates: Self::SelfGrads,
) -> Result<(), Error>;
// Provided methods
fn new_momentum(
&self,
params: TrainParams,
momentum_coefficient: f32,
) -> Momentum<Self::SelfGrads>
where <Self as BackpropModule<X>>::SelfGrads: Gradients { ... }
fn new_rmsprop(
&self,
params: TrainParams,
beta: f32,
) -> RMSProp<Self::SelfGrads>
where <Self as BackpropModule<X>>::SelfGrads: Gradients,
<Self::SelfGrads as Gradients>::Concrete: Float { ... }
fn new_rmsprop_with_momentum(
&self,
params: TrainParams,
momentum_coefficient: f32,
beta: f32,
) -> RMSProp<Self::SelfGrads>
where <Self as BackpropModule<X>>::SelfGrads: Gradients,
<Self::SelfGrads as Gradients>::Concrete: Float { ... }
}Expand description
Some sequential computation which can perform backprop on itself given trace state and the gradients of its outputs: computing parameter updates for itself.
Trainable layers implement this trait.
Relies on behavior from the TracedModule trait.
Required Associated Types§
Required Methods§
Sourcefn backprop(
&self,
trace: &<Self as TracedModule<X>>::Trace,
grads_wrt_output: <Self as Module<X>>::Output,
) -> (X, Self::SelfGrads)
fn backprop( &self, trace: &<Self as TracedModule<X>>::Trace, grads_wrt_output: <Self as Module<X>>::Output, ) -> (X, Self::SelfGrads)
Computes gradients for this layer/module, given tracing state from forward execution, and the gradients of the output.
Returns the gradients with respect to the input to the layer/module, as well as
gradients with respect to parameters (needed to call update()).
Sourcefn update(
&mut self,
applyer: &mut impl GradApplyer,
updates: Self::SelfGrads,
) -> Result<(), Error>
fn update( &mut self, applyer: &mut impl GradApplyer, updates: Self::SelfGrads, ) -> Result<(), Error>
Applies a gradient update step, given (Self::SelfGrads) and a GradApplyer.
While updates describes the change in parameters, applyer is used to change the parameters
of this layer, which may include applying any kind of clipping or regularization.
Provided Methods§
Sourcefn new_momentum(
&self,
params: TrainParams,
momentum_coefficient: f32,
) -> Momentum<Self::SelfGrads>
fn new_momentum( &self, params: TrainParams, momentum_coefficient: f32, ) -> Momentum<Self::SelfGrads>
Returns a GradApplyer object needed to train using SGD + momentum.
Sourcefn new_rmsprop(
&self,
params: TrainParams,
beta: f32,
) -> RMSProp<Self::SelfGrads>
fn new_rmsprop( &self, params: TrainParams, beta: f32, ) -> RMSProp<Self::SelfGrads>
Returns a GradApplyer object needed to train using rmsprop.
Sourcefn new_rmsprop_with_momentum(
&self,
params: TrainParams,
momentum_coefficient: f32,
beta: f32,
) -> RMSProp<Self::SelfGrads>
fn new_rmsprop_with_momentum( &self, params: TrainParams, momentum_coefficient: f32, beta: f32, ) -> RMSProp<Self::SelfGrads>
Returns a GradApplyer object needed to train using rmsprop + momentum.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".