TorchLean API

NN.Runtime.Autograd.Torch.ScalarTrainer

Scalar Trainer Operations #

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

def Runtime.Autograd.Torch.ScalarTrainer.loss {α δ : 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.grad {α δ : Type} [TorchLean.Storage α] [TorchLean.Storage δ] {paramShapes inputShapes dataInputShapes : List Spec.Shape} (trainer : ScalarTrainer α δ paramShapes inputShapes dataInputShapes) (inputs : TorchLean.TensorPack α inputShapes) (dataInputs : TorchLean.TensorPack δ dataInputShapes) (value : Bool := false) :
    IO (match value with | false => TorchLean.TensorPack α paramShapes | true => TorchLean.TensorPack α paramShapes × TorchLean.Tensor α Spec.Shape.scalar)

    Evaluate parameter gradients on packed inputs.

    Set value := true to return (gradients, loss) from the same forward tape. The default uses the backend's gradient-only operation.

    Instances For