TorchLean API

NN.Runtime.Autograd.Model.Module.Evaluator

Module Evaluators #

Reusable no-gradient evaluators over live module state, including scalar-objective evaluation.

structure Runtime.Autograd.Model.Module.Evaluator (α β : Type) [TorchLean.Storage α] [TorchLean.Storage β] (stateShapes inputShapes dataInputShapes : List Spec.Shape) (outputShape : Spec.Shape) :

A reusable no-gradient evaluator over existing model state.

The evaluator accepts differentiable tensors and non-differentiable data tensors separately. It can therefore run both scalar objectives and tensor-valued forward programs without rebuilding a session for each input batch.

Instances For
    @[reducible, inline]
    abbrev Runtime.Autograd.Model.Module.ObjectiveEvaluator (α β : Type) [TorchLean.Storage α] [TorchLean.Storage β] (stateShapes inputShapes : List Spec.Shape) (dataInputShapes : List Spec.Shape := []) :

    Scalar-output specialization of Evaluator.

    Instances For
      def Runtime.Autograd.Model.Module.Evaluator.run {α β : Type} [TorchLean.Storage α] [TorchLean.Storage β] {stateShapes inputShapes dataInputShapes : List Spec.Shape} {outputShape : Spec.Shape} (evaluator : Evaluator α β stateShapes inputShapes dataInputShapes outputShape) (xs : TorchLean.TensorPack α inputShapes) (dataInputs : TorchLean.TensorPack β dataInputShapes) :
      IO (TorchLean.Tensor α outputShape)

      Apply a reusable evaluator to shape-indexed ordinary and discrete inputs.

      Instances For
        def Runtime.Autograd.Model.Module.Evaluator.withState {α β : Type} [TorchLean.Storage α] [TorchLean.Storage β] [Context α] [tensorTransfer : Torch.TensorTransfer α] {stateShapes inputShapes dataInputShapes : List Spec.Shape} {outputShape : Spec.Shape} (program : ProgramWithDataInputs α β (stateShapes ++ inputShapes) dataInputShapes outputShape) (options : Config) (state : Torch.ParamList α stateShapes) (validateDataInputs : TorchLean.TensorPack β dataInputShapesExcept String Unit := fun (x : TorchLean.TensorPack β dataInputShapes) => pure ()) (rngCounter : Option (IO.Ref ) := none) :
        IO (Evaluator α β stateShapes inputShapes dataInputShapes outputShape)

        Create a reusable no-gradient evaluator for an execution-polymorphic program.

        The evaluator shares the supplied live parameter objects. Its eager session is reset after every call, so validation and generation do not retain one execution graph per input batch.

        Instances For
          def Runtime.Autograd.Model.Module.ObjectiveDef.evaluatorWithState {α β : Type} [TorchLean.Storage α] [TorchLean.Storage β] [Context α] [tensorTransfer : Torch.TensorTransfer α] {stateShapes inputShapes dataInputShapes : List Spec.Shape} (d : ObjectiveDef β stateShapes inputShapes dataInputShapes) (options : Config) (state : Torch.ParamList α stateShapes) :
          IO (ObjectiveEvaluator α β stateShapes inputShapes dataInputShapes)

          Create a reusable no-gradient evaluator over an existing live parameter list.

          This is useful when two definitions share the same parameter layout but differ in execution mode, for example training and evaluation losses for a model containing dropout. The evaluator shares the parameter objects and their current backend storage with the training module. Its eager session is reset after every call, so repeated validation does not retain one execution graph per batch.

          Instances For