Struct dfdx::nn::LayerNorm1D
source · [−]pub struct LayerNorm1D<const M: usize> {
pub gamma: Tensor1D<M>,
pub beta: Tensor1D<M>,
pub epsilon: f32,
}
Expand description
Implements layer normalization as described in Layer Normalization.
This calls normalize() on the last axis of the input to normalize to 0 mean and unit std dev, and then does an element-wise affine transform using learnable parameters Self::gamma and Self::beta.
Self::epsilon is passed to normalize() and added to the variance to ensure big enough numbers. It defaults to 1e-5
.
Generics
M
The size of the affine transform tensors.
Examples
let model: LayerNorm1D<5> = Default::default();
let x: Tensor1D<5> = Default::default();
let _: Tensor1D<5> = model.forward(x);
Fields
gamma: Tensor1D<M>
beta: Tensor1D<M>
epsilon: f32
Trait Implementations
sourceimpl<const M: usize> CanUpdateWithGradients for LayerNorm1D<M>
impl<const M: usize> CanUpdateWithGradients for LayerNorm1D<M>
sourcefn update<G: GradientProvider>(
&mut self,
grads: &mut G,
unused: &mut UnusedTensors
)
fn update<G: GradientProvider>(
&mut self,
grads: &mut G,
unused: &mut UnusedTensors
)
Updates Self::gamma and Self::beta.
sourceimpl<const M: usize> Clone for LayerNorm1D<M>
impl<const M: usize> Clone for LayerNorm1D<M>
sourcefn clone(&self) -> LayerNorm1D<M>
fn clone(&self) -> LayerNorm1D<M>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl<const M: usize> Debug for LayerNorm1D<M>
impl<const M: usize> Debug for LayerNorm1D<M>
sourceimpl<const M: usize> Default for LayerNorm1D<M>
impl<const M: usize> Default for LayerNorm1D<M>
sourcefn default() -> Self
fn default() -> Self
Fills Self::gamma with 1s and Self::beta with 0s and sets Self::epsilon to 1e-5
.
sourceimpl<const M: usize> LoadFromNpz for LayerNorm1D<M>
impl<const M: usize> LoadFromNpz for LayerNorm1D<M>
sourceimpl<H: Tape, const M: usize> Module<Tensor1D<M, H>> for LayerNorm1D<M>
impl<H: Tape, const M: usize> Module<Tensor1D<M, H>> for LayerNorm1D<M>
sourcefn forward(&self, x: Tensor1D<M, H>) -> Self::Output
fn forward(&self, x: Tensor1D<M, H>) -> Self::Output
Calls:
- normalize() with Self::epsilon
- mul() with Self::gamma
- add() with Self::beta
sourceimpl<H: Tape, const B: usize, const M: usize> Module<Tensor2D<B, M, H>> for LayerNorm1D<M>
impl<H: Tape, const B: usize, const M: usize> Module<Tensor2D<B, M, H>> for LayerNorm1D<M>
sourcefn forward(&self, x: Tensor2D<B, M, H>) -> Self::Output
fn forward(&self, x: Tensor2D<B, M, H>) -> Self::Output
Calls:
- normalize() with Self::epsilon.
- mul() with Self::gamma
- add() with Self::beta
sourceimpl<H: Tape, const B: usize, const S: usize, const M: usize> Module<Tensor3D<B, S, M, H>> for LayerNorm1D<M>
impl<H: Tape, const B: usize, const S: usize, const M: usize> Module<Tensor3D<B, S, M, H>> for LayerNorm1D<M>
sourcefn forward(&self, x: Tensor3D<B, S, M, H>) -> Self::Output
fn forward(&self, x: Tensor3D<B, S, M, H>) -> Self::Output
Calls:
- normalize() with Self::epsilon.
- add() with Self::gamma
- add() with Self::beta
sourceimpl<T, const M: usize> ModuleMut<T> for LayerNorm1D<M>where
Self: Module<T>,
impl<T, const M: usize> ModuleMut<T> for LayerNorm1D<M>where
Self: Module<T>,
type Output = <LayerNorm1D<M> as Module<T>>::Output
type Output = <LayerNorm1D<M> as Module<T>>::Output
The type that this unit produces given
Input
.sourcefn forward_mut(&mut self, input: T) -> Self::Output
fn forward_mut(&mut self, input: T) -> Self::Output
sourceimpl<const M: usize> ResetParams for LayerNorm1D<M>
impl<const M: usize> ResetParams for LayerNorm1D<M>
sourcefn reset_params<R: Rng>(&mut self, _: &mut R)
fn reset_params<R: Rng>(&mut self, _: &mut R)
Fills Self::gamma with 1s and Self::beta with 0s.
Auto Trait Implementations
impl<const M: usize> RefUnwindSafe for LayerNorm1D<M>
impl<const M: usize> Send for LayerNorm1D<M>
impl<const M: usize> Sync for LayerNorm1D<M>
impl<const M: usize> Unpin for LayerNorm1D<M>
impl<const M: usize> UnwindSafe for LayerNorm1D<M>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more