pub struct RmsNorm {
pub normalized_shape: Vec<usize>,
pub eps: f64,
pub gamma: ArrayD<f64>,
}Expand description
Root Mean Square Layer Normalization (no mean centering).
Normalizes by: x / sqrt(mean(x^2) + eps) * gamma
Used in LLaMA and other modern transformer architectures.
Fields§
§normalized_shape: Vec<usize>Shape of the dimensions to normalize over (typically the last N dims).
eps: f64Small constant for numerical stability.
gamma: ArrayD<f64>Learnable scale parameter.
Implementations§
Source§impl RmsNorm
impl RmsNorm
Sourcepub fn new(
normalized_shape: Vec<usize>,
eps: f64,
) -> Result<Self, NormalizationError>
pub fn new( normalized_shape: Vec<usize>, eps: f64, ) -> Result<Self, NormalizationError>
Create a new RmsNorm layer.
normalized_shape specifies the trailing dimensions to normalize over.
gamma is initialized to ones.
Sourcepub fn forward(
&self,
input: &ArrayD<f64>,
) -> Result<ArrayD<f64>, NormalizationError>
pub fn forward( &self, input: &ArrayD<f64>, ) -> Result<ArrayD<f64>, NormalizationError>
Forward pass: normalize the input tensor.
The last normalized_shape.len() dimensions of the input must match
normalized_shape.
Sourcepub fn rms(input: &ArrayD<f64>, axes: &[usize]) -> ArrayD<f64>
pub fn rms(input: &ArrayD<f64>, axes: &[usize]) -> ArrayD<f64>
Compute Root Mean Square along specified axes (keeping dims).
Sourcepub fn update_gamma(
&mut self,
new_gamma: ArrayD<f64>,
) -> Result<(), NormalizationError>
pub fn update_gamma( &mut self, new_gamma: ArrayD<f64>, ) -> Result<(), NormalizationError>
Update the learnable scale parameter gamma.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RmsNorm
impl RefUnwindSafe for RmsNorm
impl Send for RmsNorm
impl Sync for RmsNorm
impl Unpin for RmsNorm
impl UnsafeUnpin for RmsNorm
impl UnwindSafe for RmsNorm
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more