TorchLean API

NN.Runtime.Autograd.Torch.ScalarTrainer

Scalar Trainer Operations #

Packed loss, gradient, and update operations, plus simple training and evaluation loops. Differentiable inputs use scalar type α; non-differentiable data, such as token identifiers, labels, or masks, use a separate type δ.

def Runtime.Autograd.Torch.ScalarTrainer.runLoss {α δ : Type} [TorchLean.Storage α] [TorchLean.Storage δ] {paramShapes inputShapes dataInputShapes : List Spec.Shape} (trainer : ScalarTrainer α δ paramShapes inputShapes dataInputShapes) (inputs : TorchLean.TensorPack α inputShapes) (dataInputs : TorchLean.TensorPack δ dataInputShapes) :

Evaluate the scalar loss on packed differentiable and non-differentiable inputs.

Instances For
    def Runtime.Autograd.Torch.ScalarTrainer.runDiff {α δ : Type} [TorchLean.Storage α] [TorchLean.Storage δ] {paramShapes inputShapes dataInputShapes : List Spec.Shape} (trainer : ScalarTrainer α δ paramShapes inputShapes dataInputShapes) (inputs : TorchLean.TensorPack α inputShapes) (dataInputs : TorchLean.TensorPack δ dataInputShapes) :

    Evaluate one loss and its parameter gradients from the same tape.

    Instances For
      def Runtime.Autograd.Torch.ScalarTrainer.runGrad {α δ : Type} [TorchLean.Storage α] [TorchLean.Storage δ] {paramShapes inputShapes dataInputShapes : List Spec.Shape} (trainer : ScalarTrainer α δ paramShapes inputShapes dataInputShapes) (inputs : TorchLean.TensorPack α inputShapes) (dataInputs : TorchLean.TensorPack δ dataInputShapes) :
      IO (TorchLean.TensorPack α paramShapes)

      Evaluate parameter gradients on packed inputs.

      Instances For
        def Runtime.Autograd.Torch.ScalarTrainer.runStep {α δ : Type} [TorchLean.Storage α] [TorchLean.Storage δ] {paramShapes inputShapes dataInputShapes : List Spec.Shape} (trainer : ScalarTrainer α δ paramShapes inputShapes dataInputShapes) (learningRate : α) (inputs : TorchLean.TensorPack α inputShapes) (dataInputs : TorchLean.TensorPack δ dataInputShapes) :

        Apply the trainer's SGD update to packed inputs.

        Instances For
          def Runtime.Autograd.Torch.ScalarTrainer.runStepWithLoss {α δ : Type} [TorchLean.Storage α] [TorchLean.Storage δ] {paramShapes inputShapes dataInputShapes : List Spec.Shape} (trainer : ScalarTrainer α δ paramShapes inputShapes dataInputShapes) (learningRate : α) (inputs : TorchLean.TensorPack α inputShapes) (dataInputs : TorchLean.TensorPack δ dataInputShapes) :

          Apply the trainer's SGD update and return the loss used for the update.

          Instances For
            def Runtime.Autograd.Torch.trainCycleSGD {α : Type} [TorchLean.Storage α] [ToString α] {paramShapes inputShapes : List Spec.Shape} (trainer : ScalarTrainer α Unit paramShapes inputShapes) (learningRate : α) (steps : ) (samples : List (TorchLean.TensorPack α inputShapes)) (logEvery : := 1) :

            Apply steps SGD updates while cycling through samples without auxiliary data tensors.

            Logging reuses each update's loss. Set logEvery := 0 to disable logging. Rejects an empty dataset.

            Instances For
              def Runtime.Autograd.Torch.meanLoss {α : Type} [TorchLean.Storage α] [Add α] [Div α] [Zero α] [NatCast α] {paramShapes inputShapes : List Spec.Shape} (trainer : ScalarTrainer α Unit paramShapes inputShapes) (samples : List (TorchLean.TensorPack α inputShapes)) :
              IO α

              Evaluate the arithmetic mean loss over samples without auxiliary data tensors.

              Rejects an empty dataset.

              Instances For