Optimizer Law Interface #
This module gives TorchLean optimizers a small proof layer interface.
Runtime optimizers live in NN.Runtime.Optim.Optimizers as executable tensor equations. The
definitions below package those equations as shape-polymorphic optimizers and provide a common
interface for independent update specifications.
The pattern for adding an optimizer is:
- define a pure per-tensor
initandupdateequation; - package it as a
TensorOptimizer; - state an independent
StepSpecwhen a proof-facing recurrence is needed; - prove optimizer-specific algebraic facts as consequences of that generic interface.
TorchLean does not register a second, definitionally identical copy of every runtime update. Such a
copy would add a theorem name without adding an independent claim. Higher-level trainer proofs can
instead quantify over any TensorOptimizer, reason about whole gradient streams via runSteps,
and introduce a StepSpec only when its equations come from a separate mathematical description.
A shape-polymorphic per-tensor optimizer.
- State : Spec.Shape → Type
Per-parameter optimizer state for a tensor of shape
s. - init {s : Spec.Shape} : Spec.Tensor α s → self.State s
Initialize optimizer state from the current parameter tensor.
- update {s : Spec.Shape} : self.State s → Spec.Tensor α s → Spec.Tensor α s → self.State s × Spec.Tensor α s
One update from state, parameters, and gradients.
Instances For
Package plain SGD as a TensorOptimizer.
Instances For
Package momentum SGD as a TensorOptimizer.
Instances For
Package AdaGrad as a TensorOptimizer.
Instances For
Package RMSProp as a TensorOptimizer.
Instances For
Package Adam as a TensorOptimizer.
Instances For
Package AdamW as a TensorOptimizer.
Instances For
Package Adadelta as a TensorOptimizer.
Instances For
Package Muon-style orthogonalized momentum as a TensorOptimizer.
Instances For
State/parameter pair threaded by an optimizer for one fixed tensor shape.
Instances For
Run one optimizer step on a state/parameter pair.
Instances For
Run a finite stream of gradients through an optimizer.
Instances For
Splitting a gradient stream and running the two pieces sequentially gives the same state and parameters as running the concatenated stream.
Optimizer state after a finite gradient stream.
Instances For
Optimizer parameters after a finite gradient stream.
Instances For
State projection of runSteps_append.
Parameter projection of runSteps_append.
Generic step specifications #
Proof-facing specification of one optimizer step.
An optimizer-specific file only has to identify the next-state and next-parameter equations once. The generic theorems below then lift that one-step fact to whole finite gradient streams.
- nextState {s : Spec.Shape} : opt.State s → Spec.Tensor α s → Spec.Tensor α s → opt.State s
Spec equation for the next optimizer state.
- nextParams {s : Spec.Shape} : opt.State s → Spec.Tensor α s → Spec.Tensor α s → Spec.Tensor α s
Spec equation for the next parameter tensor.
- update_eq {s : Spec.Shape} (state : opt.State s) (params grads : Spec.Tensor α s) : opt.update state params grads = (self.nextState state params grads, self.nextParams state params grads)
The executable optimizer update agrees with the stated step equations.
Instances For
Run one step through the proof layer equations.
Instances For
Run a finite stream of gradients through the proof layer equations.
Instances For
A registered step spec agrees with the executable optimizer for one step.
A registered one-step optimizer spec agrees with the executable optimizer over any finite gradient stream. This is the general theorem optimizer-specific registrations feed into.
The proof layer equations compose over concatenated gradient streams just like the executable optimizer.
Muon comparison laws #
If a Muon backend returns the fresh momentum buffer unchanged on this step, then the parameter update agrees with momentum SGD for this step.
Initialized version of update_params_eq_momentumSGD_of_apply_eq.