linear_lr_warmup

paddle.fluid.layers. linear_lr_warmup ( learning_rate, warmup_steps, start_lr, end_lr ) [源代码]

该OP使用学习率优化策略-线性学习率热身(warm up)对学习率进行初步调整。在正常调整学习率之前,先逐步增大学习率,具体原理可参考: Bag of Tricks for Image Classification with Convolutional Neural Networks

当训练步数(global_step)小于热身步数(warmup_steps)时,学习率lr按如下方式更新:

  1. linear_step = end_lr - start_lr
  2. lr = start_lr + linear_step * (global_step / warmup_steps)

其中start_lr为warm up起始学习率,end_lr为最终学习率;

当训练步数(global_step)大于等于热身步数(warmup_steps)时,学习率lr为:

  1. lr = learning_rate

其中learning_rate为热身之后的学习率。

参数:

  • learning_rate (Variable|float) - 热身之后的学习率,它可以是数据类型为float32的1D-Tensor或单个浮点数。

  • warmup_steps (int) - 进行warm up过程的步数。

  • start_lr (float) - warm up的起始学习率。

  • end_lr (float) - warm up的最终学习率。

返回:进行热身衰减后的学习率,数据类型与learning_rate相同。

返回类型:Variable

示例代码

  1. import paddle.fluid as fluid
  2. boundaries = [100, 200]
  3. lr_steps = [0.1, 0.01, 0.001]
  4. learning_rate = fluid.layers.piecewise_decay(boundaries, lr_steps) #case1, Tensor
  5. #learning_rate = 0.1 #case2, float32
  6. warmup_steps = 50
  7. start_lr = 1. / 3.
  8. end_lr = 0.1
  9. decayed_lr = fluid.layers.linear_lr_warmup(learning_rate,
  10. warmup_steps, start_lr, end_lr)
  11. place = fluid.CPUPlace()
  12. exe = fluid.Executor(place)
  13. exe.run(fluid.default_startup_program())
  14. out, = exe.run(fetch_list=[decayed_lr.name])
  15. print(out)
  16. # case1: [0.33333334]
  17. # case2: [0.33333334]