chemprop.schedulers
#
Module Contents#
Classes#
A Noam learning rate scheduler schedules the learning rate with a piecewise linear followed |
- class chemprop.schedulers.NoamLR(optimizer, warmup_epochs, total_epochs, steps_per_epoch, init_lrs, max_lrs, final_lrs)[source]#
Bases:
torch.optim.lr_scheduler.LRScheduler
A Noam learning rate scheduler schedules the learning rate with a piecewise linear followed by an exponential decay.
The learning rate increases linearly from
init_lr
tomax_lr
over the course of the first warmup_steps then decreases exponentially tofinal_lr
over the course of the remainingtotal_steps - warmup_steps
(wheretotal_steps = total_epochs * steps_per_epoch
). This is roughly based on the learning rate schedule from [1], section 5.3.Formally, the learning rate schedule is defined as:
\[\begin{split}\mathtt{lr}(i) &= \begin{cases} \mathtt{init\_lr} + \delta \cdot i &\text{if } i < \mathtt{warmup\_steps} \\ \mathtt{max\_lr} \cdot \left( \frac{\mathtt{final\_lr}}{\mathtt{max\_lr}} \right)^{\gamma(i)} &\text{otherwise} \\ \end{cases} \\ \delta &\mathrel{:=} \frac{\mathtt{max\_lr} - \mathtt{init\_lr}}{\mathtt{warmup\_steps}} \\ \gamma(i) &\mathrel{:=} \frac{i - \mathtt{warmup\_steps}}{\mathtt{total\_steps} - \mathtt{warmup\_steps}}\end{split}\]- Parameters:
optimizer (Optimizer) – A PyTorch optimizer.
warmup_epochs (ArrayLike) – The number of epochs during which to linearly increase the learning rate.
total_epochs (int) – The total number of epochs.
steps_per_epoch (int) – The number of steps (batches) per epoch.
init_lr (ArrayLike) – The initial learning rate.
max_lr (ArrayLike) – The maximum learning rate (achieved after
warmup_epochs
).final_lr (ArrayLike) – The final learning rate (achieved after
total_epochs
).init_lrs (numpy.typing.ArrayLike)
max_lrs (numpy.typing.ArrayLike)
final_lrs (numpy.typing.ArrayLike)
References