pub struct Trainer<B: Backend> {
pub executor: Executor<B>,
pub batch_size: usize,
/* private fields */
}Expand description
High-level training loop runner.
Reads the @training configuration from an IrProgram and orchestrates forward, backward, and optimizer steps.
Fields§
§executor: Executor<B>The graph executor.
batch_size: usizeBatch size (for reference, data batching is external).
Implementations§
Source§impl<B: Backend> Trainer<B>
impl<B: Backend> Trainer<B>
Sourcepub fn from_program(
program: IrProgram,
device: B::Device,
config: RuntimeConfig,
) -> Result<Self>
pub fn from_program( program: IrProgram, device: B::Device, config: RuntimeConfig, ) -> Result<Self>
Create a Trainer from an IrProgram.
Reads the @training block and fails if no training config exists.
Sourcepub fn train(
&mut self,
data: &[HashMap<String, Tensor<B>>],
targets_key: &str,
) -> Result<TrainResult>
pub fn train( &mut self, data: &[HashMap<String, Tensor<B>>], targets_key: &str, ) -> Result<TrainResult>
Run the training loop with an iterator of input batches.
Each batch is a HashMap<String, Tensor<B>> mapping input names to
tensors. Returns a TrainResult with per-epoch loss logs.
targets_key is the name of the target tensor in each batch map.
Sourcepub fn infer(
&self,
inputs: &HashMap<String, Tensor<B>>,
) -> Result<HashMap<String, Tensor<B>>>
pub fn infer( &self, inputs: &HashMap<String, Tensor<B>>, ) -> Result<HashMap<String, Tensor<B>>>
Run a single forward pass (inference mode).
Sourcepub fn model_graph_name(&self) -> &str
pub fn model_graph_name(&self) -> &str
Get the model graph name.
Sourcepub fn loss_fn_name(&self) -> &str
pub fn loss_fn_name(&self) -> &str
Get the loss function name.
Auto Trait Implementations§
impl<B> Freeze for Trainer<B>
impl<B> RefUnwindSafe for Trainer<B>
impl<B> Send for Trainer<B>
impl<B> Sync for Trainer<B>
impl<B> Unpin for Trainer<B>
impl<B> UnwindSafe for Trainer<B>
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> 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