TorchLean API

NN.API.Optim

Optimizers #

Optimizer configuration records and runtime optimizer constructors.

The default trainer config exposes self-contained core update rules for SGD, momentum SGD, AdaGrad, RMSProp, Adam, AdamW, and Adadelta. Runtime-only extension points live here too:

@[reducible, inline]

Optimizer algorithm and hyperparameters used by Trainer.

Instances For

    Public SGD optimizer configuration.

    • lr : Float

      Learning rate.

    • momentum : Float

      Momentum coefficient.

    Instances For

      Public AdaGrad optimizer configuration.

      • lr : Float

        Learning rate.

      • epsilon : Float

        Numerical stabilizer.

      Instances For

        Public RMSProp optimizer configuration.

        • lr : Float

          Learning rate.

        • decay : Float

          Decay coefficient for the running average of squared gradients.

        • epsilon : Float

          Numerical stabilizer.

        Instances For

          Public Adam optimizer configuration.

          • lr : Float

            Learning rate.

          • beta1 : Float

            First moment coefficient.

          • beta2 : Float

            Second moment coefficient.

          • epsilon : Float

            Numerical stabilizer.

          Instances For

            Public AdamW optimizer configuration.

            Instances For

              Public Adadelta optimizer configuration.

              • lr : Float

                Learning rate.

              • rho : Float

                Decay coefficient for gradient/update accumulators.

              • epsilon : Float

                Numerical stabilizer.

              Instances For

                SGD optimizer config, written optim.sgd { lr := 0.05 }.

                Instances For

                  Momentum SGD, using momentum 0.9 when the configuration leaves it at zero.

                  Instances For

                    AdaGrad optimizer config, written optim.adagrad { lr := 0.05 }.

                    Instances For

                      RMSProp optimizer config, written optim.rmsprop { lr := 1e-3 }.

                      Instances For

                        Adam optimizer config, written optim.adam { lr := 1e-3 }.

                        Instances For

                          AdamW optimizer config, written optim.adamw { lr := 1e-3, weightDecay := 0.01 }.

                          Instances For

                            Adadelta optimizer config, written optim.adadelta {}.

                            Instances For

                              Optimizer names accepted by model-training commands.

                              Instances For
                                @[implicit_reducible]

                                Parse an optimizer name used by --optim.

                                Instances For

                                  Name written to logs and summaries.

                                  Instances For

                                    Build the selected optimizer with the defaults used by training commands.

                                    Instances For
                                      def TorchLean.optim.runtimeAdam {α : Type} [Context α] (lr beta1 beta2 epsilon : α) {paramShapes : List Shape} :

                                      Runtime Adam optimizer for module-level training.

                                      Instances For
                                        def TorchLean.optim.runtimeAdamW {α : Type} [Context α] (lr weightDecay beta1 beta2 epsilon : α) {paramShapes : List Shape} :

                                        Runtime AdamW optimizer for module-level training.

                                        Instances For
                                          def TorchLean.optim.runtimeSGD {α : Type} [Context α] (lr : α) {paramShapes : List Shape} :

                                          Runtime SGD optimizer for module-level training.

                                          Instances For
                                            def TorchLean.optim.runtimeMomentumSGD {α : Type} [Context α] (lr momentum : α) {paramShapes : List Shape} :

                                            Runtime momentum-SGD optimizer for module-level training.

                                            Instances For
                                              def TorchLean.optim.runtimeAdaGrad {α : Type} [Context α] (lr epsilon : α) {paramShapes : List Shape} :

                                              Runtime AdaGrad optimizer for module-level training.

                                              Instances For
                                                def TorchLean.optim.runtimeRMSProp {α : Type} [Context α] (lr decay epsilon : α) {paramShapes : List Shape} :

                                                Runtime RMSProp optimizer for module-level training.

                                                Instances For
                                                  def TorchLean.optim.runtimeAdadelta {α : Type} [Context α] (lr rho epsilon : α) {paramShapes : List Shape} :

                                                  Runtime Adadelta optimizer for module-level training.

                                                  Instances For
                                                    @[reducible, inline]

                                                    Orthogonalization backend for a matrix-shaped update.

                                                    Muon uses a momentum buffer and then replaces the raw momentum direction by an approximately orthogonalized update, commonly via Newton-Schulz iterations. TorchLean keeps this as an explicit backend so the pure update rule is testable before CUDA kernels are introduced.

                                                    Instances For

                                                      The identity orthogonalizer, used when Muon is requested without a matrix backend.

                                                      Instances For
                                                        def TorchLean.optim.runtimeMuon {α : Type} [Context α] (lr momentum : α) (orthogonalizer : {s : Shape} → MuonOrthogonalizer α s := fun {s : Shape} => identityMuonOrthogonalizer) {paramShapes : List Shape} :

                                                        Runtime Muon-style optimizer for module-level training.

                                                        Muon is public at the runtime layer because a meaningful Muon run needs an orthogonalization backend. The default identity backend supports proofs and fallback behavior; production Muon should pass a matrix-shaped orthogonalizer.

                                                        Instances For

                                                          Identity projector, used when projected SGD is requested without a projection backend.

                                                          Instances For
                                                            def TorchLean.optim.galore.projectedSGD {α : Type} [Context α] (lr : α) (projector : {s : Shape} → Projector α s s := fun {s : Shape} => identityProjector) {paramShapes : List Shape} :

                                                            Projected-SGD runtime constructor for GaLore-style gradient projection.

                                                            This is a projection strategy wrapped around an SGD update. Full GaLore also needs a policy that constructs and refreshes low-rank projectors for matrix parameters; this constructor exposes the verified update boundary once a same-shape projector is supplied.

                                                            Instances For