Pytorch 闪电学习率调节器给出意想不到的结果

问题描述 投票:0回答:0

我正在尝试使用

python pl.tuner.Tuner
找到最佳学习率,但结果并不符合预期

我运行的模型是 BertForSequenceClassification Automodel 之上的线性分类器

我想找到bert模型冻结时的最佳学习率。

为此,我正在运行以下代码:

  
    tuner = pl.tuner.Tuner(trainer)
    results = tuner.lr_find(
        model, 
        # optimizer = optimizer,
        
        train_dataloaders=data_module, 
        min_lr=10e-8,
        max_lr=10.0,
    )
    # Plot with
    fig = results.plot(suggest=True)
    fig.show()

我的优化器在模型中的配置如下:

   def configure_optimizers(self):
        """
        :return:
        """
        optimizer = torch.optim.AdamW(self.parameters(), lr=self.learning_rate)

        scheduler = get_linear_schedule_with_warmup(
            optimizer,
            num_warmup_steps=self.n_warmup_steps,
            num_training_steps=self.n_training_steps,
        )
        return dict(optimizer=optimizer, lr_scheduler=dict(scheduler=scheduler, interval="step"))

这会产生:

Chart of loss against learning rate

我很困惑为什么损失会在较低的学习率下增加,这不是我所期望的。

我已经尝试过:

  • 删除调度程序
  • 冻结/解冻权重
  • 更改初始学习率

我期待这样的图表:https://github.com/comhar/pytorch-learning-rate-tuner/blob/master/images/learning_rate_tuner_plot.png

任何帮助表示赞赏

非常感谢

deep-learning pytorch-lightning learning-rate
© www.soinside.com 2019 - 2024. All rights reserved.