pub struct RMSNorm { /* private fields */ }Expand description
Root Mean Square Layer Normalization (Zhang & Sennrich, 2019).
A simplified version of LayerNorm that only uses the root mean square for normalization, without centering (no mean subtraction). This is faster than LayerNorm while achieving similar results.
y = x / RMS(x) * gamma
RMS(x) = sqrt(mean(x^2) + eps)Used in LLaMA, Gemma, and other modern transformers.
§Example
ⓘ
use aprender::nn::{RMSNorm, Module};
use aprender::autograd::Tensor;
let norm = RMSNorm::new(&[256]); // Normalize over 256 features
let x = Tensor::randn(&[32, 10, 256]); // [batch, seq, features]
let y = norm.forward(&x); // Normalized§References
- Zhang, B., & Sennrich, R. (2019). Root Mean Square Layer Normalization. NeurIPS.
Implementations§
Source§impl RMSNorm
impl RMSNorm
Sourcepub fn with_eps(normalized_shape: &[usize], eps: f32) -> Self
pub fn with_eps(normalized_shape: &[usize], eps: f32) -> Self
Create RMSNorm with custom epsilon.
Sourcepub fn without_affine(normalized_shape: &[usize]) -> Self
pub fn without_affine(normalized_shape: &[usize]) -> Self
Create RMSNorm without learnable parameters.
Sourcepub fn normalized_shape(&self) -> &[usize]
pub fn normalized_shape(&self) -> &[usize]
Get the normalized shape.
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 !UnwindSafe for RMSNorm
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§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> 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