Skip to main content

Trainer

Struct Trainer 

Source
pub struct Trainer { /* private fields */ }
Expand description

High-level trainer that bundles a model and training config.

Construct via Trainer::builder() and the TrainerBuilder struct. Users provide token sequences (Vec<Vec<u32>>) from their own tokenizer.

Implementations§

Source§

impl Trainer

Source

pub fn builder() -> TrainerBuilder

Returns a new TrainerBuilder with sensible defaults.

Source

pub fn train_on_token_sequences_with_callback( &mut self, sequences: &[Vec<u32>], on_step: impl FnMut(usize, f32), ) -> Result<TrainingReport>

Trains the model on the provided token sequences.

Each inner Vec<u32> is a tokenized text sample. Use your own tokenizer to produce these sequences before calling this method.

The on_step callback is invoked after each optimizer step with (step_index, loss_value).

Source

pub fn train_on_token_sequences( &mut self, sequences: &[Vec<u32>], ) -> Result<TrainingReport>

Convenience wrapper that trains without a per-step callback.

Source

pub fn train_on_chat_sequences_with_callback( &mut self, chat_pairs: &[(Vec<u32>, Vec<u32>)], on_step: impl FnMut(usize, f32), ) -> Result<TrainingReport>

Trains the model on chat-style (prompt, response) token-ID pairs.

Each element of chat_pairs is (prompt_token_ids, response_token_ids). The model sees the full context but loss is computed only on response tokens, preventing the model from learning to generate role labels.

The on_step callback is invoked after each optimizer step with (step_index, loss_value).

Source

pub fn train_on_chat_sequences( &mut self, chat_pairs: &[(Vec<u32>, Vec<u32>)], ) -> Result<TrainingReport>

Convenience wrapper that trains on chat pairs without a per-step callback.

Source

pub fn save_checkpoint(&self, path: &str) -> Result<()>

Saves a model checkpoint to the given path.

Source

pub fn model(&self) -> &DefaultMultiscreenModel

Returns a reference to the underlying model.

Source

pub fn model_mut(&mut self) -> &mut DefaultMultiscreenModel

Returns a mutable reference to the underlying model.

Source

pub fn training_config(&self) -> &ModelTrainingConfig

Returns a reference to the training configuration.

Trait Implementations§

Source§

impl Debug for Trainer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.