Understanding Why Adam Outperforms SGD: Gradient Heterogeneity in Transformers

Akiyoshi Tomihari, Issei Sato
1/31/2025
cs.LGcs.AIcs.NE

Official code: tom4649/gradient-heterogeneity (1 star, last commit 2025-02-04).

Abstract

Transformers are challenging to optimize with SGD and typically require adaptive optimizers such as Adam. However, the reasons behind the superior performance of Adam over SGD remain unclear. In this study, we investigate the optimization of transformers by focusing on gradient heterogeneity, defined as the disparity in gradient norms among parameters. Our analysis shows that gradient heterogeneity hinders gradient-based optimization, including SGD, while sign-based optimization, a simplified variant of Adam, is less affected. We further examine gradient heterogeneity in transformers and show that it is influenced by the placement of layer normalization. Experimental results from fine-tuning transformers in both NLP and vision domains validate our theoretical analyses. This study provides insights into the optimization challenges of transformers and offers guidance for designing future optimization algorithms. Code is available at https://github.com/tom4649/gradient-heterogeneity.

View on arXivView PDF

Code Implementations(1)

Code for "Understanding Why Adam Outperforms SGD: Gradient Heterogeneity in Transformers"

10Shell, PythonJan 31, 20251 years ago

Similar Papers

Cite this paper

@article{tomihari2025understanding,
  title  = {Understanding Why Adam Outperforms SGD: Gradient Heterogeneity in Transformers},
  author = {Akiyoshi Tomihari and Issei Sato},
  year   = {2025},
  eprint = {2502.00213},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2502.00213v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2502.00213.svg)](https://codeofpaper.com/paper/2502.00213)

Discussion