mindspore.nn.PolynomialDecayLR

class mindspore.nn.PolynomialDecayLR(learning_rate, end_learning_rate, decay_steps, power, update_decay_steps=False)[source]

Calculates learning rate base on polynomial decay function.

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

\[decayed\_learning\_rate[i] = (learning\_rate - end\_learning\_rate) * (1 - tmp\_step / tmp\_decay\_steps)^{power} + end\_learning\_rate\]

Where :

\[tmp\_step=min(current\_step, decay\_steps)\]

If update_decay_steps is true, update the value of tmp_decay_step every decay_steps. The formula is :

\[tmp\_decay\_steps = decay\_steps * ceil(current\_step / decay\_steps)\]
Parameters
  • learning_rate (float) – The initial value of learning rate.

  • end_learning_rate (float) – The end value of learning rate.

  • decay_steps (int) – A value used to calculate decayed learning rate.

  • power (float) – A value used to calculate decayed learning rate. This parameter must be greater than 0.

  • update_decay_steps (bool) – If true, learning rate is decayed once every decay_steps time. Default: False.

Inputs:
  • global_step (Tensor) - The current step number.

Outputs:

Tensor. The learning rate value for the current step with shape \(()\).

Raises
  • TypeError – If learning_rate, end_learning_rate or power is not a float.

  • TypeError – If decay_steps is not an int or update_decay_steps is not a bool.

  • ValueError – If end_learning_rate is less than 0 or decay_steps is less than 1.

  • ValueError – If learning_rate or power is less than or equal to 0.

Supported Platforms:

Ascend GPU

Examples

>>> learning_rate = 0.1
>>> end_learning_rate = 0.01
>>> decay_steps = 4
>>> power = 0.5
>>> global_step = Tensor(2, mstype.int32)
>>> polynomial_decay_lr = nn.PolynomialDecayLR(learning_rate, end_learning_rate, decay_steps, power)
>>> result = polynomial_decay_lr(global_step)
>>> print(result)
0.07363961