TorchLean API

NN.Runtime.Autograd.Model.Training

TorchLean training-loop helpers #

Training loops over the runtime optimizer interface. The simpler SGD loop lives in Runtime.Autograd.Torch.ScalarTrainer, where it only needs the trainer's own update operation.

def Runtime.Autograd.Model.trainCycleOptim {α : Type} [TorchLean.Storage α] [Context α] [ToString α] {paramShapes inputShapes : List Spec.Shape} (tr : Torch.ScalarTrainer α Unit paramShapes inputShapes) (opt : Optim.Optimizer α paramShapes) (st0 : opt.State) (steps : ) (samples : Array (TorchLean.TensorPack α inputShapes)) (logEvery : := 1) :
IO opt.State

Train steps updates with an arbitrary TorchLean optimizer, cycling through samples.

PyTorch comparison: analogous to using a torch.optim.Optimizer and calling loss.backward(); opt.step() in a loop, except here opt.step consumes an explicit gradient TorchLean.TensorPack aligned with paramShapes.

Instances For