pub struct LayerNorm { /* private fields */ }
Expand description
[Listing 4.2] A layer normalization struct
Implementations§
Source§impl LayerNorm
impl LayerNorm
Sourcepub fn new(emb_dim: usize, vb: VarBuilder<'_>) -> Result<Self>
pub fn new(emb_dim: usize, vb: VarBuilder<'_>) -> Result<Self>
Creates a new LayerNorm
use candle_core::{Device, DType};
use candle_nn::{VarBuilder, VarMap};
use llms_from_scratch_rs::listings::ch04::{Config, LayerNorm};
let dev = Device::cuda_if_available(0).unwrap();
let varmap = VarMap::new();
let vb = VarBuilder::from_varmap(&varmap, DType::F32, &dev);
let cfg = Config::gpt_sm_test();
let layer_norm = LayerNorm::new(cfg.emb_dim, vb).unwrap();
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LayerNorm
impl !RefUnwindSafe for LayerNorm
impl Send for LayerNorm
impl Sync for LayerNorm
impl Unpin for LayerNorm
impl !UnwindSafe 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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