TorchLean API

NN.API.Trainer.Run

Training Configuration #

Probes, run-configuration helpers, and per-training options for the trainer API. Command-line parsing is available separately from NN.API.CLI.Trainer, keeping process flags out of these configuration records.

A small input probe evaluated at the start and end of training.

  • name : String

    Human-facing probe name.

  • inputText : String

    Human-facing input description.

  • input : Tensor Float σ

    Concrete input converted to the selected runtime arithmetic when the probe runs.

  • expected : Option String

    Optional expected value shown beside the prediction.

Instances For
    def TorchLean.Trainer.Probe.tensor {σ : Shape} (name : String) (input : Tensor Float σ) (inputText : String := "") (expected : Option String := none) :

    Build a named prediction probe from a tensor.

    Example:

    -- Probes print a named prediction before and after the run, so training shows its movement
    -- without a separate evaluation script.
    def probes : Array (Trainer.Probe [2]) :=
      #[Trainer.Probe.tensor "heldout" [0.25, -0.75] (inputText := "x = (0.25, -0.75)")]
    
    Instances For

      Per-training-call options for the trainer API.

      steps has no default so that trainer.train data {} cannot silently perform a single update.

      Example:

      -- `steps` has no default on purpose: how long to train is not a library's decision.
      def options : Trainer.TrainOptions :=
        { steps := 200
          logEvery := 25
          saveCheckpoint? := some "checkpoints/mlp.state" }
      
      • steps : ℕ

        Number of optimizer updates.

      • samplesPerStep : ℕ

        Number of dataset items whose gradients are accumulated into one optimizer update.

        The items are processed one after another and their gradients are averaged at the same parameter point; this is gradient accumulation, not a vectorized minibatch. To run a vectorized minibatch, give the model an explicit batch axis and build the dataset with Data.batch, whose items are already fixed-size tensor minibatches, then keep this option at 1.

      • Optional learning-rate schedule, indexed by completed optimizer updates.

      • logEvery : ℕ

        Print step losses every logEvery updates; 0 disables stdout step logging.

      • cudaMemorySampleEvery : ℕ

        CUDA allocator sampling cadence. 0 uses automatic sampling for runs of at least 1000 updates and disables it for shorter runs. Non-CUDA runs do not sample the allocator.

      • logDestination : Training.LogDestination

        Optional TrainLog artifact destination. Use .disabled for stdout-only runs.

      • logTitle : String

        Title used when writing a TrainLog artifact.

      • logNotes : Array String

        Free-form notes attached to the TrainLog artifact.

      • loadCheckpoint? : Option System.FilePath

        Optional model-state checkpoint loaded before training; optimizer and schedule start fresh.

      • saveCheckpoint? : Option System.FilePath

        Optional model-state checkpoint written after training.

      • reportLoss : Bool

        Measure and print the evaluation-mode mean loss over the whole dataset before and after training. Each measurement is a forward pass over every sample, so large streamed datasets may turn it off; the report then records NaN for both losses.

      Instances For

        Reject option combinations that cannot describe a training run.

        Instances For