TorchLean API

NN.API.Trainer

Training #

The main training interface:

let trainer := Trainer.new model
  { objective := .meanSquaredError
    optimizer := optim.adam { learningRate := 0.03 } }
let y0 ← trainer.predict x
let trained ← trainer.train data { steps := 200, samplesPerStep := 16, logEvery := 25 }
trained.printSummary
trained.save "model.state"

The same interface supports regression, classification, custom losses, finite datasets, and streaming batches. Public signatures use Tensor Float; the run executes in the binary32 scalar selected by arithmetic (Float32 or ExecFloat.Binary 8 23) and the report names it.

Programs that own the optimizer loop open the same trainer as a session:

let session ← trainer.open
for step in [0:steps] do
  let loss ← session.step (sampleAt step)
let trained ← session.finish { before, after }

trainer.train is exactly this pattern with dataset cycling, logging, and checkpoints added. Benchmark and diagnostic code that repeatedly trains one sample should import NN.API.Trainer.FixedSample explicitly.