TorchLean API

NN.API.Optim.Config

Optimizer Configuration #

Optimizer algorithms and hyperparameters shared by the public training and runtime APIs.

Closed optimizer representation used only when lowering the public configuration to a runtime.

Instances For

    An optimizer configuration accepted by the trainer and manual-module APIs.

    Construct values with optim.sgd, optim.adam, and the other record-based helpers. The sealed representation prevents positional runtime constructors from leaking into user code.

    Instances For

      Public SGD optimizer configuration.

      • lr : Float

        Learning rate.

      • momentum : Float

        Momentum coefficient.

      Instances For
        @[instance_reducible]

        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
              @[instance_reducible]

              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

                  Build the sealed public optimizer value at the API boundary.

                  Reveal an optimizer only at the runtime-lowering boundary.

                  Render a hyperparameter as a Lean expression, preserving every finite binary64 bit.

                  FloatLib rounds the exact value to seventeen significant decimal digits. The candidate is decoded with Lean's scientific-literal decoder and OfScientific Float; it is used only if the resulting bits match. Otherwise an explicit Float.ofBits expression retains the original finite value. Negative zero and nonfinite values use Float.ofBits directly. NaNs follow Lean's canonicalization.

                  Instances For

                    SGD optimizer config, optionally with momentum.

                    Example:

                    -- `torch.optim.SGD(params, lr=0.01)`, then the same with heavy-ball momentum.
                    def plain : optim.Optimizer := optim.sgd { lr := 0.01 }
                    
                    def withMomentum : optim.Optimizer :=
                      optim.sgd { lr := 0.01, momentum := 0.9 }
                    
                    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 }.

                          Example:

                          -- `torch.optim.Adam(params, lr=1e-3)`: same default moments, same stabilizer
                          -- (Kingma and Ba, "Adam: A Method for Stochastic Optimization", ICLR 2015).
                          def optimizer : optim.Optimizer := optim.adam { lr := 1e-3 }
                          
                          Instances For

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

                            Example:

                            -- Decoupled weight decay, so the penalty does not travel through the adaptive moments
                            -- (Loshchilov and Hutter, "Decoupled Weight Decay Regularization", ICLR 2019).
                            def optimizer : optim.Optimizer :=
                              optim.adamW { lr := 1e-3, weightDecay := 0.01 }
                            
                            Instances For

                              AdaDelta optimizer config, written optim.adaDelta {}.

                              Instances For

                                Render an optimizer in the record-based syntax used to construct it. Finite fields retain their binary64 bits through Internal.formatScalar, including coefficients close to one and subnormal stabilizers. Negative zero and nonfinite fields use explicit Float.ofBits expressions; NaNs follow Lean's canonicalization.

                                Instances For

                                  Return the base learning rate encoded in an optimizer configuration.

                                  Instances For

                                    Reject a hyperparameter that is not a finite number at or above zero.

                                    isFinite is the load-bearing half of the test: 0.0 <= value alone would accept +∞, and an infinite learning rate or weight decay poisons every later update instead of failing where it was configured.

                                    Instances For

                                      Reject a coefficient that is not a finite number in [0, 1).

                                      Exponential-average coefficients such as Adam's beta1 and beta2 belong in the half-open interval: at exactly 1.0 the running average never forgets its initial value, so the optimizer would ignore the gradient forever rather than merely converge slowly.

                                      Instances For

                                        Reject a hyperparameter that is not a finite number strictly above zero. This is the check for quantities that end up in a denominator, such as Adam's epsilon.

                                        Instances For

                                          Check the numerical domain of an optimizer configuration before allocating optimizer state.

                                          The checks require finite hyperparameters, nonnegative rates and weight decay, positive stabilizers, and averaging coefficients below one. They are shared by the trainer, manual-module, and reinforcement-learning entry points. They do not bound parameters or gradients, so valid hyperparameters alone do not guarantee finite updates.

                                          Instances For

                                            Transform every scalar in a configuration for validation after conversion.

                                            Instances For