TorchLean API

NN.API.Public.Facade.Trainer.Train.Streams

TorchLean Stream Trainer Implementation #

Regression stream and paired-stream training for generated or resampled workloads.

def TorchLean.Trainer.Implementation.Regression.trainStreamFloatWithRun {σ τ : Shape} (trainer : Regression σ τ) (runtimeOpts : Options) (sampleAt : SupervisedSample Float σ τ) (evalSample : SupervisedSample Float σ τ) (run : RunConfig := trainer.runConfig) (trainOpts : TrainOptions := { }) (curveEvery cudaMemWatch : := 0) (onEval : String(Tensor.T Float σIO (Tensor.T Float τ))IO Unit := fun (x : ) (x_1 : String) (x_2 : Tensor.T Float σIO (Tensor.T Float τ)) => pure ()) :

Train a regression trainer from a step-indexed Float sample stream.

Use this when the "dataset" is really a recipe:

  • diffusion draws a fresh noised image at each step,
  • PDE examples resample collocation points,
  • operator-learning demos cycle generated batches while evaluating on one fixed probe.

The public contract is still trainer-shaped. The caller supplies sampleAt step, TorchLean owns the optimizer and runner state, and the returned value is the same trained model handle used by ordinary static-dataset training, plus a curve of evaluation loss on evalSample.

Instances For
    def TorchLean.Trainer.Implementation.Regression.trainStreamFloat {σ τ : Shape} (trainer : Regression σ τ) (runtimeOpts : Options) (sampleAt : SupervisedSample Float σ τ) (evalSample : SupervisedSample Float σ τ) (trainOpts : TrainOptions := { }) (curveEvery cudaMemWatch : := 0) (onEval : String(Tensor.T Float σIO (Tensor.T Float τ))IO Unit := fun (x : ) (x_1 : String) (x_2 : Tensor.T Float σIO (Tensor.T Float τ)) => pure ()) :

    Train a regression trainer from a Float sample stream using the trainer's attached runtime settings.

    This is the stream analogue of trainer.train: most static datasets should use the unified method, while generated or resampled workloads should use this entrypoint so they do not hand-roll module loops.

    Instances For
      def TorchLean.Trainer.Implementation.Regression.trainPairStreamFloat {σ₁ τ₁ σ₂ τ₂ : Shape} (first : Regression σ₁ τ₁) (second : Regression σ₂ τ₂) (runtimeOpts : Options) (firstSampleAt : SupervisedSample Float σ₁ τ₁) (secondSamplesAt : List (SupervisedSample Float σ₂ τ₂)) (evalTotal : (Tensor.T Float σ₁IO (Tensor.T Float τ₁))(Tensor.T Float σ₂IO (Tensor.T Float τ₂))IO Float) (trainOpts : TrainOptions := { }) (curveEvery : := 1) (cudaMemWatch : := 0) :
      IO (PairStreamTrainResult σ₁ τ₁ σ₂ τ₂)

      Train two regression trainers with an alternating Float sample stream.

      This is the public paired-model training path. A GAN is the motivating case: the generator receives one supervised warm-up sample per step, while the discriminator may receive both real and fake score samples. The facade owns the alternating optimizer mechanics and lets the example provide only the domain-specific pieces:

      • firstSampleAt step for the first model,
      • secondSamplesAt step for one or more second-model updates,
      • evalTotal predictFirst predictSecond for the scalar curve to record.

      The callback sees only prediction functions, never modules or optimizer states. That is the important boundary: examples can define meaningful metrics, but they do not become miniature copies of the runtime trainer.

      The trained handles use the paired evalTotal value for their before/after summaries. For coupled models, the generator and discriminator are judged by one task-level scalar, not by two unrelated dataset losses. If a future caller needs separate reports, it should expose them through the curve/history artifact rather than reopening the modules.

      Instances For