WarmupLinearSchedule为什么先升后降

#num_train_optimization_steps = int(len(train_data) / args.train_batch_size / args.gradient_accumulation_steps) * args.num_train_epochs

class WarmupLinearSchedule(_LRSchedule):
    """
    Linearly increases learning rate from 0 to 1 over `warmup` fraction of training steps.
    Linearly decreases learning rate from 1. to 0. over remaining `1 - warmup` steps.
    """
    warn_t_total = True

    def get_lr_(self, progress):
    	# progerss从0开始
        if progress < self.warmup:
            return progress / self.warmup
        return max((progress - 1.) / (self.warmup - 1.), 0.)

设self.warmup=0.3,表示前30%的epoch学习率逐步上升,后70%逐步下降。
progress=0.1时, progress / self.warmup=1/3
progress=0.2时, progress / self.warmup=2/3
progress=0.3时, progress / self.warmup=3/3
progress=0.4时, (progress - 1.) / (self.warmup - 1.)=6/7
progress=0.5时, (progress - 1.) / (self.warmup - 1.)=5/7
progress=0.6时, (progress - 1.) / (self.warmup - 1.)=4/7
progress=0.7时, (progress - 1.) / (self.warmup - 1.)=3/7
progress=0.8时, (progress - 1.) / (self.warmup - 1.)=2/7
progress=0.9时, (progress - 1.) / (self.warmup - 1.)=1/7
progress / self.warmup(progress - 1.) / (self.warmup - 1.)相当于控制学习率增长的一个系数。

# 在BertAdam中,group['schedule'].get_lr(state['step'])就会调用WarmupLinearSchedule函数,前提是使用线性的Schedule
lr_scheduled = group['lr']
lr_scheduled *= group['schedule'].get_lr(state['step'])
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值