Various Lengths, Constant Speed: Efficient Language Modeling with Lightning Attention

Zhen Qin, Weigao Sun, Dong Li, Xuyang Shen, Weixuan Sun +1 more
2/12/2026

No official code found. Best implementation: OpenNLPLab/TransnormerLLM (256 stars, Apache-2.0, last commit 2024-01-23).

Abstract

We present Lightning Attention, the first linear attention implementation that maintains a constant training speed for various sequence lengths under fixed memory consumption. Due to the issue with cumulative summation operations (cumsum), previous linear attention implementations cannot achieve their theoretical advantage in a casual setting. However, this issue can be effectively solved by utilizing different attention calculation strategies to compute the different parts of attention. Specifically, we split the attention calculation into intra-blocks and inter-blocks and use conventional attention computation for intra-blocks and linear attention kernel tricks for inter-blocks. This eliminates the need for cumsum in the linear attention calculation. Furthermore, a tiling technique is adopted through both forward and backward procedures to take full advantage of the GPU hardware. To enhance accuracy while preserving efficacy, we introduce TransNormerLLM (TNL), a new architecture that is tailored to our lightning attention. We conduct rigorous testing on standard and self-collected datasets with varying model sizes and sequence lengths. TNL is notably more efficient than other language models. In addition, benchmark results indicate that TNL performs on par with state-of-the-art LLMs utilizing conventional transformer structures. The source code is released at github.com/OpenNLPLab/TransnormerLLM.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Official implementation of TransNormerLLM: A Faster and Better LLM

25611Shell, PythonJul 27, 20232 years agoApache-2.0
llmtransnormertransnormerllm

Similar Papers

Cite this paper

@article{qin2026various,
  title  = {Various Lengths, Constant Speed: Efficient Language Modeling with Lightning Attention},
  author = {Zhen Qin and Weigao Sun and Dong Li and Xuyang Shen and Weixuan Sun and Yiran Zhong},
  year   = {2026},
  eprint = {2405.17381},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2405.17381},
  journal = {ICML 2024 2024}
}

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

Discussion