[深度学习] 深度学习优化器选择学习笔记

2024-09-09

本文主要展示各类深度学习优化器Optimizer的效果。所有结果基于pytorch实现,参考github项目pytorch-optimizer(仓库地址)的结果。pytorch-optimizer基于pytorch实现了常用的optimizer,非常推荐使用并加星该仓库。

pytorch-optimizer中所实现的optimizer及其文章主要如下所示。关于optimizer的优化研究非常多,但是不同任务,不同数据集所使用的optimizer效果都不一样,看看研究结果就行了。

optimizerpaper
A2GradExphttps://arxiv.org/abs/1810.00553
A2GradInchttps://arxiv.org/abs/1810.00553
A2GradUnihttps://arxiv.org/abs/1810.00553
AccSGDhttps://arxiv.org/abs/1803.05591
AdaBeliefhttps://arxiv.org/abs/2010.07468
AdaBoundhttps://arxiv.org/abs/1902.09843
AdaModhttps://arxiv.org/abs/1910.12249
Adafactorhttps://arxiv.org/abs/1804.04235
AdamPhttps://arxiv.org/abs/2006.08217
AggMohttps://arxiv.org/abs/1804.00325
Apollohttps://arxiv.org/abs/2009.13586
DiffGradhttps://arxiv.org/abs/1909.11015
Lambhttps://arxiv.org/abs/1904.00962
Lookaheadhttps://arxiv.org/abs/1907.08610
NovoGradhttps://arxiv.org/abs/1905.11286
PIDhttps://www4.comp.polyu.edu.hk/~cslzhang/paper/CVPR18_PID.pdf
QHAdamhttps://arxiv.org/abs/1810.06801
QHMhttps://arxiv.org/abs/1810.06801
RAdamhttps://arxiv.org/abs/1908.03265
Rangerhttps://arxiv.org/abs/1908.00700v2
RangerQHhttps://arxiv.org/abs/1908.00700v2
RangerVAhttps://arxiv.org/abs/1908.00700v2
SGDPhttps://arxiv.org/abs/2006.08217
SGDWhttps://arxiv.org/abs/1608.03983
SWATShttps://arxiv.org/abs/1712.07628
Shampoohttps://arxiv.org/abs/1802.09568
Yogihttps://papers.nips.cc/paper/8186-adaptive-methods-for-nonconvex-optimization

为了评估不同optimizer的效果,pytorch-optimizer使用可视化方法来评估optimizer。可视化帮助我们了解不同的算法如何处理简单的情况,例如:鞍点,局部极小值,最低值等,并可能为算法的内部工作提供有趣的见解。pytorch-optimizer选择了Rosenbrock和Rastrigin 函数来进行可视化。具体如下:

  1. Rosenbrock(也称为香蕉函数)是具有一个全局最小值(1.0,1.0)的非凸函数。整体最小值位于一个细长的,抛物线形的平坦山谷内。寻找山谷是微不足道的。但是,要收敛到全局最小值(1.0,1.0)是很困难的。优化算法可能会陷入局部最小值。

Rosenbrock

  1. Rastrigin函数是非凸函数,并且在(0.0,0.0)中具有一个全局最小值。由于此函数的搜索空间很大且局部最小值很大,因此找到该函数的最小值是一个相当困难的工作。

Rastrigin

下面分别显示不同年份算法在Rastrigin和Rosenbrock函数下的结果,结果显示为Rastrigin和Rosenbroc从上往下的投影图,其中绿色点表示最优点,结果坐标越接近绿色点表示optimizer效果越好。个人觉得效果较好的方法会在方法标题后加*。

Paper: Optimal Adaptive and Accelerated Stochastic Gradient Descent (2018)

rastriginrosenbrock

Paper: Optimal Adaptive and Accelerated Stochastic Gradient Descent (2018)

rastriginrosenbrock

Paper: Optimal Adaptive and Accelerated Stochastic Gradient Descent (2018)

rastriginrosenbrock

Paper: On the insufficiency of existing momentum schemes for Stochastic Optimization (2019)

rastriginrosenbrock

Paper: AdaBelief Optimizer, adapting stepsizes by the belief in observed gradients (2020)

rastriginrosenbrock

Paper: An Adaptive and Momental Bound Method for Stochastic Learning. (2019)

rastriginrosenbrock

Paper: An Adaptive and Momental Bound Method for Stochastic Learning. (2019)

rastriginrosenbrock

Paper: Adafactor: Adaptive Learning Rates with Sublinear Memory Cost. (2018)

rastriginrosenbrock

Paper: Slowing Down the Weight Norm Increase in Momentum-based Optimizers. (2020)

rastriginrosenbrock

Paper: Aggregated Momentum: Stability Through Passive Damping. (2019)

rastriginrosenbrock

Paper: Apollo: An Adaptive Parameter-wise Diagonal Quasi-Newton Method for Nonconvex Stochastic Optimization. (2020)

rastriginrosenbrock

Paper: diffGrad: An Optimization Method for Convolutional Neural Networks. (2019)

Reference Code: https://github.com/shivram1987/diffGrad

rastriginrosenbrock

Paper: Large Batch Optimization for Deep Learning: Training BERT in 76 minutes (2019)

rastriginrosenbrock

Paper: Lookahead Optimizer: k steps forward, 1 step back (2019)

Reference Code: https://github.com/alphadl/lookahead.pytorch

非常需要注意的是Lookahead严格来说不算一种优化器,Lookahead需要一种其他优化器搭配工作,这里Lookahead搭配Yogi进行优化

rastriginrosenbrock

Paper: Stochastic Gradient Methods with Layer-wise Adaptive Moments for Training of Deep Networks (2019)

rastriginrosenbrock

Paper: A PID Controller Approach for Stochastic Optimization of Deep Networks (2018)

rastriginrosenbrock

Paper: Quasi-hyperbolic momentum and Adam for deep learning (2019)

rastriginrosenbrock

Paper: Quasi-hyperbolic momentum and Adam for deep learning (2019)

rastriginrosenbrock

Paper: On the Variance of the Adaptive Learning Rate and Beyond (2019)

Reference Code: https://github.com/LiyuanLucasLiu/RAdam

rastriginrosenbrock

Paper: Calibrating the Adaptive Learning Rate to Improve Convergence of ADAM (2019)

rastriginrosenbrock

Paper: Calibrating the Adaptive Learning Rate to Improve Convergence of ADAM (2019)

rastriginrosenbrock

Paper: Calibrating the Adaptive Learning Rate to Improve Convergence of ADAM (2019)

rastriginrosenbrock

Paper: Slowing Down the Weight Norm Increase in Momentum-based Optimizers. (2020)

rastriginrosenbrock

Paper: SGDR: Stochastic Gradient Descent with Warm Restarts (2017)

rastriginrosenbrock

Paper: Improving Generalization Performance by Switching from Adam to SGD (2017)

rastriginrosenbrock

Paper: Shampoo: Preconditioned Stochastic Tensor Optimization (2018)

rastriginrosenbrock

Paper: Adaptive Methods for Nonconvex Optimization (2018)

Reference Code: https://github.com/4rtemi5/Yogi-Optimizer_Keras

rastriginrosenbrock

pytorch自带

rastriginrosenbrock

pytorch自带

rastriginrosenbrock

看了第2节的结果,DiffGrad,Lookahead,RAdam,Yogi的结果应该还算不错。但是这种可视化结果并不完全正确,一方面训练的epoch太少,另外一方面数据不同以及学习率不同,结果也会大大不同。所以选择合适的优化器在实际调参中还是要具体应用。比如在这个可视化结果中,SGD和Adam效果一般,但是实际上SGD和Adam是广泛验证的优化器,各个任务都能获得不错的结果。SGD是著名的大后期选手,Adam无脑调参最优算法。RAdam很不错,但是并没有那么强,具体RAdam的评价见如何看待最新提出的Rectified Adam (RAdam)?。DiffGrad和Yogi某些任务不错,在某些任务可能效果更差,实际选择需要多次评估。Lookahead是Adam作者和Hinton联合推出的训练优化器,Lookahead可以配合多种优化器,好用是好用,可能没效果,但是一般都会有点提升,实际用Lookahead还是挺不错的。

结合可视化结果,实际下调参,先试试不同的学习率,然后再选择不同的优化器,如果不会调参,优化器个人推荐选择顺序如下:

  1. Adam
  2. Lookahead + (Adam or Yogi or RAdam)
  3. 带有动量的SGD
  4. RAdam,Yogi,DiffGrad

地址:广东省广州市天河区88号 客服热线:400-123-4567 传真:+86-123-4567 QQ:1234567890

Copyright © 2012-2018 首页-焦点娱乐-注册登录站琼ICP备xxxxxxxx号

平台注册入口