我正在尝试使用
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"))
这会产生:
我很困惑为什么损失会在较低的学习率下增加,这不是我所期望的。
我已经尝试过:
任何帮助表示赞赏
非常感谢