mindspore.nn.warmup_lr

mindspore.nn.warmup_lr(learning_rate, total_step, step_per_epoch, warmup_epoch)[source]

Get learning rate warming up.

For the i-th step, the formula of computing warmup_learning_rate[i] is:

\[warmup\_learning\_rate[i] = learning\_rate * tmp\_epoch / tmp\_warmup\_epoch\]

Where \(tmp\_epoch=min(current\_epoch, warmup\_epoch),\ current\_epoch=floor(\frac{i}{step\_per\_epoch})\)

Parameters
  • learning_rate (float) – The initial value of learning rate.

  • total_step (int) – The total number of steps.

  • step_per_epoch (int) – The number of steps in per epoch.

  • warmup_epoch (int) – A value that determines the epochs of the learning rate is warmed up.

Returns

list[float]. The size of list is total_step.

Examples

>>> learning_rate = 0.1
>>> total_step = 6
>>> step_per_epoch = 2
>>> warmup_epoch = 2
>>> output = warmup_lr(learning_rate, total_step, step_per_epoch, warmup_epoch)
>>> print(output)
[0.0, 0.0, 0.05, 0.05, 0.1, 0.1]