mojolearn.StepLR#
- class mojolearn.StepLR(base_lr, step_size, gamma=0.1)[source]#
Bases:
_PowSchedStep-decay learning-rate schedule: multiply by
gammaeverystep_sizesteps.Computes torch’s
StepLRclosed form,lr = base_lr * gamma ** (epoch // step_size), as a function of the step index.lr_at(t)takes the one-based optimizer step:lr_at(1)is the rate before the firstscheduler.step()in torch, andlr_at(t)the rate aftert - 1steps. Each value is the exact closed form rounded once to float32 (ties to even, values below the smallest normal flushed to +0.0), so a schedule gives the same bits on every machine.Pass a schedule as
lr_schedule=to the optimizersRMSprop,Adagrad,Lion,AdamaxandNAdam, and to the recurrent estimators (LSTMClassifier,GRURegressor, …); they setlr = schedule.lr_at(t)before step t.- Parameters:
base_lr (float) – Learning rate of the first step. Must be finite.
step_size (int) – Number of steps between decays. Must be >= 1, otherwise
ValueError.gamma (float, default 0.1) – Multiplicative decay factor. Must be finite.
Notes
lr_at(t)raisesValueErrorfort < 1andOverflowErrorwhen the value overflows float32. Per-group learning rates andlast_epochresumption are not supported: to resume, evaluatelr_atat the step you resume from.Examples
>>> import mojolearn >>> sched = mojolearn.StepLR(0.1, step_size=30, gamma=0.1) >>> first, after_30 = sched.lr_at(1), sched.lr_at(31)
Methods
bits_at(t)lr_at(t)lr_values(n)lr_at(1) .
lrs(n)lr_at(1) .