pub struct TextModelBase {
pub ctx: Context,
pub tokenizer: Tokenizer,
pub embedding: Embedding,
pub eos_token_id: Option<EosTokenId>,
pub index_pos: usize,
pub generated: usize,
pub prompt_len: usize,
pub blocks: Vec<Box<dyn Forwarder>>,
pub ln_f: RmsNorm,
pub lm_head: Linear,
pub logits_processor: LogitsProcessor,
pub tokens: Vec<u32>,
}Expand description
Shared base for decoder-only text models (LLaMA, Qwen2, Qwen3.5, etc.).
Contains all the state and logic that is identical across model architectures: embedding, transformer blocks, final norm, lm_head, tokenizer, sampling, and the forward/generation loop.
Fields§
§ctx: Context§tokenizer: Tokenizer§embedding: Embedding§eos_token_id: Option<EosTokenId>§index_pos: usize§generated: usize§prompt_len: usize§blocks: Vec<Box<dyn Forwarder>>§ln_f: RmsNorm§lm_head: Linear§logits_processor: LogitsProcessor§tokens: Vec<u32>Implementations§
Source§impl TextModelBase
impl TextModelBase
Sourcepub async fn load<B: Forwarder + 'static>(
ctx: &mut Context,
default_eos_token: &str,
) -> Result<Self>
pub async fn load<B: Forwarder + 'static>( ctx: &mut Context, default_eos_token: &str, ) -> Result<Self>
Load the shared model structure from the context.
default_eos_token is the model-specific fallback EOS string.
The type parameter B determines which block type to use for local layers.
Sourcepub async fn forward(&mut self, x: &Tensor, idx: usize) -> Result<Tensor>
pub async fn forward(&mut self, x: &Tensor, idx: usize) -> Result<Tensor>
Forward pass through all blocks.
Sourcepub fn prepare_prompt(&mut self, dialog: &str) -> Result<()>
pub fn prepare_prompt(&mut self, dialog: &str) -> Result<()>
Tokenize a prompt string and set up token state for generation.
Sourcepub async fn next_token(&mut self, index: usize) -> Result<Token>
pub async fn next_token(&mut self, index: usize) -> Result<Token>
Generate the next token. Assumes prepare_prompt() has been called for the first token.
Auto Trait Implementations§
impl !Freeze for TextModelBase
impl !RefUnwindSafe for TextModelBase
impl Send for TextModelBase
impl Sync for TextModelBase
impl Unpin for TextModelBase
impl UnsafeUnpin for TextModelBase
impl !UnwindSafe for TextModelBase
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> 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