paper-with-me

홈 › Papers

Lightning Attention-2: A Free Lunch for Handling Unlimited Sequence Lengths in Large Language Models

2024-01-09 · Zhen Qin, Weigao Sun, Dong Li, Xuyang Shen, Weixuan Sun, Yiran Zhong

Linear attention is an efficient attention mechanism that has recently emerged as a promising alternative to conventional softmax attention. With its ability to process tokens in linear computational complexities, linear attention, in theory, can handle sequences of unlimited length without sacrificing speed, i.e., maintaining a constant training speed for various sequence lengths with a fixed memory consumption. However, due to the issue with cumulative summation (cumsum), current linear attention algorithms cannot demonstrate their theoretical advantage in a causal setting. In this paper, we present Lightning Attention-2, the first linear attention implementation that enables linear attention to realize its theoretical computational benefits. To achieve this, we leverage the thought of tiling, separately handling the intra-block and inter-block components in linear attention calculation. Specifically, we utilize the conventional attention computation mechanism for the intra-blocks and apply linear attention kernel tricks for the inter-blocks. A tiling technique is adopted through both forward and backward procedures to take full advantage of the GPU hardware. We implement our algorithm in Triton to make it IO-aware and hardware-friendly. Various experiments are conducted on different model sizes and sequence lengths. Lightning Attention-2 retains consistent training and inference speed regardless of input sequence length and is significantly faster than other attention mechanisms. The source code is available at https://github.com/OpenNLPLab/lightning-attention.

📄 PDF Abstract BibTeX arXiv:2401.04658

Code (1)

opennlplab/lightning-attention 공식 구현 pytorch

Tasks

GPU

Methods 이 논문이 사용한 방법론

Softmax The Softmax output function transforms a previous layer's output into a vector of probabilities. It is commonly used for multiclass classification. Given an input vector $x$…
SPEED The monocular depth estimation (MDE) is the task of estimating depth from a single frame. This information is an essential knowledge in many computer vision tasks such as scene…

Similar Papers 제목 키워드 기반

EMPURPLE: A Free Lunch for Diffusion Distillation based on the Information Bottleneck

2026-07-05 · Zilai Li, Lujia Bai arxiv

Diffusion models achieve impressive image-generation quality but remain expensive at inference time. Diffusion distillation reduces sampling steps, yet many distilled models, including SDXL-Lightning and distribution mat…

Can Mamba Always Enjoy the "Free Lunch"?

2024-10-04 · Ruifeng Ren, Zhicong Li, Yong liu

Transformers have been the cornerstone of current Large Language Models (LLMs); however, its linear growth in overhead during inference with respect to sequence length poses challenges for modeling long sequences. In thi…

Mamba

Free Lunch for Optimisation under the Universal Distribution

2016-08-16 · Tom Everitt, Tor Lattimore, Marcus Hutter

Function optimisation is a major challenge in computer science. The No Free Lunch theorems state that if all functions with the same histogram are assumed to be equally probable then no algorithm outperforms any other in…

Free-Lunch Saliency via Attention in Atari Agents

2019-08-07 · Dmitry Nikulin, Anastasia Ianina, Vladimir Aliev, Sergey Nikolenko

We propose a new approach to visualize saliency maps for deep neural network models and apply it to deep reinforcement learning agents trained on Atari environments. Our method adds an attention module that we call FLS (…

Decision MakingDeep Reinforcement Learningreinforcement-learningReinforcement Learning+1

Algebraic Invariants of Lightning Self-Attention

2026-04-17 · Yulia Alexandr, Hao Duan, Guido Montúfar arxiv

We study the polynomial coefficients of lightning self-attention as coordinates of an algebraic variety. We identify linear and nonlinear families of algebraic invariants, including Chow-type, low-rank, Veronese-type, an…