#[non_exhaustive]pub struct NormSpec { /* private fields */ }Expand description
Kind, eps and optional affine parameters of an ErasedNormPlan.
The optional weight (scale) and bias (shift) are vectors along the
normalized axis, each with its own element stride; the result is
y * weight + bias.
§Examples
use strided_basic::{NormKind, NormSpec};
let spec = NormSpec::layer_norm(1e-5).with_weight(1).with_bias(-1);
assert_eq!(spec.kind(), NormKind::Layer);
assert_eq!(spec.eps(), 1e-5);
assert_eq!(spec.weight_stride(), Some(1));
assert_eq!(spec.bias_stride(), Some(-1));
assert_eq!(NormSpec::rms_norm(0.0).weight_stride(), None);Implementations§
Source§impl NormSpec
impl NormSpec
Sourcepub const fn layer_norm(eps: f64) -> Self
pub const fn layer_norm(eps: f64) -> Self
Layer normalization with the given eps and no affine parameters.
§Examples
use strided_basic::{NormKind, NormSpec};
assert_eq!(NormSpec::layer_norm(1e-6).kind(), NormKind::Layer);Sourcepub const fn rms_norm(eps: f64) -> Self
pub const fn rms_norm(eps: f64) -> Self
RMS normalization with the given eps and no affine parameters.
§Examples
use strided_basic::{NormKind, NormSpec};
assert_eq!(NormSpec::rms_norm(1e-6).kind(), NormKind::Rms);Sourcepub const fn with_weight(self, stride: isize) -> Self
pub const fn with_weight(self, stride: isize) -> Self
Multiply by a weight vector with the given element stride.
§Examples
use strided_basic::NormSpec;
assert_eq!(NormSpec::rms_norm(0.0).with_weight(2).weight_stride(), Some(2));Sourcepub const fn with_bias(self, stride: isize) -> Self
pub const fn with_bias(self, stride: isize) -> Self
Add a bias vector with the given element stride.
§Examples
use strided_basic::NormSpec;
assert_eq!(NormSpec::rms_norm(0.0).with_bias(1).bias_stride(), Some(1));Sourcepub const fn kind(&self) -> NormKind
pub const fn kind(&self) -> NormKind
Normalization kind.
§Examples
use strided_basic::{NormKind, NormSpec};
assert_eq!(NormSpec::rms_norm(0.0).kind(), NormKind::Rms);Sourcepub const fn eps(&self) -> f64
pub const fn eps(&self) -> f64
The eps added to the variance (or mean square) before the square root.
§Examples
use strided_basic::NormSpec;
assert_eq!(NormSpec::rms_norm(0.25).eps(), 0.25);Sourcepub const fn weight_stride(&self) -> Option<isize>
pub const fn weight_stride(&self) -> Option<isize>
Element stride of the weight vector, if any.
§Examples
use strided_basic::NormSpec;
assert_eq!(NormSpec::layer_norm(0.0).weight_stride(), None);Sourcepub const fn bias_stride(&self) -> Option<isize>
pub const fn bias_stride(&self) -> Option<isize>
Element stride of the bias vector, if any.
§Examples
use strided_basic::NormSpec;
assert_eq!(NormSpec::layer_norm(0.0).bias_stride(), None);Trait Implementations§
impl Copy for NormSpec
impl StructuralPartialEq for NormSpec
Auto Trait Implementations§
impl Freeze for NormSpec
impl RefUnwindSafe for NormSpec
impl Send for NormSpec
impl Sync for NormSpec
impl Unpin for NormSpec
impl UnsafeUnpin for NormSpec
impl UnwindSafe for NormSpec
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