The higher (or smaller) the learning rate, the higher (or, respectively, smaller) the contribution of the gradient of the objective function, with respect to the parameters of the model, to the new parameters of the model. Therefore, if you progressively increase (or decrease) the learning rate, then you will accelerate (or, respectively, slow down) the learning process, so later training examples have higher (or, respectively, smaller) influence on the parameters of the model.
In your example, the function warmup_lr_scheduler
returns an object of class LambdaLR
, initialized with a certain optimizer and the function f
, which is defined as
def f(x):
if x >= warmup_iters:
return 1
alpha = float(x) / warmup_iters
return warmup_factor * (1 - alpha) + alpha
The documentation of torch.optim.lr_scheduler.LambdaLR
says that the function f
should compute a multiplicative factor given an integer parameter epoch, so x
is a training epoch. If the epoch x
is greater than or equal to warmup_iters
, then 1 is returned, but anything multiplied by 1 is itself, so, when the epoch x
is greater than a threshold, warmup_iters
(e.g. 1000), then the initial learning rate is unaffected. However, when x < warmup_iters
, the multiplicative factor is given by
alpha = float(x) / warmup_iters
warmup_factor * (1 - alpha) + alpha
which is a function of the epoch x
. The higher the epoch x
, the higher the value of alpha
, so the smaller (1 - alpha)
and warmup_factor * (1 - alpha)
. Note that float(x) / warmup_iters
will never be greater than 1 because x
is never greater than warmup_iters
. So, effectively, as the epoch increases, warmup_factor * (1 - alpha)
tends to 0 and alpha
tends to 1.
The learning rate can only increase if you multiply it with a constant greater than 1. However, this can only happen if warmup_factor > 1
. You can verify this by solving the inequality warmup_factor * (1 - alpha) + alpha > 1
.
To conclude, the initial learning rate is not being increased, but the learning process starts with a smaller learning rate than the given learning rate, for a warmup_iters
epochs, then, after warmup_iters
epochs, it uses the initially given learning rate (e.g. 0.002).