Fixed-Sample Training #
Some runnable examples train repeatedly on one caller-supplied sample:
- build a model with
TorchLean.nn.withModel, - wrap it as a
ScalarModuleDef(model + supervised loss), - load or synthesize one supervised sample
(x, y), - run
stepsoptimizer updates on that fixed sample, and - either print before/after loss or write a TrainLog curve.
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-zoo
loader helpers.
Before/after scalar losses for a fixed-sample training run.
- beforeLoss : α
- afterLoss : α
Instances For
def
TorchLean.Trainer.FixedSample.instReprLossPair.repr
{α✝ : Type}
[Repr α✝]
:
LossPair α✝ → ℕ → Std.Format
Instances For
def
TorchLean.Trainer.FixedSample.steps
{α : Type}
[Context α]
[DecidableEq Spec.Shape]
[ToString α]
[Runtime.FromFloat α]
[Runtime.Autograd.Torch.Internal.CudaBridge.TensorConv α]
{σ τ : Spec.Shape}
(mkModel : nn.M (nn.Sequential σ τ))
(mkModuleDef :
(model : nn.Sequential σ τ) →
Runtime.Autograd.TorchLean.ScalarModuleDef (Runtime.Autograd.TorchLean.NN.Seq.paramShapes model) [σ, τ])
(mkOptim : (Float → α) → (paramShapes : List Spec.Shape) → Runtime.Autograd.TorchLean.Optimizer α paramShapes)
(cast : Float → α)
(opts : Runtime.Autograd.Torch.Options)
(sample : Sample.Supervised α σ τ)
(steps : ℕ)
(cudaMemWatch : ℕ := 0)
:
One fixed-sample run for an arbitrary scalar backend.
Instances For
def
TorchLean.Trainer.FixedSample.curveFloat
{σ τ : Spec.Shape}
(mkModel : nn.M (nn.Sequential σ τ))
(mkModuleDef :
(model : nn.Sequential σ τ) →
Runtime.Autograd.TorchLean.ScalarModuleDef (Runtime.Autograd.TorchLean.NN.Seq.paramShapes model) [σ, τ])
(mkOptim : (paramShapes : List Spec.Shape) → Runtime.Autograd.TorchLean.Optimizer Float paramShapes)
(opts : Runtime.Autograd.Torch.Options)
(sample : Sample.Supervised Float σ τ)
(steps : ℕ)
(cudaMemWatch : ℕ := 0)
:
Fixed-sample run specialized to Float, returning a full per-step curve.