Struct dfdx::nn::modules::LayerNorm1D

source ·
pub struct LayerNorm1D<const M: usize, E: Dtype, D: DeviceStorage> {
    pub gamma: Tensor<Rank1<M>, E, D>,
    pub beta: Tensor<Rank1<M>, E, D>,
    pub epsilon: E,
}
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

type Model = LayerNorm1D<5>;
let model = dev.build_module::<Model, f32>();
let _: Tensor<Rank1<5>, f32, _> = model.forward(dev.zeros::<Rank1<5>>());

Fields§

§gamma: Tensor<Rank1<M>, E, D>§beta: Tensor<Rank1<M>, E, D>§epsilon: E

Trait Implementations§

source§

impl<const M: usize, E: Clone + Dtype, D: Clone + DeviceStorage> Clone for LayerNorm1D<M, E, D>

source§

fn clone(&self) -> LayerNorm1D<M, E, D>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const M: usize, E: Debug + Dtype, D: Debug + DeviceStorage> Debug for LayerNorm1D<M, E, D>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<B: Dim, const M: usize, E: Dtype, D: Device<E>, T: Tape<E, D>> Module<Tensor<(B, Const<M>), E, D, T>> for LayerNorm1D<M, E, D>

§

type Output = Tensor<(B, Const<M>), E, D, T>

The type that this unit produces given Input.
§

type Error = <D as HasErr>::Err

source§

fn try_forward( &self, x: Tensor<(B, Const<M>), E, D, T> ) -> Result<Self::Output, D::Err>

source§

fn forward(&self, input: Input) -> Self::Output

Forward Input through the module and produce Module::Output. Read more
source§

impl<B: Dim, S: Dim, const M: usize, E: Dtype, D: Device<E>, T: Tape<E, D>> Module<Tensor<(B, S, Const<M>), E, D, T>> for LayerNorm1D<M, E, D>

§

type Output = Tensor<(B, S, Const<M>), E, D, T>

The type that this unit produces given Input.
§

type Error = <D as HasErr>::Err

source§

fn try_forward( &self, x: Tensor<(B, S, Const<M>), E, D, T> ) -> Result<Self::Output, D::Err>

source§

fn forward(&self, input: Input) -> Self::Output

Forward Input through the module and produce Module::Output. Read more
source§

impl<const M: usize, E: Dtype, D: Device<E>, T: Tape<E, D>> Module<Tensor<(Const<M>,), E, D, T>> for LayerNorm1D<M, E, D>

§

type Output = Tensor<(Const<M>,), E, D, T>

The type that this unit produces given Input.
§

type Error = <D as HasErr>::Err

source§

fn try_forward( &self, x: Tensor<Rank1<M>, E, D, T> ) -> Result<Self::Output, D::Err>

source§

fn forward(&self, input: Input) -> Self::Output

Forward Input through the module and produce Module::Output. Read more
source§

impl<const M: usize, E: Dtype, D: Device<E>> TensorCollection<E, D> for LayerNorm1D<M, E, D>

§

type To<E2: Dtype, D2: Device<E2>> = LayerNorm1D<M, E2, D2>

Type alias that specifies the how a module’s type changes when using a different dtype and/or device.
source§

fn iter_tensors<V: ModuleVisitor<Self, E, D>>( visitor: &mut V ) -> Result<Option<Self::To<V::E2, V::D2>>, V::Err>

Specifies how to iterate through tensors or modules containted within this module, and how to contruct this module given values for its fields. Returns Err(_) to indicate an error, Ok(None) to indicate that there is no error and a module has not been built, and Ok(Some(_)) contains Self::Output<E2, D2>
source§

fn module<F1, F2, Field>( name: &str, get_ref: F1, get_mut: F2 ) -> ModuleField<'_, F1, F2, Self, Field>where F1: FnMut(&Self) -> &Field, F2: FnMut(&mut Self) -> &mut Field, Field: TensorCollection<E, D>,

Creates a ModuleFields that represents a field that may contain one or more tensors. Read more
source§

fn tensor<F1, F2, S>( name: &str, get_ref: F1, get_mut: F2, options: TensorOptions<S, E, D> ) -> TensorField<'_, F1, F2, Self, S, E, D>where F1: FnMut(&Self) -> &Tensor<S, E, D>, F2: FnMut(&mut Self) -> &mut Tensor<S, E, D>, S: Shape,

Creates a ModuleFields that represents a tensor field. Read more
source§

impl<const M: usize, E: Dtype, D: DeviceStorage> NonMutableModule for LayerNorm1D<M, E, D>

Auto Trait Implementations§

§

impl<const M: usize, E, D> RefUnwindSafe for LayerNorm1D<M, E, D>where D: RefUnwindSafe, E: RefUnwindSafe, <D as DeviceStorage>::Vec<E>: RefUnwindSafe,

§

impl<const M: usize, E, D> Send for LayerNorm1D<M, E, D>where D: Send,

§

impl<const M: usize, E, D> Sync for LayerNorm1D<M, E, D>where D: Sync,

§

impl<const M: usize, E, D> Unpin for LayerNorm1D<M, E, D>where D: Unpin,

§

impl<const M: usize, E, D> UnwindSafe for LayerNorm1D<M, E, D>where D: UnwindSafe, E: UnwindSafe, <D as DeviceStorage>::Vec<E>: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V