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.
- sgd (learningRate momentum : Float) : View
- adaGrad (learningRate epsilon : Float) : View
- rmsProp (learningRate decay epsilon : Float) : View
- adam (learningRate beta1 beta2 epsilon : Float) : View
- adamW (learningRate weightDecay beta1 beta2 epsilon : Float) : View
- adaDelta (learningRate rho epsilon : Float) : View
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.
- representation : TorchLean.optim.Optimizer.Internal.View
Instances For
Public SGD optimizer configuration.
Instances For
Public AdaGrad optimizer configuration.
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 { learningRate := 0.01 }
def withMomentum : optim.Optimizer :=
optim.sgd { learningRate := 0.01, momentum := 0.9 }
Instances For
AdaGrad optimizer config, written optim.adaGrad { learningRate := 0.05 }.
Instances For
RMSProp optimizer config, written optim.rmsProp { learningRate := 1e-3 }.
Instances For
Adam optimizer config, written optim.adam { learningRate := 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 { learningRate := 1e-3 }
Instances For
AdamW optimizer config, written optim.adamW { learningRate := 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 { learningRate := 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
Check the numerical domain of an optimizer configuration before allocating optimizer state.
The checks rule out undefined bias corrections and non-finite updates. They are shared by the trainer, manual-module, and reinforcement-learning entry points.
Instances For
Check both the supplied configuration and its binary32 representation.
Training must reject coefficients that round to one, stabilizers that round to zero, and finite
binary64 rates that overflow binary32. validate remains available for binary64 callers.