pub struct LayerNorm {
pub weight: Option<Param>,
pub bias: Option<Param>,
pub dim: usize,
pub eps: f32,
}Expand description
Differentiable LayerNorm using candle_nn::ops::layer_norm_slow (for OPT).
Fields§
§weight: Option<Param>Optional affine weight (dim,).
bias: Option<Param>Optional affine bias (dim,).
dim: usizeHidden size.
eps: f32Stability epsilon.
Implementations§
Source§impl LayerNorm
impl LayerNorm
Sourcepub fn from_tensors(
prefix: &str,
tensors: &HashMap<String, Tensor>,
dim: usize,
eps: f64,
affine: bool,
dtype: DType,
device: &Device,
) -> Result<Self>
pub fn from_tensors( prefix: &str, tensors: &HashMap<String, Tensor>, dim: usize, eps: f64, affine: bool, dtype: DType, device: &Device, ) -> Result<Self>
Load LayerNorm {prefix}.weight and {prefix}.bias when affine is true.
§Errors
Returns ModelError::MissingWeight if expected weights are absent.
Sourcepub fn new_init(
dim: usize,
eps: f64,
affine: bool,
dtype: DType,
device: &Device,
) -> Result<Self>
pub fn new_init( dim: usize, eps: f64, affine: bool, dtype: DType, device: &Device, ) -> Result<Self>
Construct standard unit-weight, zero-bias LayerNorm.
§Errors
Returns an error if tensor creation fails.
Sourcepub fn trainable_vars(&self) -> Vec<Var>
pub fn trainable_vars(&self) -> Vec<Var>
Collect trainable variables.
Sourcepub fn make_trainable(&mut self) -> Result<()>
pub fn make_trainable(&mut self) -> Result<()>
Sourcepub fn pack_state_dict(&self, prefix: &str, out: &mut HashMap<String, Tensor>)
pub fn pack_state_dict(&self, prefix: &str, out: &mut HashMap<String, Tensor>)
Export {prefix}.weight and {prefix}.bias.
Sourcepub fn param_count(&self) -> usize
pub fn param_count(&self) -> usize
Scalar parameter count.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for LayerNorm
impl !UnwindSafe for LayerNorm
impl Freeze for LayerNorm
impl Send for LayerNorm
impl Sync for LayerNorm
impl Unpin for LayerNorm
impl UnsafeUnpin for LayerNorm
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
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