TorchLean API

NN.Runtime.Optim.Schedulers.Core

Scheduler Arithmetic #

Learning-rate schedulers for TorchLean runtime training.

Schedulers are small deterministic state machines that answer:

TorchLean keeps schedulers explicit and pure so:

Step counter convention:

This module contains the shared scalar operations used by native and PyTorch-compatible schedules.

References (common schedules we implement):

PyTorch references:

Shared utilities #

def Optim.SchedulerUtils.clamp {α : Type} [Context α] [DecidableRel fun (x1 x2 : α) => x1 > x2] (value lo hi : α) :
α

Clamp value to the closed interval [lo, hi].

Instances For
    def Optim.SchedulerUtils.safeDiv {α : Type} [Context α] (num denom : α) :
    α

    Safe division num/denom.

    Returns 0 when denom == 0 so schedulers stay total even when misconfigured. This is used by the PyTorch-compatible schedulers, which mirror PyTorch's use of floating pct values but avoid exceptions in pure code.

    Instances For
      def Optim.SchedulerUtils.ratioNat {α : Type} [Context α] (num denom : ) :
      α

      Safe ratio num/denom cast into the scalar type.

      Returns 0 when denom = 0 so schedulers stay total even when misconfigured.

      Instances For
        def Optim.SchedulerUtils.linearInterpolation {α : Type} [Context α] [DecidableRel fun (x1 x2 : α) => x1 > x2] (startValue endValue factor : α) :
        α

        Linear interpolation between startValue and endValue with factor ∈ [0,1].

        Instances For
          def Optim.SchedulerUtils.linearInterpolationRaw {α : Type} [Context α] (startValue endValue factor : α) :
          α

          Linear interpolation between startValue and endValue with no clamping.

          This matches PyTorch's anneal helpers (OneCycleLR._annealing_linear), which permit factor outside [0,1] and therefore extrapolate.

          Instances For
            def Optim.SchedulerUtils.cosineInterpolation {α : Type} [Context α] [DecidableRel fun (x1 x2 : α) => x1 > x2] (startValue endValue factor : α) :
            α

            Cosine interpolation between startValue and endValue with factor ∈ [0,1].

            This is the usual smooth schedule: it starts and ends with zero slope.

            Instances For
              def Optim.SchedulerUtils.cosineAnnealRaw {α : Type} [Context α] (startValue endValue factor : α) :
              α

              Cosine anneal between startValue and endValue with no clamping.

              This matches PyTorch's anneal helper (OneCycleLR._annealing_cos).

              Instances For