English

Transformer tricks: Precomputing the first layer

Machine Learning 2024-03-13 v3

Abstract

This micro-paper describes a trick to speed up inference of transformers with RoPE (such as LLaMA, Mistral, PaLM, and Gemma). For these models, a large portion of the first transformer layer can be precomputed, which results in slightly lower latency and lower cost-per-token. Because this trick optimizes only one layer, the relative savings depend on the total number of layers. For example, the maximum savings for a model with only 4 layers (such as Whisper tiny) is limited to 25%, while a 32-layer model is limited to 3% savings. See https://github.com/OpenMachine-ai/transformer-tricks for code and more transformer tricks.

Keywords

Cite

@article{arxiv.2402.13388,
  title  = {Transformer tricks: Precomputing the first layer},
  author = {Nils Graef},
  journal= {arXiv preprint arXiv:2402.13388},
  year   = {2024}
}

Comments

5 pages, 2 figures

R2 v1 2026-06-28T14:55:08.434Z