schedulers
Learning-rate schedules with a linear warm-up, complementing torch.optim.lr_scheduler.
The schedules count in steps: call scheduler.step() once per epoch for an epoch-based schedule and once per iteration for an iteration-based one; total_steps and warmup_steps are in the same unit.
Classes:
-
CosineWarmupLRβCosine decay with linear warm-up (one cycle).
-
PolyLRβPolynomial decay with linear warm-up (one cycle).
CosineWarmupLR [source] ΒΆ
CosineWarmupLR(
optimizer: Optimizer,
total_steps: int,
*,
warmup_steps: int = 0,
warmup_lr_init: float = 0.0,
lr_min: float = 0.0,
warmup_prefix: bool = False,
last_epoch: int = -1,
)
Bases: _WarmupSchedule
Cosine decay with linear warm-up (one cycle).
after a linear warm-up from warmup_lr_init over warmup_steps. With warmup_prefix=False (the default), \(t\) counts from step \(0\) and \(T\) is total_steps, so the warm-up takes its steps from the cosine; with warmup_prefix=True, \(t\) and \(T\) count from the end of the warm-up.
Parameters:
-
optimizer(Optimizer) βWrapped optimizer.
-
total_steps(int) βLength of the schedule in steps (epochs or iterations, whichever
step()counts). -
warmup_steps(int, default:0) βLength of the linear warm-up.
-
warmup_lr_init(float, default:0.0) βLearning rate at step \(0\) of the warm-up.
-
lr_min(float, default:0.0) βFinal (and post-schedule) learning rate.
-
warmup_prefix(bool, default:False) βCount the cosine from the end of the warm-up instead of from step \(0\).
-
last_epoch(int, default:-1) βThe index of the last step, for resuming.
Example
import torch
from torch_pointcloud.optim import CosineWarmupLR
opt = torch.optim.SGD([torch.zeros(1, requires_grad=True)], lr=1.0)
sched = CosineWarmupLR(opt, total_steps=10, warmup_steps=2, lr_min=0.0)
lrs = []
for _ in range(10):
opt.step()
sched.step()
lrs.append(round(sched.get_last_lr()[0], 3))
lrs # [0.5, 0.905, 0.794, 0.655, 0.5, 0.345, 0.206, 0.095, 0.024, 0.0]
PolyLR [source] ΒΆ
PolyLR(
optimizer: Optimizer,
total_steps: int,
*,
power: float = 0.9,
warmup_steps: int = 0,
warmup_lr_init: float = 0.0,
lr_min: float = 0.0,
warmup_prefix: bool = False,
last_epoch: int = -1,
)
Bases: _WarmupSchedule
Polynomial decay with linear warm-up (one cycle).
after the warm-up; see CosineWarmupLR for how \(t\) and \(T\) are counted. The decay reaches lr_min at step total_steps; to keep a non-zero rate on the last of \(n\) steps, pass total_steps=n + 1.
Parameters:
-
optimizer(Optimizer) βWrapped optimizer.
-
total_steps(int) βLength of the schedule in steps.
-
power(float, default:0.9) βExponent \(p\) of the decay.
-
warmup_steps(int, default:0) βLength of the linear warm-up.
-
warmup_lr_init(float, default:0.0) βLearning rate at step \(0\) of the warm-up.
-
lr_min(float, default:0.0) βFinal (and post-schedule) learning rate.
-
warmup_prefix(bool, default:False) βCount the decay from the end of the warm-up instead of from step \(0\).
-
last_epoch(int, default:-1) βThe index of the last step, for resuming.