pub struct GPTModel { /* private fields */ }
Expand description
[Listing 4.7] The GPT model architecture implementation
Implementations§
Source§impl GPTModel
New GPTModel
constructor using ConfigV2
impl GPTModel
New GPTModel
constructor using ConfigV2
pub fn new_v2(cfg: ConfigV2, vb: VarBuilder<'_>) -> Result<Self>
Source§impl GPTModel
impl GPTModel
Sourcepub fn new(cfg: Config, vb: VarBuilder<'_>) -> Result<Self>
pub fn new(cfg: Config, vb: VarBuilder<'_>) -> Result<Self>
Creates a new GPTModel
use candle_core::{Device, DType};
use candle_nn::{VarBuilder, VarMap};
use llms_from_scratch_rs::listings::ch04::{Config, GPTModel};
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 model = GPTModel::new(cfg, vb).unwrap();
pub fn from_fields( tok_emb: Embedding, pos_emb: Embedding, drop_emb: Dropout, trf_blocks: SequentialTransformers, final_norm: LayerNorm, out_head: Linear, ) -> Result<Self>
pub fn drop_emb(&self) -> &Dropout
pub fn tok_emb(&self) -> &Embedding
pub fn pos_emb(&self) -> &Embedding
pub fn trf_blocks(&self) -> &SequentialTransformers
pub fn final_norm(&self) -> &LayerNorm
pub fn out_head(&self) -> &Linear
Sourcepub fn forward(&self, xs: &Tensor) -> Result<Tensor>
pub fn forward(&self, xs: &Tensor) -> Result<Tensor>
Manual implementation of forward
Note: that blanket implementation of ModuleT
when a type implements
Module
prevents having forward
being overrided. Thus, this type
is ModuleT
but technically not Module
.
pub fn set_out_head(&mut self, new_out_head: Linear)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GPTModel
impl !RefUnwindSafe for GPTModel
impl Send for GPTModel
impl Sync for GPTModel
impl Unpin for GPTModel
impl !UnwindSafe for GPTModel
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