colossalai.nn.lr_scheduler.cosine
- class colossalai.nn.lr_scheduler.cosine.CosineAnnealingLR(optimizer, total_steps, eta_min=0, last_epoch=- 1, **kwargs)[source]
Set the learning rate of each parameter group using a cosine annealing schedule, where \(\eta_{max}\) is set to the initial lr and \(T_{cur}\) is the number of epochs since the last restart in SGDR:
\[\begin{split}\begin{aligned} \eta_t & = \eta_{min} + \frac{1}{2}(\eta_{max} - \eta_{min})\left(1 + \cos\left(\frac{T_{cur}}{T_{max}}\pi\right)\right), & T_{cur} \neq (2k+1)T_{max}; \\ \eta_{t+1} & = \eta_{t} + \frac{1}{2}(\eta_{max} - \eta_{min}) \left(1 - \cos\left(\frac{1}{T_{max}}\pi\right)\right), & T_{cur} = (2k+1)T_{max}. \end{aligned}\end{split}\]When last_epoch=-1, sets initial lr as lr. Notice that because the schedule is defined recursively, the learning rate can be simultaneously modified outside this scheduler by other operators. If the learning rate is set solely by this scheduler, the learning rate at each step becomes:
\[\eta_t = \eta_{min} + \frac{1}{2}(\eta_{max} - \eta_{min})\left(1 + \cos\left(\frac{T_{cur}}{T_{max}}\pi\right)\right)\]It has been proposed in SGDR: Stochastic Gradient Descent with Warm Restarts. Note that this only implements the cosine annealing part of SGDR, and not the restarts.
- Parameters
optimizer (
torch.optim.Optimizer) – Wrapped optimizer.total_steps (int) – Number of total training steps.
eta_min (int, optional) – Minimum learning rate, defaults to 0.
last_epoch (int, optional) – The index of last epoch, defaults to -1. When last_epoch=-1, the schedule is started from the beginning or When last_epoch=-1, sets initial lr as lr.
- class colossalai.nn.lr_scheduler.cosine.CosineAnnealingWarmupLR(optimizer, total_steps, warmup_steps=0, eta_min=0.0, last_epoch=- 1)[source]
Cosine annealing learning rate scheduler with learning rate warmup. A linear warmup schedule will be applied.
- Parameters
optimizer (
torch.optim.Optimizer) – Wrapped optimizer.total_steps (int) – Number of total training steps.
warmup_steps (int, optional) – Number of warmup steps, defaults to 0.
eta_min (int, optional) – Minimum learning rate, defaults to 0.
last_epoch (int, optional) – The index of last epoch, defaults to -1. When last_epoch=-1, the schedule is started from the beginning or When last_epoch=-1, sets initial lr as lr.
- class colossalai.nn.lr_scheduler.cosine.FlatAnnealingLR(optimizer, total_steps, pct_start=0.72, last_epoch=- 1, **kwargs)[source]
Flat and cosine annealing learning rate scheduler. The learning rate will be a fixed value before starting decay.
- Parameters
optimizer (
torch.optim.Optimizer) – Wrapped optimizer.total_steps (int) – Number of total training steps.
pct_start (float, optional) – Percent of steps before starting learning rate decay, defaults to -0.72.
last_epoch (int, optional) – The index of last epoch, defaults to -1. When last_epoch=-1, the schedule is started from the beginning or When last_epoch=-1, sets initial lr as lr.
- class colossalai.nn.lr_scheduler.cosine.FlatAnnealingWarmupLR(optimizer, total_steps, warmup_steps=0, pct_start=0.72, eta_min=0, last_epoch=- 1, **kwargs)[source]
Flat and cosine annealing learning rate scheduler with learning rate warmup. A linear warmup schedule will be applied, and then the learning rate will be a fixed value before starting decay.
- Parameters
optimizer (
torch.optim.Optimizer) – Wrapped optimizer.total_steps (int) – Number of total training steps.
warmup_steps (int, optional) – Number of warmup steps, defaults to 0.
pct_start (float, optional) – Percent of steps before starting learning rate decay, defaults to -0.72.
eta_min (int, optional) – Minimum learning rate, defaults to 0.
last_epoch (int, optional) – The index of last epoch, defaults to -1. When last_epoch=-1, the schedule is started from the beginning or When last_epoch=-1, sets initial lr as lr.