赞
踩
lr_scheduler在深度学习模型中经常遇到,虽粗通其理,然未解其中奥秘。
简单整理,冀假以时日,略加参悟。
代码参考自https://github.com/huggingface/transformers/blob/main/src/transformers/optimization.py
的get_linear_schedule_with_warmup
部分。
import matplotlib.pyplot as plt
t_total = 10000
warmup_steps = 1000
lr = 1e-4
def lr_lambda(step):
if step < warmup_steps:
return float(step) / float(max(1, warmup_steps))
return max(0.0, float(t_total - step) / float(
max(1.0, t_total - warmup_steps)))
lrs = []
for step in range(t_total):
lrs.append(lr*lr_lambda(step))
plt.plot(lrs)
plt.show()
[1]https://github.com/huggingface/transformers/blob/main/src/transformers/optimization.py
[2] pytorch how-to-adjust-learning-rate
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。