Trainer Runtime Internals #
Scalar-generic implementation of the trainer: an instantiated model with reusable forward and loss
evaluators (Runner), gradient accumulation and optimizer updates, and the stateful Stepper that
applies a configured optimizer and schedule.
Everything here is indexed by the runtime scalar α. The public API (Trainer.Session,
Trainer.train, Trainer.predict) wraps it and exposes Float only.
A checked model instantiated under one runtime scalar.
This bundles the imperative runtime objective (parameters and buffers stored in refs), reusable no-gradient forward and evaluation-loss evaluators over the same live state, and the current mode. Training forwards update their buffers; evaluation forwards leave them unchanged.
- runtimeObjective : TorchLean.Module.Objective α Unit (Runtime.Autograd.Model.Layers.Seq.stateShapes model) [σ, τ]
- trainingPredictor : Runtime.Autograd.Model.Module.Evaluator α Unit (Runtime.Autograd.Model.Layers.Seq.stateShapes model) [σ] [] τ
- evaluationPredictor : Runtime.Autograd.Model.Module.Evaluator α Unit (Runtime.Autograd.Model.Layers.Seq.stateShapes model) [σ] [] τ
- evaluationLossEvaluator : Runtime.Autograd.Model.Module.ObjectiveEvaluator α Unit (Runtime.Autograd.Model.Layers.Seq.stateShapes model) [σ, τ]
- modeRef : IO.Ref TorchLean.nn.Mode
Instances For
Construct a runner from its objective, evaluators, and mode cell.
The executable runtime module behind a runner.
The reusable no-gradient evaluator for one execution mode.
Reusable evaluator for the evaluation-mode loss.
The runner's mode cell.
Runtime configuration used by the runner's objective.
Instances For
Finish runner construction once its executable objective has been instantiated.
Instances For
Instantiate a model and objective under a runtime scalar, injecting literals with ofFloat.
Instances For
Read the complete parameter-and-buffer state.
Instances For
Replace the complete parameter-and-buffer state.
Instances For
Read every tensor of a runtime pack back to host Float.
Instances For
Read the state back as host Float tensors; exact for binary32 runtime scalars.
Instances For
Replace the state from host Float tensors, casting them into the runtime scalar.
Instances For
Initialize the state owned by a runtime optimizer for this runner.
Instances For
Select training behavior for stateful layers.
Instances For
Select evaluation behavior for stateful layers.
Instances For
Evaluate one input tensor in an explicit mode without changing the runner's mode cell.
Instances For
Scalar loss of one supervised sample in an explicit mode without changing the runner's mode cell.
Training uses the instantiated objective, including its random stream and buffer updates. Evaluation uses a reusable no-gradient evaluator over the same live parameter objects and does not update running buffers.
Instances For
Scalar loss of one supervised sample using the active mode.
Instances For
Mean scalar loss over a finite sample stream in the active mode; 0 for an empty stream.
Instances For
Optimizer binding #
Bind a configured optimizer, its initialized state, and its scheduled state updater.
Instances For
Instances For
Gradient accumulation and optimizer updates #
Compute mean parameter gradients for a nonempty batch at one parameter point.
Set value := true to return (meanGradient, meanLoss).
Instances For
Apply one optimizer update to a nonempty batch.
When useNative is set, supported CUDA optimizers accumulate gradients on device and use the
same moment state for every batch size. Other optimizers average explicit per-sample gradients.
Set loss := true to return (nextOptimizerState, meanLoss).
Instances For
Stateful steppers #
Stateful optimizer step functions and completed-step counter for one runner.
- runBatch : Array (TorchLean.Sample.Supervised α σ τ) → IO α
- runBatchSilently : Array (TorchLean.Sample.Supervised α σ τ) → IO Unit
Instances For
Construct a stepper from its hidden batch-step functions and counter.
The hidden loss-returning batch-step function.
The hidden batch-step function that does not read the loss back.
The hidden completed-step counter.
Run one optimizer step and return its scalar loss.
Instances For
Run one averaged-gradient optimizer step over a nonempty batch and return its mean scalar loss.
Every sample is differentiated at the same parameter point. The completed-step counter advances once for the whole batch.
Instances For
Run one optimizer step over a nonempty batch without reading the loss back.
Instances For
Read the number of completed optimizer steps.
Instances For
Construct a Stepper for a runner, optimizer config, and optional scheduler.
Every step switches the runner to training mode, applies the schedule for the current step index, and advances the completed-step counter once per batch. A singleton batch uses the runtime's native single-sample update.