AI Logic

Learning Rate Schedulers

Polynomial Decay (poly)

Updated:

Learning rate graphs for polynomial decay. The vertical axis is the ratio to the initial learning rate and the horizontal axis is training progress. The left panel shows curves for powers p = 0.5, 0.9, 1 and 2: the smaller p is below 1, the longer the learning rate stays high before dropping sharply near the end. The right panel shows DeepLab's comparison setting (6K iterations), with step decay multiplying the rate by 0.1 every 2000 iterations alongside poly with p = 0.9

What is polynomial decay (poly)?

Polynomial decay (poly) is a learning rate scheduler that multiplies the learning rate by (1−t/T)p(1 - t/T)^{p}, lowering it smoothly in polynomial form so that it reaches exactly 0 at the end of training (t=Tt = T). Here tt is the current iteration, TT is the total number of iterations and pp is the power. Only the total number of iterations and the power need to be chosen; unlike step decay, there is no need to list when to decay.

It was not proposed in a specific paper; it was one of the learning rate policies built into the deep learning framework Caffe under the name poly. The semantic segmentation model ParseNet (Liu et al., 2015) used it with power p=0.9p = 0.9 and reported results about 1.5% better than step decay with the same number of iterations. DeepLab (Chen et al., 2016) followed suit; because poly gave a mean IoU 1.17% higher than step decay on PASCAL VOC 2012, it used poly in all subsequent experiments.

With power p=1p = 1, the learning rate decreases linearly toward 0, which is "linear decay". Poly can be seen as linear decay whose curvature is adjustable through the power.

Theory (how the learning rate is set)

The poly procedure is as follows.

  1. Choose the initial learning rate η0\eta_0.
  2. Choose the total number of iterations TT. The learning rate reaches 0 at TT, so set it to the number of iterations at which training ends.
  3. Choose the power pp. ParseNet and DeepLab use p=0.9p = 0.9.
  4. At every iteration, compute the learning rate with the following formula.
ηt=η0(1−tT)p\eta_t = \eta_0 \left(1 - \frac{t}{T}\right)^{p}

Caffe's poly and PyTorch's PolynomialLR follow this formula exactly and end at 0. TensorFlow (Keras) PolynomialDecay lets the final learning rate ηend\eta_{\mathrm{end}} be specified and lowers the rate from η0\eta_0 to ηend\eta_{\mathrm{end}} with the following formula (defaults are ηend=0.0001\eta_{\mathrm{end}} = 0.0001 and p=1p = 1).

ηt=(η0−ηend)(1−min⁡(t,T)T)p+ηend\eta_t = (\eta_0 - \eta_{\mathrm{end}}) \left(1 - \frac{\min(t, T)}{T}\right)^{p} + \eta_{\mathrm{end}}

Changing the power pp changes the shape of the curve as follows (left of the figure at the top).

Power ppShapeLearning rate halfway through training (t=T/2t = T/2)
0.5Concave down, dropping sharply near the endAbout 0.71 times η0\eta_0
0.9Slightly above a straight lineAbout 0.54 times η0\eta_0
1Straight line (linear decay)0.5 times η0\eta_0
2Concave up, dropping quickly at first0.25 times η0\eta_0

Why does it work?

The defining feature of poly is that it never drops the learning rate abruptly midway, but brings it gradually toward 0 by the end of training.

With step decay, the learning rate changes all at once, for example when it is cut to 1/10. If the cut comes too early, the rest of training runs with a small learning rate. Poly changes the rate only slightly at each iteration, and it keeps decreasing little by little until the very end. As shown on the right of the figure at the top, in DeepLab's comparison setting (6K iterations, with step decay multiplying the rate by 0.1 every 2000 iterations), step decay is already at 1/10 of the initial value at iteration 2000, while poly still keeps about half the initial learning rate in the middle of training.

The power pp determines when most of the decrease happens. Differentiating ηt\eta_t with respect to tt gives a slope of −p η0T(1−tT)p−1-\dfrac{p\,\eta_0}{T}\left(1 - \dfrac{t}{T}\right)^{p-1}. For p<1p < 1, (1−t/T)p−1(1 - t/T)^{p-1} grows as the end approaches, so the shape keeps the learning rate high in the first half and drops it sharply near the end. p=0.9p = 0.9 is quite close to a straight line, with the decrease speeding up a little before the end.

As an analogy, step decay is like driving and shifting down one gear at fixed points, while poly is like gradually easing off the accelerator toward the stopping point. If the stopping point (the total number of iterations) is known, there is no need to decide when to shift down along the way.

Experimental results

The DeepLab paper trained DeepLab-LargeFOV (a model based on VGG-16) on PASCAL VOC 2012 and compared learning rate policies (Table 2, mean IoU on the validation set before applying the CRF). The step decay setting multiplies the learning rate by 0.1 every 2000 iterations.

Learning rate policyBatch sizeIterationsMean IoU (%)
Step decay306K62.25
poly (p=0.9p = 0.9)306K63.42
poly (p=0.9p = 0.9)3010K64.90
poly (p=0.9p = 0.9)1010K64.71
poly (p=0.9p = 0.9)1020K65.88

With the same batch size and number of iterations, poly scored 1.17 points higher than step decay. The last row reduces the batch size and increases the number of iterations so that training time is about the same as for step decay; it scores 3.63 points higher than step decay.

The ParseNet paper likewise reports that, in experiments reproducing FCN-32s on PASCAL-Context, poly with p=0.9p = 0.9 converged faster than step decay and gave results about 1.5% better at the same 80k iterations.

Both results are for semantic segmentation. Poly is not guaranteed to always beat step decay on other tasks.

Practical considerations

The default value of total_iters in PyTorch's PolynomialLR is 5. If it is not set, the learning rate becomes 0 at the 5th call to scheduler.step() and stays at 0 afterward, so training makes no progress. Set total_iters to the total number of step() calls (the total number of iterations if it is called every iteration).

When the training length changes, change the total number of iterations to match. If TT is shorter than the actual training, the learning rate hits 0 partway and training stops. If TT is too long, training ends before the learning rate has decreased enough.

Keep the following points in mind as well.

  • To avoid ending at 0, use a form that lets the final learning rate be specified: TensorFlow (Keras) PolynomialDecay accepts end_learning_rate (default 0.0001). PyTorch's PolynomialLR always ends at 0, so to stop at a value above 0, write the formula with LambdaLR.
  • Update every iteration: the formulas in ParseNet and DeepLab are written in terms of the iteration count iter. Updating every epoch gives the same shape but is less smooth.
  • When starting from a large learning rate, combine it with warmup: poly uses its largest learning rate at the start of training, so if training is unstable, add a phase that ramps up the learning rate over the first few hundred to few thousand steps.

Comparison with other learning rate schedulers

The table compares poly with the schedulers it is often compared with, from the same viewpoints.

SchedulerHow the learning rate decreasesWhat must be set in advanceTypical use
Step decayIn steps at chosen timesWhen to decay and by what factorReproducing tasks with established settings
Polynomial decay (poly)Polynomially toward 0Total steps and the powerSemantic segmentation and similar tasks
Cosine annealingSmoothly along a cosine curveTotal steps, maximum and minimumMany tasks with a fixed total number of steps
One CycleRaised once, then lowered sharplyTotal steps and maximumWhen fast convergence in short training is the goal
WSDHeld constant, then lowered in a short final phaseWhen to start decayingPretraining large language models and similar

Poly and cosine annealing have in common that both decay smoothly with only the total number of steps fixed. They differ in the shape of the curve: cosine annealing is gentle at the start and end and fast in the middle, while poly with p=0.9p = 0.9 decreases almost linearly.

Some rules of thumb for choosing:

  • To reproduce results from papers that use poly, such as DeepLab, use poly: match p=0.9p = 0.9 and the total number of iterations to the paper.
  • When choosing a new setup, either poly or cosine annealing is a fine starting point: they require almost the same settings, and neither is always better.
  • If the training length is not fixed or may be extended midway, consider WSD: poly keeps decreasing from the start according to the total number of steps, which makes it hard to extend training later.

PyTorch example

Show code
python
import torch
import torch.nn as nn

model = nn.Sequential(nn.Conv2d(3, 16, 3, padding=1), nn.ReLU(), nn.Conv2d(16, 21, 1))  # 21-class segmentation (dummy)
criterion = nn.CrossEntropyLoss(ignore_index=255)
optimizer = torch.optim.SGD(model.parameters(), lr=0.001, momentum=0.9, weight_decay=0.0005)

max_iter = 20000
# η_t = η_0 · (1 − t / total_iters)^power. total_iters defaults to 5, so always set it
# total_iters counts scheduler.step() calls -> call step() every iteration
scheduler = torch.optim.lr_scheduler.PolynomialLR(optimizer, total_iters=max_iter, power=0.9)

model.train()
for it in range(max_iter):
    images = torch.randn(10, 3, 64, 64)
    labels = torch.randint(0, 21, (10, 64, 64))
    optimizer.zero_grad()
    loss = criterion(model(images), labels)
    loss.backward()
    optimizer.step()
    scheduler.step()                              # Call once per mini-batch
    if it in (0, max_iter // 2, max_iter - 1):
        print(it, scheduler.get_last_lr())        # About 0.00054 halfway; approaches 0 at the end


# To stop at end_lr instead of 0 (same formula as TensorFlow's PolynomialDecay), write it with LambdaLR
base_lr, end_lr, power = 0.001, 1e-5, 0.9
optimizer2 = torch.optim.SGD(model.parameters(), lr=base_lr, momentum=0.9)
poly_with_end = torch.optim.lr_scheduler.LambdaLR(
    optimizer2,
    lambda t: ((base_lr - end_lr) * (1 - min(t, max_iter) / max_iter) ** power + end_lr) / base_lr,
)

FAQ

Q. What value should the power p take?
A.

ParseNet and DeepLab use 0.9, and this value is common in segmentation. The default in PyTorch's PolynomialLR and TensorFlow's PolynomialDecay is 1 (linear decrease). The best value depends on the task, so starting with 0.9 or 1 is easy.

Q. What is the difference between poly and linear decay?
A.

Linear decay is poly with a power of 1. By changing the power, poly can either keep the learning rate high in the first half (power below 1) or lower it earlier (power above 1).

Q. Which is better, poly or cosine annealing?
A.

Both decay smoothly once the total number of steps is set, and they require almost the same settings. Neither is always better. To reproduce a paper's setup in segmentation, use poly; when choosing anew for other tasks, either can be tried first.

References

  1. W. Liu, A. Rabinovich, and A. C. Berg, "ParseNet: Looking Wider to See Better," arXiv:1506.04579, 2015.
  2. L.-C. Chen, G. Papandreou, I. Kokkinos, K. Murphy, and A. L. Yuille, "DeepLab: Semantic Image Segmentation with Deep Convolutional Nets, Atrous Convolution, and Fully Connected CRFs," IEEE TPAMI, 2018 (arXiv:1606.00915).
  3. PyTorch Documentation, "PolynomialLR."
  4. TensorFlow Documentation, "tf.keras.optimizers.schedules.PolynomialDecay."
  5. Caffe, src/caffe/solvers/sgd_solver.cpp (definition of the poly learning rate policy).