ηt=ηmin+21(ηmax−ηmin)(1+cos(TmaxTcurπ))
ηt is the learning rate at step t
Tcur is the number of epochs since the last restart
Tmax is the maximum number of epochs in a cycle
- Parameters:
optimizer (Optimizer) – Wrapped optimizer.
T_max (int) – Maximum number of iterations.
eta_min (float) – Minimum learning rate. Default: 0.
last_epoch (int) – The index of the last epoch. Default: -1.
Example
num_epochs = 100
scheduler = CosineAnnealingLR(optimizer, T_max=num_epochs)
for epoch in range(num_epochs):
train(...)
validate(...)
scheduler.step()
-
get_last_lr()
Get the most recent learning rates computed by this scheduler.
- Returns:
A list of learning rates with entries
for each of the optimizer’s
param_groups, with the same types as
their group["lr"]s.
- Return type:
list[float | Tensor]
-
get_lr()
Compute the next learning rate for each of the optimizer’s
param_groups.
Scales the group["lr"]s in the optimizer’s
param_groups such that their learning
rates approximate
eta_min+21(base_lr−eta_min)(1+cos(π⋅T_maxlast_epoch))
- Returns:
A list of learning rates for each of
the optimizer’s param_groups with the
same types as their current group["lr"]s.
- Return type:
list[float | Tensor]
-
load_state_dict(state_dict)
Load the scheduler’s state.
- Parameters:
state_dict (dict) – scheduler state. Should be an object returned
from a call to state_dict().
-
state_dict()
Return the state of the scheduler as a dict.
It contains an entry for every variable in self.__dict__ which
is not the optimizer.
- Return type:
dict[str, Any]
-
step(epoch=None)
Step the scheduler.
- Parameters:
epoch (int, optional) –