pub struct LayerNorm { /* private fields */ }Expand description
Trainable FP32 LayerNorm over the final input dimension.
Implementations§
Source§impl LayerNorm
impl LayerNorm
pub fn new(normalized_shape: usize, epsilon: f32) -> Result<Self>
Sourcepub fn new_on(
runtime: &Runtime,
normalized_shape: usize,
epsilon: f32,
) -> Result<Self>
pub fn new_on( runtime: &Runtime, normalized_shape: usize, epsilon: f32, ) -> Result<Self>
Construct a LayerNorm with unit weight and zero bias.
§Errors
Returns an error when normalized_shape is zero, epsilon is not finite
and positive, or parameter allocation/upload fails.
Sourcepub fn new_from_matrices(
weight: Matrix,
bias: Matrix,
epsilon: f32,
) -> Result<Self>
pub fn new_from_matrices( weight: Matrix, bias: Matrix, epsilon: f32, ) -> Result<Self>
Construct a LayerNorm from exact weight and bias matrices.
§Errors
Returns an error unless weight and bias are equal, nonempty, same-runtime
FP32 vectors and epsilon is finite and positive.
Sourcepub fn forward(&self, input: &Matrix) -> Result<Matrix>
pub fn forward(&self, input: &Matrix) -> Result<Matrix>
Normalize each row over the final dimension and apply affine parameters.
§Errors
Returns an error when the input is empty, is not FP32, its final dimension differs from the normalized shape, it belongs to another runtime, or runtime recording fails.
Sourcepub fn forward_channel(&self, input: &Matrix) -> Result<Matrix>
pub fn forward_channel(&self, input: &Matrix) -> Result<Matrix>
Normalize channels directly in [B, C, T] storage.
This uses the same affine parameters as ordinary LayerNorm without the
transpose pair otherwise needed to place C last.
§Errors
Returns an error unless the input satisfies the channel-normalization contract or runtime recording fails.
Sourcepub fn forward_channel_relu(&self, input: &Matrix) -> Result<Matrix>
pub fn forward_channel_relu(&self, input: &Matrix) -> Result<Matrix>
Normalize channels in [B, C, T] storage and fuse ReLU.
§Errors
Returns an error unless the input satisfies the channel-normalization contract or runtime recording fails.
Sourcepub const fn normalized_shape(&self) -> usize
pub const fn normalized_shape(&self) -> usize
Return the normalized final-dimension width.
Sourcepub fn parameters(&self) -> [Parameter; 2]
pub fn parameters(&self) -> [Parameter; 2]
Return the parameters in deterministic weight, bias order.
Trait Implementations§
Source§impl Module for LayerNorm
impl Module for LayerNorm
Source§fn forward(&self, input: &Matrix) -> Result<Matrix>
fn forward(&self, input: &Matrix) -> Result<Matrix>
Source§fn registry(&self) -> &ModuleRegistry
fn registry(&self) -> &ModuleRegistry
Source§fn parameters(&self) -> Vec<Parameter>
fn parameters(&self) -> Vec<Parameter>
Source§fn named_parameters(&self) -> Vec<NamedParameter>
fn named_parameters(&self) -> Vec<NamedParameter>
Source§fn named_buffers(&self) -> Vec<NamedBuffer>
fn named_buffers(&self) -> Vec<NamedBuffer>
Source§fn all_parameters(&self) -> Result<Vec<Parameter>>
fn all_parameters(&self) -> Result<Vec<Parameter>>
Source§fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>
fn all_named_parameters(&self) -> Result<Vec<NamedParameter>>
Source§fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>
fn all_named_buffers(&self) -> Result<Vec<NamedBuffer>>
Source§fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>
fn all_named_state_u32(&self) -> Result<Vec<NamedStateU32>>
u32 scalar state in
deterministic depth-first order. Read more