struct Optimizer {
struct Vec<&FloatTensor> params;
struct Vec<&FloatTensor> m;
struct Vec<&FloatTensor> v;
int kind;
float lr;
float momentum;
float beta1;
float beta2;
float eps;
float weightDecay;
unsigned long t;
}Fields are public: change lr (a schedule), betas or weight decay between steps. State buffers are created when a parameter is added, always on the heap even inside a tensor arena.
Fields
first moment / velocity, one per parameter
second moment, one per parameter
L2 for SGD / momentum / RMSProp / Adagrad / Adam, decoupled for AdamW / Lion
steps taken
Methods
Scales every gradient so their global L2 norm is at most maxNorm and returns the norm before scaling.
frees the state, not the parameters
= drop()
An empty optimizer with o's kind and hyperparameters (not its parameters or state).