mindspore.nn.PolynomialDecayLR

View Source On Gitee
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 current step, the formula of computing decayed learning rate is:

decayed_learning_rate=(learning_rateend_learning_rate)(1tmp_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_steps every decay_steps. The formula is :

tmp_decay_steps=decay_stepsceil(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) – Number of steps to decay over.

  • power (float) – The power of polynomial. It 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. Shape is ().

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

>>> import mindspore
>>> from mindspore import Tensor, nn
>>>
>>> learning_rate = 0.1
>>> end_learning_rate = 0.01
>>> decay_steps = 4
>>> power = 0.5
>>> global_step = Tensor(2, mindspore.int32)
>>> polynomial_decay_lr = nn.PolynomialDecayLR(learning_rate, end_learning_rate, decay_steps, power)
>>> lr = polynomial_decay_lr(global_step)
>>> net = nn.Dense(2, 3)
>>> optim = nn.SGD(net.trainable_params(), learning_rate=lr)