Fixed-Sample Training #
Some runnable examples train repeatedly on one caller-supplied sample:
- build a model with
TorchLean.nn.withModel, - wrap it as an
ObjectiveDefinition(model + supervised loss), - load or synthesize one supervised input and target,
- run optimizer updates on that fixed sample, and
- report the loss before and after training.
This module provides that loop without tying it to a particular model family.
Scope:
- it trains against one fixed sample supplied by the caller;
- it is model-agnostic: callers supply the loss wrapper and optimizer constructor;
- it is backend-agnostic: callers can use it on CPU or CUDA via
API.Runtime.Options.
For dataset-backed training, use the TorchLean.Trainer API exported by NN or the shared model
loader helpers.
def
TorchLean.Trainer.FixedSample.train
{α : Type}
[Storage α]
[Context α]
[ToString α]
[Runtime.FromFloat α]
[Runtime.Autograd.Torch.TensorTransfer α]
{σ τ : Shape}
(buildModel : nn.Builder (nn.Sequential σ τ))
(buildObjective :
(model : nn.Sequential σ τ) →
Module.ObjectiveDefinition Unit (Runtime.Autograd.Model.Layers.Seq.stateShapes model) [σ, τ])
(buildOptimizer : (Float → α) → (stateShapes : List Shape) → Runtime.Autograd.Model.Optimizer α stateShapes)
(cast : Float → α)
(options : Runtime.Autograd.Torch.Config)
(sample : Sample.Supervised α σ τ)
(steps : ℕ)
(cudaMemorySampleEvery : ℕ := 0)
:
One fixed-sample run for an arbitrary scalar backend.