Your Transformer is Secretly Linear

Anton Razzhigaev, Matvey Mikhalchuk, Elizaveta Goncharova, Nikolai Gerasimenko, Ivan Oseledets +2 more
5/19/2024
cs.LGcs.AIcs.CL

No official code found. Best implementation: AIRI-Institute/LLM-Microscope (64 stars, Apache-2.0, last commit 2025-03-03).

Abstract

This paper reveals a novel linear characteristic exclusive to transformer decoders, including models such as GPT, LLaMA, OPT, BLOOM and others. We analyze embedding transformations between sequential layers, uncovering a near-perfect linear relationship (Procrustes similarity score of 0.99). However, linearity decreases when the residual component is removed due to a consistently low output norm of the transformer layer. Our experiments show that removing or linearly approximating some of the most linear blocks of transformers does not affect significantly the loss or model performance. Moreover, in our pretraining experiments on smaller models we introduce a cosine-similarity-based regularization, aimed at reducing layer linearity. This regularization improves performance metrics on benchmarks like Tiny Stories and SuperGLUE and as well successfully decreases the linearity of the models. This study challenges the existing understanding of transformer architectures, suggesting that their operation may be more linear than previously assumed.

View on arXivView PDF

Code Implementations(1)

Apache-2.0
644Python, Jupyter NotebookSep 23, 20241 years agoApache-2.0

Similar Papers

Cite this paper

@article{razzhigaev2024your,
  title  = {Your Transformer is Secretly Linear},
  author = {Anton Razzhigaev and Matvey Mikhalchuk and Elizaveta Goncharova and Nikolai Gerasimenko and Ivan Oseledets and Denis Dimitrov and Andrey Kuznetsov},
  year   = {2024},
  eprint = {2405.12250},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2405.12250v1}
}

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/2405.12250.svg)](https://codeofpaper.com/paper/2405.12250)

Discussion