ArXiv: 2401.04658
🎯 Pitch
Linear attention promises O(n) complexity but has never actually run faster than FlashAttention for causal models—until now. Lightning Attention-2 achieves constant training speed across 1K to 92K token sequences by tiling attention into fast left-product intra-block and right-product inter-block computations, delivering a true free lunch with no accuracy loss.
1. Executive Summary
This paper introduces Lightning Attention-2, a linear attention implementation that resolves the cumulative summation (cumsum) bottleneck that previously prevented linear attention from realizing its theoretical O(n) complexity advantage in causal settings, where prior implementations degraded to quadratic wall-clock time despite linear theoretical complexity. The method employs a tiling strategy that separates computation into intra-block components—computed with conventional left-product attention—and inter-block components—computed with the linear attention kernel trick (right-product, accumulating K⊤V)—and implements both forward and backward passes in Triton for IO-awareness and GPU hardware efficiency. On TransNormerLLM models ranging from 400M to 3B parameters, Lightning Attention-2 maintains constant training speed (tokens per GPU per second) as sequence length scales from 1K to 92K, while FlashAttention-2 and Lightning Attention-1 decline sharply—for example, the 400M model sustains approximately 38,000 TGS across all sequence lengths versus FlashAttention-2 dropping from ~36,000 to ~4,000 TGS. The approach achieves this without accuracy degradation—the 0.4B model shows only a 0.001 loss difference compared to Lightning Attention-1—establishing that linear attention's theoretical computational benefits are fully realizable on GPU hardware when intra- and inter-block computations are algorithmically separated and tiled, rather than relying on a single computational strategy.
2. Context and Motivation
The Core Problem: Linear Attention's Theoretical Promise Has Never Materialized in Practice
The fundamental tension this paper tackles is the gap between algorithmic theory and hardware reality for linear attention mechanisms. Linear attention has existed as a theoretical concept since at least 2020 (Katharopoulos et al., 2020b; Choromanski et al., 2020), promising to reduce the quadratic O(n²d) complexity of standard softmax attention to O(nd²) — a transformation that should make processing arbitrarily long sequences computationally tractable. In theory, this means you could train a language model on sequences of 100,000 tokens with roughly the same per-token cost as training on 1,000 tokens. The paper's opening states this promise explicitly:
"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."
The critical word here is "in theory." The paper's central observation is that this theoretical advantage has never been realized on actual GPU hardware when operating in causal (autoregressive) mode — which is precisely the setting that matters for training and deploying large language models. Prior implementations of linear attention, despite having O(n) algorithmic complexity, exhibited wall-clock training times that grew with sequence length, undermining the entire motivation for using linear attention in the first place. The paper identifies the specific culprit as the cumulative summation (cumsum) operation required by the linear attention kernel trick when applied causally.
This gap between theory and practice is not a minor implementation detail — it is existential for linear attention as a viable alternative to softmax attention. If linear attention cannot actually run faster than softmax attention on long sequences, then its primary selling point evaporates. Researchers and practitioners would continue using FlashAttention-style optimized softmax attention, accepting quadratic scaling as an unavoidable cost, while the theoretical O(n) complexity of linear attention remains a purely academic curiosity.
Why This Problem Matters: The Long-Sequence Bottleneck in Modern LLMs
The inability to efficiently process long sequences is not a niche concern — it touches nearly every frontier of large language model research and deployment. The paper enumerates several domains where unlimited sequence length would be transformative:
Extended conversations and document processing. Professional applications — legal document analysis, medical record summarization, financial report generation — routinely involve inputs spanning tens or hundreds of thousands of tokens. Current models either truncate these inputs (losing information), chunk them (losing cross-chunk dependencies), or process them with quadratic attention at enormous computational cost. A genuinely O(n) attention mechanism that maintains constant per-token speed regardless of sequence length would remove this tradeoff entirely.
Multimodal modeling. When transformers process images, video, or audio alongside text, the token count explodes. A single high-resolution image can produce thousands of visual tokens; a video of even modest length can produce hundreds of thousands. The paper references several multimodal works (Li et al., 2022; Liu et al., 2023; Radford et al., 2021) that are constrained by the quadratic attention bottleneck. Linear attention that scales gracefully to millions of tokens would be foundational for next-generation multimodal systems.
Training from scratch on long contexts. The paper draws an important distinction in Section 2.3 between methods that extend context length during fine-tuning or inference (like Position Interpolation from Chen et al., 2023, or StreamingLLM from Xiao et al., 2023) and methods that enable training on long sequences from scratch with no additional cost. The former category includes valuable techniques but represents a patch — they allow models trained on short contexts to somewhat generalize to longer ones, but with degraded performance as length increases. The paper notes:
"These methods can only extend sequence length in fine-tuning or testing phases, while our method allows training models in long sequence lengths from scratch with no additional cost."
This distinction matters because the quality ceiling for long-context understanding is likely higher when the model has been trained natively on long sequences, learning to attend over and reason about distant dependencies during pretraining itself. If linear attention could deliver on its theoretical promise, it would enable this natively long-context training paradigm at scale.
Where Prior Approaches Fall Short
The paper identifies a lineage of work that attempted to address these challenges, categorizing the failures into two distinct problems:
Problem 1: IO-awareness — solved by Lightning Attention-1.
The first problem is that attention computation on GPUs is bottlenecked not by arithmetic throughput but by memory access bandwidth. The GPU's High Bandwidth Memory (HBM) is large but slow; its on-chip SRAM is fast but tiny (typically tens of megabytes). Naively computing attention requires repeatedly reading large Q, K, V matrices from HBM, computing partial results, and writing intermediate values back — the data movement dominates the actual computation time. The FlashAttention series (Dao et al., 2022; Dao, 2023) addressed this for softmax attention through tiling: splitting inputs into blocks that fit in SRAM, computing attention locally within each block, and carefully orchestrating reads and writes to minimize HBM traffic. This is an IO-aware optimization — it doesn't change the algorithmic complexity (softmax attention remains O(n²d)) but dramatically improves the constant factors on GPU hardware.
Lightning Attention-1 (Qin et al., 2023b) applied similar tiling principles to linear attention, segmenting Q, K, V into blocks, moving them to SRAM, and accumulating results. However, the paper points out a crucial limitation:
"Although this method is much more efficient than the PyTorch implementation, it does not take advantage of the computational characteristics inherent to Linear Attention, and the theoretical complexity remains O(n²d)."
In other words, Lightning Attention-1 made linear attention faster by being IO-aware, but it did not actually achieve linear complexity in practice. It still used the left-product computation (QK⊤ first, then multiplying by V) within its tiled structure, meaning the computation within each block scaled quadratically with block size and the overall computation still scaled quadratically with sequence length when all blocks were accounted for. The paper's Figure 1 and Table 1 (referenced in the executive summary) show this empirically: Lightning Attention-1's throughput drops from ~42,000 TGS at 1K sequence length to ~6,000 TGS at 92K on a 400M model — better than FlashAttention-2's drop to ~4,000 TGS, but still a steep decline that contradicts linear attention's theoretical O(n) promise.
Problem 2: Cumulative summation (cumsum) in causal settings — the unsolved bottleneck.
The second problem is deeper and more fundamental. It stems from the mathematical structure of linear attention when applied causally (autoregressively, where each token can only attend to previous tokens). Understanding this requires a brief walkthrough of the linear attention formulation.
Standard softmax attention computes:
The multiplication produces an attention matrix, making the forward pass O(n²d). The key insight of linear attention is to eliminate the softmax (replacing it with a kernel function or simply removing it, as in TransNormer's NormAttention) and then exploit the associativity of matrix multiplication:
If you compute first — a matrix — and then multiply by , the complexity drops to O(nd²). Since (the feature dimension) is typically much smaller than (the sequence length), this can be a massive reduction. For autoregressive inference, this is particularly elegant: you can maintain a running state (a matrix) that accumulates as new tokens arrive, enabling O(d²) per-token generation regardless of how long the sequence has grown.
However, the causal setting introduces a complication. When each token can only attend to tokens before it, the straightforward right-product formulation is no longer valid — it implicitly allows each token to attend to all tokens, including future ones. The mathematically correct formulation for causal linear attention requires a cumulative sum over time:
For each position , you need to compute the sum of outer products up to and including that position, then multiply by the query at that position. Computing this naively requires outer products per token, bringing the total complexity back to O(n²d²). The standard approach has been to use a parallel prefix sum (cumsum) operation: compute all the per-token outer products , then perform a cumulative sum along the sequence dimension, then multiply by each query. In principle, parallel prefix sum has O(log n) depth and O(n) work — it should be fast. But on GPU hardware, the paper identifies that this cumsum operation is the critical bottleneck:
"the effectiveness of the right product is compromised, leading to the requirement for the computation of cumsum [...] This impediment hinders the potential for highly efficient parallel computation."
The issue is that cumsum is memory-bound: it requires repeatedly reading and writing the accumulating KV matrix, with data dependencies that prevent full parallelization. As grows (and modern LLMs use or larger, making the KV state a matrix with 16.8 million entries), the cumsum operation dominates runtime, and its cost scales with sequence length despite the theoretical O(n) complexity. This is the core conundrum: the mathematical trick that makes linear attention linear in theory introduces a computational pattern that is inefficient on GPU hardware in practice.
Prior work on long sequences is compensatory, not fundamental.
The paper distinguishes its approach from the broader literature on handling long sequences (Section 2.3). Methods like ALiBi (Press et al., 2022), RoPE (Su et al., 2021), Kerple (Chi et al., 2022), and Sandwich (Chi et al., 2023) modify positional encodings to help models generalize to longer sequences than they were trained on — these are length extrapolation techniques. Position Interpolation (Chen et al., 2023) extends context windows of pretrained models through minimal fine-tuning. StreamingLLM (Xiao et al., 2023) exploits the "attention sink" phenomenon to maintain performance with windowed attention. All of these approaches are valuable, but they share a fundamental limitation: they work within the constraints of quadratic attention, attempting to mitigate its costs rather than eliminate them. They either sacrifice the ability to attend to distant tokens (window attention), require expensive fine-tuning (Position Interpolation), or operate on model behavior rather than computational efficiency (positional encoding modifications).
The paper's critique is implicit but clear: these methods treat the symptom (models can't handle long sequences) rather than the cause (attention computation scales quadratically). They enable longer sequences at inference time but don't fundamentally change the training-time cost structure — you still can't afford to train on million-token sequences from scratch.
How This Paper Positions Itself
Lightning Attention-2 is positioned as the first implementation to fully realize linear attention's theoretical computational benefits on GPU hardware, specifically by solving the cumsum bottleneck that Lightning Attention-1 and all prior linear attention implementations failed to address. The paper frames this as a natural progression: Lightning Attention-1 solved the IO-awareness problem (Problem 1), and Lightning Attention-2 solves the algorithmic structure problem (Problem 2).
The paper's key conceptual move is to recognize that the choice between left-product (compute first, yielding an matrix — good for parallel computation within small blocks but scales quadratically) and right-product (compute first, yielding a matrix — scales linearly but requires problematic cumsum for causality) is a false dichotomy. The insight is that both can be used within a single computation, applied at different granularities.
This "divide and conquer" strategy (Section 3.2) separates the sequence into blocks. Within each block (intra-block), Lightning Attention-2 uses left-product attention — the conventional computation — which is efficient for small block sizes because the attention matrix fits in SRAM. Between blocks (inter-block), it uses right-product attention — accumulating across blocks — which achieves the linear scaling in sequence length because you only need to maintain and update a constant-size state. The causal masking is handled differently in each regime: locally within blocks via an explicit causal mask matrix M, and globally across blocks via the accumulated KV state which naturally encodes the sequential dependency.
This hybrid strategy is what makes the approach novel. Prior tiling approaches (FlashAttention, Lightning Attention-1) used tiling to improve IO efficiency but maintained a single computational strategy — left-product — throughout. The paper's crucial observation is that the computational strategy itself should vary with the tiling structure: left-product for the dense, local computations within a block (where quadratic scaling on block size B is acceptable because B ≪ n); right-product for the sparse, global accumulation across blocks (where linear scaling on n/B blocks is essential).
The approach is IO-aware — implemented in Triton (Tillet et al., 2019) to orchestrate data movement between HBM and SRAM — and handles both forward and backward passes with the same tiling strategy. The backward pass (Algorithm 2) requires careful handling because gradients flow in the reverse direction: dKV states must be accumulated in reverse order, requiring a separate backward pass that mirrors the forward pass structure but with the recursion running from the end of the sequence toward the beginning.
The paper explicitly acknowledges a related concurrent work — Gated Linear Attention (GLA) by Yang et al. (2023) — which also uses chunk-wise tiling for linear attention. However, the paper distinguishes its contribution: GLA's Block-Parallel Algorithm "uses parallel computations for each block, which leads to higher memory usage" and does not address the backward pass or IO-awareness. Retentive Network (Sun et al., 2023b) uses a chunk-wise algorithm similar to Lightning Attention-2's forward pass but similarly lacks backward pass optimization and IO-awareness. These comparisons position Lightning Attention-2 as the first complete solution — forward and backward, IO-aware, memory-efficient, and achieving truly constant speed with sequence length — rather than a partial solution addressing only the forward pass or ignoring memory constraints.
The paper's positioning is ultimately about practical realizability: linear attention has been promising in theory for years, but no implementation has delivered on that promise in the setting that matters (causal training of large models on GPU hardware). Lightning Attention-2 claims to be the first to do so, and the empirical evidence — constant TGS from 1K to 92K sequence length in Figure 1 and Table 1 — is presented as the proof that the theoretical benefits are now practically accessible.
3. Technical Approach
3.1 Reader Orientation
Lightning Attention-2 is a GPU kernel implementation (written in Triton) that computes linear attention for autoregressive language models such that the wall-clock training speed remains constant regardless of sequence length, from 1K to 92K tokens and beyond. It solves the cumulative summation bottleneck that previously prevented linear attention from realizing its theoretical O(n) complexity on actual hardware by decomposing the attention computation into two separate strategies — conventional left-product attention within small blocks and linear-attention right-product accumulation across blocks — orchestrated through tiling to keep all working data in fast on-chip SRAM.
3.2 Big-Picture Architecture (Diagram in Words)
The system has five major components that operate together during both forward and backward passes:
-
Input matrices Q, K, V ∈ R^{n×d} — the query, key, and value projections produced by the model's linear layers, stored in GPU High Bandwidth Memory (HBM).
nis the sequence length,dis the feature dimension per head. -
Tiling decomposition — a preprocessing step that logically divides the full sequence of length
nintoT = n/Bblocks of sizeB × deach, whereBis a block size chosen to fit within on-chip SRAM limits. This decomposition is not a separate data copy but determines how the following loop iterates. -
Intra-block computation (left-product attention) — within each block
i, compute local attention using the conventionalQ_i K_i^\topformulation, yielding aB × Battention matrix. A causal maskM(aB × Bmatrix whereM_{st} = λ^{s-t}whens ≥ tand 0 otherwise) enforces that each token within the block can only attend to preceding tokens. This producesO_intra, the contribution from tokens within the same block. -
Inter-block computation (right-product accumulation) — a persistent
KV ∈ R^{d×d}matrix is maintained in SRAM that accumulates key-value outer products from all previous blocks. For blocki, this accumulated state is multiplied byQ_i(with appropriate decay factorsΛ) to produceO_inter, the contribution from all tokens in blocks before blocki. After computing blocki's output, the block's ownK_iandV_iare incorporated intoKVfor use by subsequent blocks. -
Output assembly — for each block
i, the final outputO_i = O_intra + O_interis the sum of the intra-block and inter-block contributions. This result is written back to HBM. The summation occurs entirely within SRAM before the write-back, minimizing HBM traffic.
Information flows as follows: Q, K, V reside in HBM → block i of each is loaded into SRAM → intra-block attention computes local contributions using left-product → inter-block attention computes global contributions using the accumulated KV state → results are summed → KV state is updated with current block's contribution → block output is written to HBM → process repeats for block i+1. The backward pass reverses this flow, computing gradients for Q, K, V by traversing blocks in forward order (for dQ) and reverse order (for dK, dV), maintaining a dKV accumulator analogous to the forward KV.
3.3 Roadmap for the Deep Dive
-
First, the linear attention formulation and the cumsum problem, to establish exactly what Lightning Attention-2 is computing and why the naive right-product formulation fails in causal settings — this is the mathematical foundation that motivates the entire tiling strategy.
-
Second, the forward pass tiling derivation, walking from the per-token recurrence through the block-level decomposition to the final Algorithm 1, showing explicitly how the intra-block and inter-block terms separate and how the KV state is updated — this is the core algorithmic contribution.
-
Third, the backward pass tiling derivation, which mirrors the forward pass structure but requires careful handling of gradient flow direction (forward for dQ, reverse for dK and dV) and introduces the dKV accumulator — this demonstrates that the method is complete and trainable.
-
Fourth, the IO-awareness and hardware mapping, explaining why the tiling strategy maps efficiently to GPU memory hierarchy (HBM vs. SRAM), how block size B is chosen, and why the Triton implementation matters — this connects the algorithm to practical speed.
-
Fifth, design choices and comparison to alternatives, explaining why left-product for intra-block and right-product for inter-block is the key insight, what would go wrong with uniform application of either strategy, and how this differs from GLA and RetNet.
3.4 Detailed, Sentence-Based Technical Breakdown
This is primarily a systems and algorithms paper whose core idea is that linear attention's cumsum bottleneck can be eliminated by applying different computation strategies at different granularities — left-product attention within tiled blocks (where the quadratic cost on block size B is negligible) and right-product accumulation across blocks (where linear scaling in the number of blocks is achieved) — and that this decomposition, when implemented with IO-aware tiling in Triton, yields the first practical realization of linear attention's theoretical O(n) complexity on GPU hardware.
The Linear Attention Formulation and the Cumsum Problem
The paper builds on the NormAttention variant from the TransNormer architecture (Qin et al., 2022a), which simplifies standard softmax attention by removing both the softmax operation and the scaling factor. The base attention computation is:
where Q ∈ R^{n×d} is the query matrix, K ∈ R^{n×d} is the key matrix, V ∈ R^{n×d} is the value matrix, n is the sequence length, d is the per-head feature dimension, and Norm(·) is a normalization operation (LayerNorm or similar) applied to the output. The QK^\top multiplication produces an n × n attention matrix — this is the source of the O(n²) complexity, because it explicitly materializes pairwise interactions between all tokens.
What this computes: each row of O is a weighted combination of all value vectors, where the weights are computed as the inner product of the query vector with all key vectors. This is the standard attention mechanism but without the softmax nonlinearity that forces the weights to be positive and sum to one.
Why this form matters for the reformulation: because there is no softmax, the matrix multiplication is purely linear and therefore associative. This associativity — the property that (QK^\top)V = Q(K^\top V) — is what enables the entire linear attention approach. Softmax attention cannot be re-associated in this way because the softmax is a nonlinearity applied element-wise to the entire QK^\top matrix, and softmax of a matrix product does not equal the product of softmaxes.
Exploiting associativity, the same computation can be mathematically equivalently expressed as:
where K^\top V is a d × d matrix (the key-value outer product sum), and the subsequent multiplication by Q produces the n × d output.
What this computes: first, all key vectors are combined with their corresponding value vectors via outer products and summed — each outer product k_s^\top v_s is a d × d matrix capturing how key dimension i and value dimension j interact for token s, and summing over s aggregates these interactions across the entire sequence. Second, each query vector q_t multiplies this aggregated d × d matrix to produce its output. The computational cost is O(nd²) for the K^\top V accumulation plus O(nd²) for the Q(K^\top V) multiplication, for a total of O(nd²), compared to O(n²d + nd²) for the left-product formulation.
Why this form is theoretically better: when d ≪ n (as is typical in transformers, where d is 64–128 per head while n can be tens or hundreds of thousands), the d × d matrix is much smaller than the n × n matrix. The computation scales linearly with sequence length rather than quadratically. For autoregressive inference, this is even more powerful: the K^\top V matrix can be maintained as a running state updated with each new token, enabling O(d²) per-token generation cost regardless of how long the sequence has grown.
However, the causal (autoregressive) setting breaks this elegant reformulation. In a causal language model, each token t can only attend to tokens s ≤ t (itself and previous tokens). The non-causal formulation Q(K^\top V) implicitly allows token t to attend to all tokens, including future ones — the K^\top V sum includes contributions from the entire sequence, and q_t multiplies this complete sum. The mathematically correct causal formulation must restrict the sum for each position t to only tokens up to t:
What this computes: for each position t, the output is the query at position t multiplied by the sum of key-value outer products from all positions up to and including t. The sum inside the parentheses is different for every t — it grows as t increases. This is the mathematical statement of causality: position 1's output depends only on token 1's key and value; position 2's output depends on tokens 1 and 2; position n's output depends on all tokens.
Why this causes the cumsum problem: computing each position's partial sum independently would require t outer products for position t, totaling O(n²d²) operations — worse than standard attention. The standard workaround is to use a parallel prefix sum (cumulative sum, or cumsum) operation: compute all per-token outer products k_t^\top v_t (O(nd²) total), then perform a cumulative sum along the sequence dimension (theoretically O(n) work with O(log n) depth using parallel algorithms), then multiply each query by its corresponding partial sum (O(nd²)). The problem is that on GPU hardware, this cumsum is extremely slow in practice. The accumulating d × d matrix (with d² entries, e.g., 4096² ≈ 16.8 million for typical configurations) must be read and written for each sequence position, and the data dependency between consecutive positions prevents full parallelization. The cumsum becomes the dominant cost, and its wall-clock time grows with n despite the theoretical O(n) asymptotic complexity. This is why prior linear attention implementations (including Lightning Attention-1, which used left-product tiling) could not achieve constant speed with increasing sequence length — the cumsum bottleneck was either present (in right-product implementations) or the implementation reverted to left-product (achieving IO-efficiency but retaining quadratic scaling).
The paper introduces an additional nuance: TransNormer's linear attention includes a decay factor λ ∈ (0, 1] that weights recent tokens more heavily than distant ones, analogous to the exponential decay in some RNN architectures. The full per-token causal formulation with decay is:
where λ^{t-s} is the decay factor raised to the power of the temporal distance between the current token t and the attended token s. When λ < 1, tokens further in the past are exponentially discounted.
What this decay accomplishes: it introduces a recency bias that helps the model focus on nearby context while still theoretically retaining access to distant information. For λ = 1, all tokens are weighted equally (no decay). For λ < 1, the contribution of a token d positions away is multiplied by λ^d, which decays to near zero for large d. This is a common design choice in linear attention models that partially compensates for the lack of the softmax's dynamic reweighting.
Why this complicates the cumsum problem further: the decay means the accumulated KV state cannot simply be a running sum — each existing term must be decayed before adding the new term. The recurrence becomes KV_t = λ · KV_{t-1} + k_t^\top v_t. This is still a linear recurrence and can in principle be handled by parallel scan algorithms, but the multiplicative decay adds another operation per step that further strains the GPU memory bandwidth.
The paper's recursive formulation (Equation 4) captures this precisely:
where kv_t is the accumulated key-value state at position t, initialized to the zero matrix, and updated at each step by decaying the previous state and adding the current token's key-value outer product. The output at position t is simply the query multiplied by this state. This recurrence is the key to understanding why the tiling strategy works: the inter-block component uses exactly this recurrence, but applied at block granularity rather than token granularity.
Forward Pass: From Per-Token Recurrence to Block-Level Decomposition
The forward pass of Lightning Attention-2 takes the per-token recurrence above and restructures it to operate on blocks of size B, where B is chosen so that B × d matrices fit comfortably in GPU SRAM. The total sequence of length n is partitioned into T = n/B blocks. The paper defines block-level notation where X_i ∈ R^{B×d} represents the i-th block of matrix X (with i ranging from 1 to T).
The first key definition is the block-level KV state (Equation 6):
What this defines: KV_t is the accumulated key-value state after processing the first t blocks (i.e., the first tB tokens). It is the sum of key-value outer products from all tokens in blocks 1 through t, with each token's contribution decayed by λ raised to the power of its distance from position tB (the end of block t). This is exactly analogous to the per-token kv_t state but defined at block boundaries.
Why define it at block boundaries: the inter-block computation needs to know the aggregate KV state from all previous blocks to compute the contribution of past tokens to the current block's outputs. By maintaining KV_t only at block boundaries (not at every token), we avoid the per-token cumsum bottleneck — we only update this d × d matrix once per block, T = n/B times total, rather than n times. The per-token updates within a block are handled by the intra-block computation, which uses the efficient left-product formulation.
The core derivation (Equation 7) shows how to compute the output for any token within block t+1. Consider the token at position tB + r where 1 ≤ r ≤ B (the r-th token within block t+1). Its output is:
What this computes: the output for the r-th token of block t+1, attending to all tokens up to and including itself.
The key manipulation is to split the sum into two parts: tokens within the same block (positions tB+1 through tB+r) and tokens in all previous blocks (positions 1 through tB):
What this split accomplishes: the first sum is the intra-block contribution — it involves only tokens within the current block, and the summation ranges from the start of the block to the current position r. The second term is the inter-block contribution — it involves all tokens from previous blocks, captured by KV_t (the accumulated state at the end of block t), multiplied by λ^r to account for the additional decay from position tB to position tB+r.
Why this splitting is the key insight: the intra-block sum involves at most B terms and can be computed efficiently using the conventional left-product QK^\top V approach, because B is small (the B × B attention matrix fits in SRAM). The inter-block term involves an arbitrarily large number of previous tokens, but it's captured entirely by the d × d matrix KV_t — no per-token operations on previous tokens are needed. The cumsum over n tokens has been replaced by: (1) a small number of per-block KV updates (T of them) and (2) per-token intra-block computations that are quadratic in B but B ≪ n.
Rewriting this in matrix form for the entire block t+1 yields the central equation of the forward pass (Equation 8):
where the first term is labeled "Intra Block" and the second term is labeled "Inter Block."
Symbol definitions:
Q_{t+1}, K_{t+1}, V_{t+1} ∈ R^{B×d}are the query, key, and value matrices for blockt+1(each containingBtoken vectors of dimensiond)M ∈ R^{B×B}is the causal mask matrix defined byM_{ij} = λ^{i-j}wheni ≥ jand0otherwise — this encodes both causality (upper triangular is zero) and the decay within the block⊙denotes element-wise (Hadamard) multiplication —(Q_{t+1}K_{t+1}^\top) \odot Mapplies the causal mask and decay to the raw attention scoresΛ = \text{diag}\{λ^0, λ^1, ..., λ^{B-1}\} ∈ R^{B×B}is a diagonal matrix whereΛ_{rr} = λ^{r-1}— this applies the appropriate decay to each row ofQ_{t+1}based on the token's positionrwithin the block when computing inter-block contributionsKV_t ∈ R^{d×d}is the accumulated key-value state from all blocks up to blockt
What the intra-block term computes: Q_{t+1}K_{t+1}^\top produces a B × B matrix of raw attention scores between every pair of tokens within block t+1. Element-wise multiplication with M zeros out the upper triangle (enforcing causality — token i cannot attend to token j > i) and applies the exponential decay λ^{i-j} to the lower triangle. Multiplying by V_{t+1} produces the output contribution: for each query position, a weighted sum of the value vectors from tokens within the same block, with weights decaying with distance.
What the inter-block term computes: KV_t is the accumulated key-value state from all previous blocks. Q_{t+1}(KV_t) would give equal weight to all previous tokens regardless of the current token's position within the block. However, tokens later in the current block are further from the previous blocks, so their attention to previous tokens should be more decayed. The diagonal matrix Λ applies this position-dependent decay: the r-th row of Q_{t+1} (corresponding to the r-th token in the block) is multiplied by λ^{r-1} before multiplying by KV_t. This correctly implements the λ^r factor from Equation 7.
Why this decomposition is correct: it is an exact mathematical equivalence to the per-token recurrence. No approximation is introduced. Every token's output is computed as the sum of its attention to tokens within its own block (via left-product with causal masking) and its attention to all tokens in previous blocks (via the accumulated KV state with position-dependent decay). The only difference from the naive per-token recurrence is the order of operations, which is rearranged to be hardware-efficient.
The final piece of the forward pass is the update rule for the KV state (Equation 10). After processing block t+1, the KV state must be updated for block t+2:
What this computes: the new KV state (at the end of block t+1) is the old KV state (at the end of block t) decayed by λ^B (to account for the B additional positions of distance) plus the contributions from the B tokens in block t+1, each decayed by the appropriate amount based on its distance from the end of the block.
Breaking down the update term: Λ^{-1} = \text{diag}\{λ^0, λ^{-1}, ..., λ^{-(B-1)}\} is the inverse of the earlier Λ matrix. The expression λ^B Λ^{-1} K_{t+1} first "un-decays" each row of K_{t+1} by the intra-block decay (since within the block, tokens were already ordered with decay, but now we need their contributions relative to the end of the block) and then applies the inter-block decay λ^B. Multiplying by λ^B Λ^{-1} is equivalent to computing \text{diag}\{λ^B, λ^{B-1}, ..., λ^1\} — the j-th token in the block (counting from the start) is distance B-j+1 from the end of the block, so its contribution should be decayed by λ^{B-j+1}. The outer product with V_{t+1} and summation across the B tokens in the block produces the block's total contribution to the KV state.
Why this update form is efficient: it requires only one d × d matrix scaling (λ^B KV_t), one B × d matrix scaling (λ^B Λ^{-1} K_{t+1}), and one batched outer product ((λ^B Λ^{-1} K_{t+1})^\top V_{t+1} of size d × d). All of these operations fit within the O(Bd²) budget of processing a block and involve only the small d × d KV matrix, not any n × n matrices.
Algorithm 1 encapsulates the complete forward pass:
-
Input preparation: Given Q, K, V ∈ R^{n×d}, decay λ, and block size B, divide all matrices into T = n/B blocks of size B × d each. Initialize the causal mask M (B×B, upper triangular zeros, lower triangular
λ^{i-j}), the intra-block decay matrix Λ (B×B diagonal), and the KV state (d×d, all zeros). -
Block iteration (forward): For i = 1 to T:
- Load Q_i, K_i, V_i from HBM to SRAM.
- Compute O_intra = [(Q_i K_i^\top) ⊙ M] V_i — this is the left-product attention within the block, producing a B×d output.
- Compute O_inter = Λ Q_i (KV) — this multiplies each query (decayed by its position within the block) by the accumulated KV state, producing a B×d output.
- Compute O_i = O_intra + O_inter — sum the two contributions.
- Write O_i to HBM as the i-th block of the output O.
- Update KV = λ^B KV + (λ^B Λ^{-1} K_i)^\top V_i — incorporate the current block's contribution for use by subsequent blocks.
-
Return O, the complete n×d output.
Design choice — why separate intra and inter rather than using a single strategy: if the entire sequence were processed with left-product attention (as in Lightning Attention-1), the computation would be quadratic in n (each block would need to attend to all previous blocks via explicit Q_i K_j^\top computations). If the entire sequence were processed with right-product accumulation (as naive linear attention), the cumsum bottleneck would dominate because the KV state would need to be updated at every token position, not just at block boundaries. By using left-product for intra-block (where B is small and quadratic scaling is acceptable) and right-product for inter-block (where the number of blocks T is much smaller than n, and only T KV updates are needed), the method achieves the best of both: the intra-block computation is fast because B×B matrices fit in SRAM, and the inter-block computation is fast because it avoids per-token cumsum.
Backward Pass: Computing Gradients with Block-Level Reversal
The backward pass computes gradients of the loss with respect to Q, K, and V (denoted dQ, dK, dV) given the gradient of the loss with respect to the output O (denoted dO). The paper provides the per-token gradient recurrence (Equations 11–12) before showing the block-level decomposition.
Given do_t (the gradient with respect to output o_t), the per-token gradients are:
where dkv_t is a d × d matrix representing the gradient with respect to the accumulated KV state at position t, defined as:
What dkv_t represents: while the forward KV state accumulates key-value information from past tokens, dkv_t accumulates query-output-gradient information from future tokens. It captures how much each position t's KV state contributes to all future outputs, weighted by the attention decay.
Why this reversal makes sense: in the forward pass, information flows from earlier tokens to later tokens (through the KV recurrence). In the backward pass, gradients flow from later tokens to earlier tokens — the gradient of the loss with respect to an early token's key or value depends on how that token affected all subsequent outputs. The dkv_t recurrence runs backward in time, starting from the end of the sequence and accumulating query-output-gradient outer products.
The recurrence for dkv_t (Equation 12) runs in reverse:
What this recurrence computes: starting from position n (where there are no future tokens, so dkv_{n+1} = 0), the dkv state moves backward through the sequence. At each step, the previous dkv is decayed (since moving one position backward means all future tokens are one step further away, requiring a λ decay), and the current position's query-output-gradient outer product is added. This is the exact mirror of the forward KV recurrence: forward accumulates k^\top v moving forward in time; backward accumulates q^\top do moving backward in time.
The block-level decomposition for the backward pass introduces a block-level dKV accumulator analogous to the forward KV:
What dKV_t represents: the gradient with respect to the KV state at the end of block t, capturing contributions from all tokens in blocks after t. Unlike the forward KV_t which accumulates information from earlier blocks, dKV_t accumulates gradient information from later blocks — it runs backward through the sequence of blocks.
The backward pass requires two separate traversals over blocks because different gradient computations depend on different temporal directions:
Forward traversal (i = 1 to T) for dQ computation (Equation 15):
where the first term is "Intra Block" and the second is "Inter Block."
What the intra-block term computes: dO_{t+1} V_{t+1}^\top produces a B × B matrix of raw gradient contributions — for each output position, how much the gradient flows back to each value position within the same block. The mask M (the same causal mask from the forward pass) ensures gradients don't flow through connections that were masked out in the forward pass. Multiplying by K_{t+1} converts these value-space gradients to query-space gradients: dQ measures how changes in queries affect the loss, and queries interact with keys through the attention scores, so the gradient with respect to Q involves K and the attention-weighted dO.
What the inter-block term computes: KV_t^\top is the transpose of the forward KV state — it captures how past keys and values were combined. dO_{t+1}(KV_t^\top) computes how the gradient with respect to block t+1's output flows back to the queries, mediated by the accumulated key-value state from previous blocks. The Λ matrix applies the same position-dependent decay as in the forward pass.
Why dQ can be computed in forward block order: the gradient dQ_{t+1} depends on dO_{t+1} (available from the start — dO is an input to the backward pass), K_{t+1}, V_{t+1} (loaded from HBM), and KV_t (the forward KV state at block t, which was computed during the forward pass and can be either stored or recomputed). There's no dependence on future gradients. The KV_t values are accumulated during the forward traversal of the backward pass, exactly mirroring the forward pass accumulation.
Reverse traversal (i = T down to 1) for dK and dV computation (Equations 17 and 19):
For block t (using index t rather than t+1 for cleaner notation, where the block contains positions (t-1)B + r for 1 ≤ r ≤ B):
In both equations, the first term is "Intra Block" and the second is "Inter Block."
What the intra-block dK term computes: (dO_t V_t^\top) \odot M is the same masked attention gradient as in dQ. Transposing the mask-applied matrix and multiplying by Q_t gives the gradient with respect to keys: how much each key vector contributed to the attention scores, weighted by the query vectors and output gradients. The transpose reflects that in the forward pass, K appears on the right side of QK^\top; in the backward pass, the chain rule transposes this relationship.
What the intra-block dV term computes: (Q_t K_t^\top) \odot M is the masked attention matrix from the forward pass. Transposing and multiplying by dO_t gives the gradient with respect to values: values affect the output directly (not through attention scores), so dV is simply the attention-weighted sum of output gradients.
What the inter-block terms compute: dKV_{t+1} is the accumulated gradient state from blocks after t. For dK, the inter-block contribution is λ^B Λ^{-1} V_t (dKV_{t+1}^\top) — this measures how block t's keys, when combined with block t's values, affected the KV state, and how that KV state in turn affected all subsequent outputs (captured by dKV_{t+1}). The λ^B Λ^{-1} factors apply the same block-boundary decay as in the forward pass. Similarly for dV, the inter-block contribution is λ^B Λ^{-1} K_t (dKV_{t+1}).
Why dK and dV require reverse traversal: the inter-block terms depend on dKV_{t+1}, which accumulates gradients from future blocks. To compute dKV_t (needed for block t-1), we need dKV_{t+1} (from block t). This creates a backward recurrence over blocks, exactly mirroring the per-token dkv_t recurrence. The block-level dKV recurrence (Equation 20) is:
What this recurrence computes: the gradient state for block t is the gradient state from block t+1 (decayed by λ^B to account for the additional distance) plus the contribution from block t's own queries and output gradients. This runs from t = T down to t = 1, starting with dKV_{T+1} = 0.
Algorithm 2 describes the complete backward pass:
-
Input preparation: Given Q, K, V, dO ∈ R^{n×d}, decay λ, and block size B, divide all matrices into T blocks. Initialize masks M and Λ (same as forward pass). Initialize KV = 0 (for recomputing or using stored forward KV values) and dKV = 0.
-
Forward-order traversal for dQ (i = 1 to T):
- Load K_i, V_i, O_i, dO_i from HBM to SRAM.
- Compute dQ_intra = [(dO_i V_i^\top) ⊙ M] K_i.
- Compute dQ_inter = Λ dO_i (KV)^\top.
- Update KV = λ^B KV + (λ^B Λ^{-1} K_i)^\top V_i (same update as forward pass).
- Write dQ_i = dQ_intra + dQ_inter to HBM.
-
Reverse-order traversal for dK and dV (i = T down to 1):
- Load Q_i, K_i, V_i, O_i, dO_i from HBM to SRAM.
- Compute dK_intra = [(dO_i V_i^\top) ⊙ M]^\top Q_i.
- Compute dK_inter = (λ^B Λ^{-1} V_i) (dKV)^\top.
- Compute dV_intra = [(Q_i K_i^\top) ⊙ M]^\top dO_i.
- Compute dV_inter = (λ^B Λ^{-1} K_i) dKV.
- Update dKV = λ^B dKV + (Λ Q_i)^\top dO_i.
- Write dK_i = dK_intra + dK_inter and dV_i = dV_intra + dV_inter to HBM.
-
Return dQ, dK, dV, the complete gradients.
Design choice — two-pass backward: the backward pass requires two traversals because dQ depends only on information available in forward order (the forward KV state), while dK and dV depend on information that must be accumulated in reverse order (the dKV state). This is not an inefficiency — it's a fundamental consequence of the chain rule applied to a directed acyclic computation graph with both forward (KV) and backward (dKV) recurrences. The computation is still O(nd²) overall, and the separation into two passes actually improves memory locality: the dQ pass only needs to access K, V, and dO (while building KV), and the dK/dV pass needs Q, K, V, dO, and dKV.
Why the backward pass is essential for a complete solution: the paper emphasizes in Section 3.3 that prior chunk-wise methods (RetNet's chunk-wise retention, GLA's Block-Parallel Algorithm) either only addressed the forward pass or used simpler backward approximations. Lightning Attention-2 provides exact gradients for all parameters through the complete tiled computation, enabling end-to-end training with standard optimization algorithms. Without an efficient backward pass, a method might be useful for inference but cannot be used for training — and training on long sequences from scratch is the paper's stated goal.
IO-Awareness and Hardware Mapping
The paper implements Lightning Attention-2 in Triton (Tillet et al., 2019), a programming language and compiler designed for writing high-performance GPU kernels. Triton provides abstractions for tiling and memory management that make it easier to write IO-aware code compared to raw CUDA, while still compiling to highly optimized PTX code.
The GPU memory hierarchy is central to understanding why tiling provides speed benefits. A modern GPU (like the A100 80G used in the paper's experiments) has two main memory regions:
-
High Bandwidth Memory (HBM): the large (80 GB) off-chip memory where all model parameters, activations, and optimizer states reside. HBM has high capacity but limited bandwidth (approximately 2 TB/s on A100) and high latency. Reading from or writing to HBM is the primary bottleneck for most deep learning operations.
-
Static Random-Access Memory (SRAM): the small (192 KB per streaming multiprocessor on A100, totaling approximately 20 MB across all SMs) on-chip memory directly accessible by compute units. SRAM has extremely high bandwidth (approximately 19 TB/s) and low latency, but its limited capacity means only small chunks of data can reside there at once.
The IO-aware principle (established by FlashAttention and followed by Lightning Attention-2) is to minimize HBM reads and writes by loading data in blocks that fit in SRAM, performing as much computation as possible on those blocks while they're in fast memory, and only writing final results back to HBM.
How Lightning Attention-2 maps to this hierarchy:
-
Initial state: Q, K, V matrices (each of size n × d, where n can be 131K and d is typically 64–128 per head, so each matrix can be tens to hundreds of megabytes) reside in HBM. The KV state (d × d, typically a few hundred KB to a few MB, fitting comfortably in SRAM) and dKV state also start in HBM but are loaded into SRAM and persist there throughout the block iteration.
-
Per-block loop (forward): For each block
i:- HBM → SRAM: Load Q_i, K_i, V_i (each B × d, where B is chosen so B × d ≪ SRAM capacity) into SRAM. This is the only HBM read for input data in this iteration.
- SRAM computation: Compute O_intra = [(Q_i K_i^\top) ⊙ M] V_i. This involves a
B × Bmatrix multiplication (fast — B is small), an element-wise mask, and aB × dmatrix multiplication. All intermediate results stay in SRAM. - SRAM computation: Compute O_inter = Λ Q_i (KV). This is a
B × dtimesd × dmultiplication. The KV matrix (d × d) was already in SRAM from the previous iteration and stays resident. - SRAM computation: O_i = O_intra + O_inter.
- SRAM computation: Update KV = λ^B KV + (λ^B Λ^{-1} K_i)^\top V_i. This modifies the KV state in-place in SRAM for use by the next block.
- SRAM → HBM: Write O_i (B × d) to HBM. This is the only HBM write in this iteration.
Why this minimizes HBM traffic: each block of Q, K, V is read once from HBM and each block of O is written once to HBM. The total HBM traffic is O(4nd) (reading Q, K, V; writing O), which is optimal — you cannot compute attention without at least reading the inputs and writing the outputs. The n × n attention matrix that would require O(n²) HBM traffic in a naive implementation is never materialized in HBM; it exists only transiently in SRAM as a B × B matrix.
Block size selection: the paper uses a block size B that fits B × d matrices in SRAM along with the d × d KV state and working memory for matrix multiplications. With d = 64-128 and SRAM of ~192 KB per SM, B values of 64–256 are typical. The paper does not specify exact B values but notes that it's chosen to fit within SRAM constraints. The constraint is O(Bd + d²) memory in SRAM, and since d² is fixed (e.g., 128² = 16,384 entries ≈ 32 KB in fp16), B can be reasonably large (e.g., B ≈ d or B = 2d).
Why Triton matters for this implementation: raw CUDA would require manual management of shared memory allocation, thread block scheduling, and data movement. Triton's programming model lets the author specify the tiling structure (block sizes, which arrays are tiled) and the per-block computation, and the Triton compiler handles the mapping to GPU compute units, including automatic double-buffering of loads and stores, register allocation, and instruction scheduling. The paper's contribution is the algorithmic decomposition; Triton makes the implementation practical and ensures the IO-awareness is properly realized.
Design Choices and Comparison to Alternatives
The core design choice — hybrid left-product and right-product:
The paper's key insight is that the cumsum bottleneck arises specifically from trying to apply a single computation strategy uniformly across the entire sequence. By separating the problem into two regimes — within blocks and across blocks — different strategies can be applied where each is optimal:
-
Within blocks (intra-block): left-product
QK^\top Vis used. Why? Because the block sizeBis small (e.g., 128), and computing aB × Battention matrix is cheap — it's only 16,384 entries, which fits comfortably in SRAM and can be computed with a single matrix multiplication. The causal mask can be applied element-wise to this small matrix without significant overhead. If right-product were used within blocks, the KV state would need to be updated at each of theBtoken positions within the block, recreating the cumsum bottleneck at the intra-block level. -
Across blocks (inter-block): right-product
Q(K^\top V)is used. Why? Because the number of blocksT = n/B(e.g., 1024 for n = 131K, B = 128) is much smaller than the sequence lengthn, so updating thed × dKV state onlyTtimes (rather thanntimes) avoids the cumsum bottleneck. Thed × dKV state (e.g., 128 × 128 = 16,384 entries) is small enough to stay resident in SRAM across all blocks. If left-product were used across blocks, each block would need to compute attention with all previous blocks —Q_i K_j^\topfor allj < i— which would be quadratic in the number of blocks and defeat the purpose.
Why this hybridization is not obvious: the linear attention literature has historically treated left-product and right-product as mutually exclusive alternatives — either you compute QK^\top V (familiar but quadratically scaling) or Q(K^\top V) (linear in theory but hampered by cumsum in practice). The idea that you can decompose the computation spatially (along the sequence dimension) and use left-product locally while using right-product globally is a genuinely novel framing. It requires recognizing that the cumsum bottleneck is specifically a problem of fine-grained recurrence (every token updating a shared state), and that coarsening the recurrence to block granularity eliminates the bottleneck while preserving the linear scaling in sequence length.
Comparison to Lightning Attention-1 (Qin et al., 2023b):
Lightning Attention-1 used tiling for IO-awareness but applied left-product uniformly — within each block and across blocks (by computing Q_i K_j^\top between blocks). The paper states this explicitly in Section 2.2:
"the theoretical complexity remains O(n²d)"
The result is visible in Figure 1: Lightning Attention-1's throughput drops as sequence length increases, because the number of block-to-block interactions grows quadratically with the number of blocks. Lightning Attention-2 fixes this by switching to right-product accumulation for inter-block interactions, reducing this cost to linear in the number of blocks.
Comparison to Gated Linear Attention (GLA, Yang et al., 2023):
GLA uses a chunk-wise algorithm that also employs tiling. The paper acknowledges this similarity but identifies two differences:
"unlike Lightning Attention-2, it uses parallel computations for each block, which leads to higher memory usage"
Specifically, GLA appears to compute attention between all pairs of chunks in parallel, which requires materializing an attention tensor of size T × T × d × d (number of chunks squared) — this is quadratic in the number of chunks, analogous to Lightning Attention-1's limitation. Additionally, the paper states that GLA does not consider IO-awareness or the backward pass in the same level of detail.
Comparison to RetNet (Sun et al., 2023b):
RetNet uses a chunk-wise retention algorithm for its forward pass that is structurally similar to Lightning Attention-2's forward pass — it maintains a recurrent state across chunks while computing attention within chunks. However, the paper notes:
"This algorithm is comparable to the forward pass of Lightning Attention-2 but does not consider IO-aware or the backward pass."
Without an IO-aware implementation, the constant factors can be poor (even if the algorithm scales linearly, frequent HBM reads and writes can make it slower than optimized quadratic attention at practical sequence lengths). Without an efficient backward pass, the method is unsuitable for training.
Position of the Norm(·) operator:
The paper explicitly ignores the Norm(·) operator in Equation 2 during the derivations (Section 3.2.1, "We ignore the Norm(·) operator in eq. (2) to simplify the derivations"). This is a reasonable simplification because the normalization (LayerNorm or similar) is applied per-token to the output and does not affect the attention computation's structure — it's an element-wise or row-wise operation that commutes with the tiling decomposition. The normalization can be applied to the output O after the attention computation, or equivalently, to each block's output before writing to HBM.
The decay parameter λ:
The decay factor λ appears throughout the formulation and is a hyperparameter of the TransNormer architecture (not introduced by Lightning Attention-2). It controls the exponential decay of attention over time. When λ = 1, there is no decay — the linear attention reduces to a simple unweighted cumulative sum. When λ < 1 (typically 0.9–0.99), recent tokens receive higher weight than distant ones. The paper uses λ as a given constant from the model architecture; Lightning Attention-2 does not modify or learn it. The specific value used in experiments is not stated in the paper, but it's an architectural detail of TransNormerLLM.
The block-level decay uses λ^B (decay over one block length) and Λ = diag{λ^0, ..., λ^{B-1}} (position-dependent decay within a block). These are precomputed constants loaded into SRAM with the block computation. The λ^B Λ^{-1} factor in the KV update (Equation 10) is also precomputed as a diagonal matrix applied to K_i.
Why the backward pass uses λ^B Λ^{-1} rather than a different formulation:
In the forward pass KV update (reproduced from Equation 10):
The term λ^B Λ^{-1} K_{t+1} can be understood operationally. Each row r of K_{t+1} (the r-th token in the block, 1-indexed from the start of the block) needs to be decayed to the end of the block. The distance from position r (within block t+1) to the end of block t+1 (position (t+1)B) is B - r. So the decay factor for this token's contribution to KV_{t+1} should be λ^{B - r}. The diagonal matrix Λ^{-1} has entries λ^{-(r-1)}, and multiplying by λ^B gives λ^{B} · λ^{-(r-1)} = λ^{B - r + 1}, which is off by one factor of λ. Looking more carefully at the paper's definition: Λ = diag{1, λ, ..., λ^{B-1}} where Λ_{rr} = λ^{r-1} for the r-th token (1-indexed). Then Λ^{-1}_{rr} = λ^{-(r-1)} and λ^B Λ^{-1}_{rr} = λ^{B-r+1}. The distance from the r-th token to position (t+1)B is indeed B - r + 1 (if r = B, distance = 1; if r = 1, distance = B). So the factor λ^{B-r+1} is exactly correct: the first token in the block is farthest from the end, so its contribution is most decayed. This confirms the mathematical consistency of the formulation.
Memory footprint of the KV and dKV states:
The KV and dKV states are d × d matrices. In multi-head attention, each head has its own KV state, so the total persistent SRAM usage for KV states is num_heads × d_head² × 2 (for KV and dKV). For TransNormerLLM-15B with 40 heads and d_head = 128, this is 40 × 128² × 2 ≈ 1.3 million entries, or about 2.6 MB in fp16 — well within the SRAM budget of an A100's L2 cache (40 MB) or distributed across SMs. For the backward pass, the forward KV states either need to be stored (requiring T × d × d HBM storage) or recomputed during the backward pass (trading compute for memory). The paper's Algorithm 2 shows KV being recomputed during the dQ traversal, which is the standard gradient checkpointing tradeoff.
4. Key Insights and Innovations
Innovation 1: The Cumsum Bottleneck Is a Spatial Granularity Problem, Not an Algorithmic One
The paper's most fundamental conceptual contribution is a diagnostic reframing of why linear attention has failed to deliver its theoretical speedups on GPU hardware. The field has known since at least 2022 (Hua et al., 2022) that the cumulative summation operation required by causal linear attention was the practical bottleneck. The implicit assumption — visible in the design of Lightning Attention-1 and essentially all prior linear attention implementations — was that this bottleneck was inherent to the right-product formulation: if you wanted linear scaling, you had to pay the cumsum cost, and if you wanted to avoid cumsum, you had to fall back to left-product attention with its quadratic scaling.
What makes Lightning Attention-2's framing novel is recognizing that the cumsum bottleneck is not a property of the right-product computation itself but rather a property of the granularity at which the recurrence is applied. The per-token recurrence KV_t = λ·KV_{t-1} + k_t^⊤ v_t requires updating a d × d matrix at every one of n sequence positions — that's n updates to a large persistent state, each with a data dependency on the previous update. This is what makes cumsum slow: not the accumulation operation, but the frequency of the accumulation operation relative to the size of the accumulated state.
By coarsening the recurrence to block granularity — updating the KV state only once per block of B tokens rather than once per token — Lightning Attention-2 reduces the number of state updates from n to n/B (e.g., from 131,072 to 1,024 for B = 128). The cumsum bottleneck, which was previously treated as a fundamental limitation of linear attention in causal mode, is revealed to be an artifact of unnecessarily fine-grained recurrence. The paper demonstrates that the per-token recurrence can be decomposed into per-token intra-block computation (handled by left-product attention within the block, where the B × B attention matrix fits in SRAM) and per-block inter-block accumulation (handled by right-product KV updates, where the reduced update frequency makes the d × d state manipulation efficient).
This insight is more than a clever implementation trick — it changes how one thinks about the design space of efficient attention. Prior to this work, the dominant axis of innovation for linear attention was the choice of kernel function (Katharopoulos et al., 2020b; Choromanski et al., 2020; Qin et al., 2022b) or the design of positional encodings. Lightning Attention-2 introduces an orthogonal axis: the temporal granularity of the recurrent state update. This is not an incremental refinement — it's a category-opening observation that the choice of recurrence frequency is a tunable parameter that mediates the tradeoff between state update overhead and intra-block computation cost. The optimal granularity depends on hardware characteristics (SRAM size determines maximum block size B) and model dimensions (head dimension d determines state size), not on any mathematical property of the attention formulation itself.
The evidence for this reframing is the central empirical result (Figure 1, Table 1): Lightning Attention-2 achieves constant training speed as sequence length scales from 1K to 92K tokens, while both FlashAttention-2 and Lightning Attention-1 show sharply declining throughput. If the cumsum bottleneck were genuinely inherent to causal linear attention, no implementation — regardless of cleverness — could produce a flat TGS curve. The fact that a flat curve is achievable proves that the bottleneck was one of implementation strategy, not algorithmic necessity. This is a fundamental advance in understanding rather than a metric improvement, though the metric improvement (4× to 10× speedup at long sequences) is a direct consequence.
Innovation 2: Hybrid Left-Product / Right-Product as a Spatial Decomposition Strategy
The paper's second conceptual contribution is the recognition that left-product and right-product attention are not competing alternatives but complementary primitives that can be applied simultaneously within a single computation, each deployed where it is most efficient. This is a significant departure from both the theoretical linear attention literature and the systems optimization literature.
What the field assumed before: Linear attention papers (Katharopoulos et al., 2020a; Choromanski et al., 2020; Qin et al., 2022b) presented the right-product formulation Q(K^⊤ V) as the linear attention algorithm — the whole point was to replace the quadratic left-product with the linear right-product. Systems papers like FlashAttention (Dao et al., 2022; Dao, 2023) optimized the left-product QK^⊤ V for softmax attention using tiling, but treated the attention computation as a unified operation — every token attended to every other token through the same mechanism. Lightning Attention-1 applied the same philosophy to linear attention: tile the computation to improve IO-awareness, but still use a uniform left-product strategy throughout.
What Lightning Attention-2 does differently: It decomposes the sequence spatially into blocks and applies different computational strategies to different spatial scales:
- Local interactions (tokens within the same block): left-product attention, because the
B × Battention matrix is small enough to materialize in SRAM, and the quadratic cost onBis negligible whenB ≪ n. - Long-range interactions (tokens in different blocks): right-product accumulation, because the
d × dKV state compactly summarizes all previous blocks, and updating it once per block achieves linear scaling in the number of blocks.
This is not an obvious decomposition. The linear attention literature has historically treated the left-product and right-product as mathematically equivalent but computationally distinct alternatives — you choose one or the other based on whether you prioritize parallel computation (left-product) or linear scaling (right-product). The idea that you can use both within a single forward pass, switching between them based on spatial granularity, represents a genuinely novel framing of the attention computation as a multi-scale operation rather than a monolithic one.
The significance of this insight extends beyond the immediate performance gains. It suggests that efficient attention implementations should be designed not around a single algorithmic primitive but around a portfolio of primitives, each applied at the spatial or temporal scale where it is most efficient. This is analogous to how fast multipole methods in computational physics decompose interactions into near-field (computed directly) and far-field (computed via aggregated representations) — the same conceptual structure. For transformers, the intra-block computation is the "near-field" (direct pairwise attention within a local window) and the inter-block computation is the "far-field" (aggregated key-value state summarizing distant context). This framing could generalize: one could imagine hierarchical decompositions with multiple levels of aggregation, or adaptive block sizes based on attention sparsity patterns.
The paper distinguishes this approach from prior chunk-wise methods (GLA by Yang et al., 2023; RetNet by Sun et al., 2023b) by noting that those methods either apply parallel computation across all chunks (quadratic in the number of chunks — effectively left-product at the inter-chunk level) or lack IO-aware optimization and backward pass support. Lightning Attention-2 is the first method to apply algorithmically different computation to intra- and inter-block regimes while maintaining IO-awareness, forward/backward completeness, and exact mathematical equivalence to the per-token recurrence. The evidence is in Figure 3: Lightning Attention-2 achieves linear growth in runtime with sequence length for both forward and backward passes, while FlashAttention-2 shows quadratic growth. This would be impossible if inter-block interactions were computed with left-product attention.
This is best classified as a fundamental advance in algorithmic design for attention, not an incremental optimization. It redefines what "linear attention" means at the implementation level — not "always use the right product" but "use the right product for long-range aggregation and the left product for local computation."
Innovation 3: The Backward Pass as a First-Class Design Constraint for Efficient Attention
A subtler but important contribution is the paper's treatment of the backward pass as a co-equal design target, not an afterthought. Prior work on efficient attention implementations has frequently focused on the forward pass — inference speed and memory are the visible bottlenecks, and forward-pass innovations (FlashAttention's tiling, RetNet's chunk-wise recurrence) can be described and benchmarked without addressing how gradients are computed. The backward pass, when considered at all, is often handled by automatic differentiation of the forward implementation, which may be inefficient but is functionally correct.
Lightning Attention-2 elevates the backward pass to the same level of algorithmic design as the forward pass. Algorithm 2 is not simply the forward pass run in reverse through autograd — it is a separately designed algorithm with its own structure (two traversals over blocks in opposite directions), its own persistent state (the dKV accumulator, analogous to but distinct from the forward KV state), and its own intra-block / inter-block decomposition. The paper derives the backward pass from first principles (Equations 11–20), showing that the gradient flow through the linear attention recurrence requires careful handling of temporal direction: dQ depends on forward-accumulated KV state, while dK and dV depend on backward-accumulated dKV state.
Why this matters beyond the specific algorithm: The backward pass is what makes training on long sequences possible. An attention mechanism with an efficient forward pass but an inefficient backward pass cannot be used for pretraining — the backward pass dominates training time (it computes gradients for all parameters, not just the attention outputs), and memory consumption during training is dominated by activations stored for the backward pass. By designing the backward pass to have the same algorithmic complexity and IO-awareness as the forward pass, Lightning Attention-2 ensures that the efficiency gains are realized during training, not just inference.
This is a methodological contribution as much as a technical one. It establishes a design principle for future efficient attention work: the backward pass should be algorithmically designed alongside the forward pass, with explicit consideration of gradient state accumulation, temporal direction of data dependencies, and memory footprint. The paper's critique of RetNet (Sun et al., 2023b) — "does not consider IO-aware or the backward pass" — and GLA (Yang et al., 2023) — "does not consider IO-aware or the backward pass" — implicitly establishes this as a standard that future work should meet.
The evidence that this matters is in Figure 3 (right panel): Lightning Attention-2's backward pass runtime grows linearly with sequence length, matching the forward pass scaling. This linear scaling in both directions is what produces the flat TGS curves in Figure 1 — the total training time per token remains constant because both forward and backward compute per token are constant. If the backward pass scaled quadratically (as it would with an autograd fallback on a left-product implementation), the overall training speed would degrade even if the forward pass were fast. The paper's demonstration that both passes scale linearly is the proof that the method is practically viable for training, not just a forward-pass curiosity.
This innovation is best characterized as a methodological standard-setter rather than a fundamental algorithmic breakthrough — the specific backward pass algorithm is derived directly from the forward pass structure through the chain rule — but it's an important one because it defines what "solving efficient attention" means in practice: forward, backward, IO-aware, and memory-efficient, all simultaneously.
Innovation 4: Constant Training Speed as an Empirical Validation of Theoretical Complexity
The paper makes an empirical contribution that is conceptually significant beyond the specific method: it provides the first experimental demonstration that linear attention's theoretical O(n) complexity can be fully realized as O(1) per-token training time on GPU hardware for causal language modeling. This is not simply "our method is faster" — it is an existence proof that resolves a long-standing gap between theory and practice.
The gap before this work: Linear attention's theoretical complexity of O(nd²) was well-established, and several papers had demonstrated that linear attention models could achieve competitive perplexity with softmax attention models (Katharopoulos et al., 2020b; Qin et al., 2022b;a). But when practitioners ran these models on actual hardware, the wall-clock training speed did not remain constant as sequence length increased — it degraded, sometimes approaching the slope of quadratic attention despite the linear theoretical complexity. This created a credibility problem for linear attention: if the theoretical advantage doesn't materialize in practice, why bother with the architectural changes required to use linear attention instead of well-optimized softmax attention?
What Lightning Attention-2 demonstrates: Figure 1 shows three model sizes (400M, 1B, 3B parameters) where the tokens-per-GPU-per-second (TGS) metric is essentially flat from 1K to 92K sequence length for Lightning Attention-2, while FlashAttention-2 and Lightning Attention-1 show steep declines. For the 400M model, Lightning Attention-2 sustains approximately 38,000 TGS at every sequence length from 1K through 92K — the variation is within ~1% across this 92× range. Meanwhile, FlashAttention-2 drops from ~36,000 TGS at 1K to ~4,000 TGS at 92K, a 9× slowdown. Lightning Attention-1 drops from ~42,000 to ~6,000 TGS, a 7× slowdown.
This flat scaling curve is more than a speedup — it is a qualitative change in behavior. A method that gets 4× faster than a baseline at a specific sequence length is an optimization; a method whose speed is independent of sequence length is a paradigm shift. It means that, from the perspective of training cost, sequence length ceases to be a constraint — training on 100K-token sequences costs the same per token as training on 1K-token sequences. This transforms what kinds of experiments and applications are feasible: you can train on entire books rather than paragraphs, full code repositories rather than single files, complete multimodal documents rather than truncated inputs.
The conceptual significance is that this result closes the theory-practice gap for linear attention in causal settings. The paper's title calls this a "free lunch" — the ability to handle unlimited sequence lengths without sacrificing speed — and the empirical evidence supports the claim: there is no asymptotic penalty for longer sequences, even at scales (92K tokens, 3B parameters) that are practically relevant. This is a fundamentally important empirical finding because it resolves the uncertainty that has surrounded linear attention since its introduction: theoretically linear, but is it actually linear on real hardware in the setting that matters? Lightning Attention-2 answers: yes, with the right decomposition.
This innovation should be understood as an empirical proof-of-principle rather than a methodological advance — the method itself is the decomposition described in Innovation 2 — but it's a proof-of-principle with substantial field-level implications. It establishes that the research program of replacing softmax attention with linear attention is not a dead end limited by hardware inefficiencies, and that further investment in linear attention architectures (better positional encodings, learned decays, gating mechanisms) is justified because the computational benefits are now realizable.
5. Experimental Analysis
Evaluation Methodology
-
Dataset. The paper uses two distinct data configurations for evaluation. For attention module micro-benchmarks (speed and memory), no specific dataset is named — the benchmarks measure runtime and memory consumption of the attention operator itself, independent of downstream task data. For language modeling loss comparisons (Table 2, Figure 4), the authors use a "sampled corpus from our corpus with 300B tokens" and a "30B subset of our uniquely assembled corpus," respectively — both are proprietary, internally assembled training corpora whose composition is not described beyond being used to train TransNormerLLM variants. For downstream task evaluation (Table 3), the benchmarks are standard public suites: Commonsense Reasoning tasks (BoolQ, PIQA, SIQA, HellaSwag, WinoGrande, ARC easy and challenge, OpenBookQA) and Aggregated Benchmarks (MMLU, C-Eval), all evaluated using the lm-evaluation-harness framework (Gao et al., 2023).
-
Base model(s). The primary model family is TransNormerLLM (Qin et al., 2023b), a linear-attention-based architecture that uses the NormAttention mechanism described in Section 3.1. Experiments span three scales: 0.4B parameters (used in Table 2 for loss comparison, and in Table 1 and Figure 1 for speed benchmarking), 1B parameters (speed and loss comparisons), and 3B parameters (speed and loss comparisons). Section 4.3 additionally evaluates a TransNormerLLM-15B model with 42 layers, 40 attention heads, and an embedding dimension of 5120, trained on over 1.3 trillion tokens at sequence length 6,144. The comparative baseline for downstream tasks is Pythia-12B (Biderman et al., 2023). The choice of TransNormerLLM is natural because it is the linear-attention architecture developed by the same research group, and the paper's contribution is the attention kernel, not the model architecture. The specific model scale choices (0.4B, 1B, 3B) span roughly an order of magnitude, allowing assessment of whether the constant-speed property holds across model sizes.
-
Metrics. Three categories of metric are used. First, training speed is measured as Tokens per GPU per Second (TGS), computed by dividing the total number of tokens processed by the wall-clock time of training iterations. This is the primary efficiency metric and appears in Table 1 and Figure 1. Second, perplexity / language modeling loss is reported as cross-entropy loss on the training corpus, used in Table 2 and Figure 4 to verify that Lightning Attention-2 does not degrade model quality. Third, downstream task accuracy is reported on commonsense reasoning and multiple-choice benchmarks in Table 3, using standard accuracy metrics (acc, acc_norm for HellaSwag; acc for BoolQ, PIQA, WinoGrande, ARC, OpenBookQA; average across tasks for CSR and MCQ). For the attention module micro-benchmarks in Figure 3, runtime (milliseconds for forward and backward passes separately) and memory footprint (GB of GPU memory) are measured as a function of sequence length on a single A100 80G GPU.
-
Baselines. The paper compares against three categories of baseline. First, FlashAttention-2 (Dao, 2023) as implemented in LLaMA (Touvron et al., 2023a) — this represents the state-of-the-art optimized softmax attention and is denoted "LLaMA-FA2" in all tables and figures. FlashAttention-2 has quadratic theoretical complexity but is the most IO-aware and hardware-efficient softmax attention kernel available, making it a strong practical baseline despite not being a linear attention method. Second, Lightning Attention-1 (Qin et al., 2023b), the direct predecessor that solved IO-awareness for linear attention but retained quadratic complexity due to left-product computation — this is denoted "TNL-LA1" and represents the incremental improvement baseline; comparing against it isolates the contribution of the intra/inter-block decomposition. Third, for the language modeling loss comparison in Figure 4, two additional efficient architectures are included: HGRN (Qin et al., 2023d), a hierarchically gated recurrent neural network, and TNN (Qin et al., 2023a), a Toeplitz neural network — both are contemporary efficient sequence modeling approaches. For downstream task evaluation (Table 3), Pythia-12B (Biderman et al., 2023) serves as the comparison model, evaluated at two training token counts (50.3B and 100.6B) to match TransNormerLLM-15B at similar data scales (49.8B and 99.7B tokens respectively).
-
Generation budget / compute accounting. The paper does not use "generations" or sampling budgets — this is a training-time and attention-module evaluation, not an inference-time sampling analysis. Instead, the independent variable that controls computational cost is sequence length, varied from 1,024 tokens to 131,072 tokens (in powers of 2: 1K, 2K, 4K, 8K, 16K, 32K, 65K, 131K for attention module benchmarks; 1K, 2K, 4K, 8K, 16K, 32K, 65K, 82K, 94K for TGS measurements depending on model size and memory constraints). Fair comparison is ensured by measuring all methods at identical sequence lengths on identical hardware (A100 80G GPUs). The TGS metric already normalizes for sequence length by dividing tokens processed by time, so comparing TGS at different sequence lengths directly reveals whether a method's efficiency is sequence-length-dependent. The number of GPUs used varies by experiment: single A100 80G for attention module benchmarks (Figure 3), 2×A100 80G for TGS measurements (Table 1), 8×A100 80G for 0.4B training (Table 2), 16×A800 80G for 1B training, 32×A800 80G for 3B training (Figure 4), and 128×A100 80G for the overall cluster specification.
-
Cross-validation / statistical protocol. The paper conducts no cross-validation or statistical significance testing. All reported numbers in tables and figures are single-run measurements. For the 0.4B loss comparison (Table 2), both models are trained for 100,000 iterations "using the sampled corpus from our corpus with 300B tokens and initial seed" — only a single seed is used, so no measure of variance is available. The downstream task evaluation in Table 3 reports point estimates from the lm-evaluation-harness with no confidence intervals. The paper's claims about speed and memory are hardware-measured quantities that are generally low-variance, but the training loss and accuracy comparisons would benefit from multiple seeds to assess whether the reported differences (e.g., 0.001 loss difference in Table 2) are statistically reliable or within noise.
Main Quantitative Results
Attention Module Micro-Benchmarks: Speed and Memory Scaling
The headline result of Figure 3 is that Lightning Attention-2 achieves linear growth in runtime with sequence length for both forward and backward passes, while FlashAttention-2 and Lightning Attention-1 exhibit superlinear growth. Reading from the Figure 3 upper-left panel (Forward Pass):
- At 1,024 sequence length, all three methods are comparable: FlashAttention-2 at approximately 50 ms, Lightning Attention-1 at approximately 40 ms, Lightning Attention-2 at approximately 40 ms.
- At 32,768 sequence length, Lightning Attention-2 remains below 100 ms, while Lightning Attention-1 has reached approximately 200 ms and FlashAttention-2 approximately 300 ms.
- At 131,072 sequence length, Lightning Attention-2 is at approximately 200 ms, Lightning Attention-1 at approximately 600 ms, and FlashAttention-2 at approximately 1,800 ms — roughly a 9× spread.
The forward pass runtime growth is visibly sublinear for Lightning Attention-2: the curve is nearly flat from 1K to 8K, then grows gradually from 8K to 131K. In contrast, FlashAttention-2 shows the characteristic quadratic curve — runtime increases roughly as the square of sequence length beyond ~8K. Lightning Attention-1 occupies an intermediate position, growing faster than linear but slower than quadratic.
The backward pass (Figure 3, upper-right panel) shows a similar pattern but with consistently higher absolute runtimes for all methods (the backward pass is generally 2–3× more expensive than the forward pass due to computing gradients for multiple parameters and managing gradient state). At 131,072 sequence length: Lightning Attention-2 backward is approximately 600 ms, Lightning Attention-1 approximately 1,200 ms, FlashAttention-2 approximately 2,000 ms. The ratio of Lightning Attention-2 to FlashAttention-2 is approximately 3.3× for the backward pass at this sequence length, compared to approximately 9× for the forward pass — the backward pass advantage is smaller but still substantial.
Memory footprint (Figure 3, lower panels) shows a different pattern. For the forward pass (lower-left):
- Lightning Attention-2 uses approximately 4 GB at 1K sequence length, growing to approximately 12 GB at 131K.
- FlashAttention-2 starts at approximately 2 GB at 1K, growing to approximately 20 GB at 131K.
- Lightning Attention-1 occupies an intermediate position.
Lightning Attention-2's forward memory is lower than FlashAttention-2's at long sequences (12 GB vs. 20 GB at 131K), but higher at short sequences (4 GB vs. 2 GB at 1K). The backward memory (lower-right) shows similar relative ordering: Lightning Attention-2 grows from approximately 8 GB to approximately 22 GB across the sequence length range, FlashAttention-2 from approximately 4 GB to approximately 45 GB, and Lightning Attention-1 from approximately 6 GB to approximately 35 GB. The backward memory advantage for Lightning Attention-2 is substantial at long sequences: roughly 2× lower than FlashAttention-2 at 131K.
Interpretation of the linear runtime growth: The paper claims in the abstract that Lightning Attention-2 "retains consistent training and inference speed regardless of input sequence length." Figure 3's forward pass supports "approximately linear" but not "perfectly constant" — the runtime does grow from ~40 ms to ~200 ms across the 128× range of sequence lengths (1K to 131K), a 5× increase in absolute time. However, this is consistent with O(n) complexity: if the computation is O(n), then processing 128× more tokens should take approximately 128× more wall-clock time, but on a per-token basis, the time should be constant. The TGS metric (tokens per second) captures per-token efficiency and is the more appropriate measure for the "constant speed" claim, addressed in the next subsection.
Training Speed: Tokens per GPU per Second (TGS)
Table 1 and Figure 1 present the central efficiency claim: Lightning Attention-2 maintains constant TGS as sequence length scales, while both FlashAttention-2 and Lightning Attention-1 exhibit steep declines. The data in Table 1, reading the 0.4B model rows:
LLaMA-FA2 (0.4B): 35,931 TGS at 1,024 sequence length, declining monotonically to 4,078 TGS at 94,208 — a decrease of 88.6%.
TNL-LA1 (0.4B): 41,789 TGS at 1,024 sequence length, declining to 6,012 TGS at 94,208 — a decrease of 85.6%. Lightning Attention-1 is consistently faster than FlashAttention-2 at every sequence length (the gap ranges from ~16% faster at 1K to ~48% faster at 94K), but it still exhibits the same declining trend.
TNL-LA2 (0.4B): 38,615 TGS at 1,024; 38,680 at 2,048; 38,714 at 4,096; 38,172 at 8,192; 37,755 at 16,384; 37,364 at 32,768; 38,278 at 65,536; 38,457 at 81,920; 38,596 at 94,208. The variation across all sequence lengths is within ±2% of the mean. There is no discernible trend — the TGS at 94,208 is essentially identical to the TGS at 1,024.
At 94,208 sequence length, Lightning Attention-2 achieves 38,596 TGS versus FlashAttention-2's 4,078 TGS — a 9.5× speedup — and versus Lightning Attention-1's 6,012 TGS — a 6.4× speedup. At 1,024 sequence length, Lightning Attention-2 is slightly slower than Lightning Attention-1 (38,615 vs. 41,789 TGS, about 7.6% slower), suggesting that the intra/inter-block decomposition introduces some overhead that is only amortized at longer sequence lengths. The crossover point where Lightning Attention-2 surpasses Lightning Attention-1 appears to be between 2,048 and 4,096 sequence length (at 2,048: LA1 = 39,043, LA2 = 38,680; at 4,096: LA1 = 34,894, LA2 = 38,714 — Lightning Attention-2 is ~11% faster).
For the 1B model (middle section of Table 1):
- LLaMA-FA2: 14,897 TGS at 1,024, declining to 3,167 at 81,920, then OOM at 94,208 — a 78.7% decline before memory exhaustion.
- TNL-LA1: 21,195 at 1,024, declining to 4,625 at 81,920, then OOM at 94,208 — a 78.2% decline.
- TNL-LA2: 20,052 at 1,024; ranging between 19,691 and 20,186 across all lengths including 81,920. At 94,208: OOM. The TGS is essentially flat through 81,920 — the variation is within ±1.4% of the mean.
At 81,920 sequence length, Lightning Attention-2 achieves 20,186 TGS versus FlashAttention-2's 3,167 TGS (6.4× speedup) and Lightning Attention-1's 4,625 TGS (4.4× speedup). Both FlashAttention-2 and Lightning Attention-1 exhaust GPU memory at 94,208 sequence length on the 1B model, while Lightning Attention-2 also OOMs at this length — the "unlimited sequence length" claim is qualified by hardware memory constraints, as the paper notes in the introduction footnote.
For the 3B model (right section of Table 1):
- LLaMA-FA2: 7,117 at 1,024, declining to 2,558 at 32,768, then OOM beyond.
- TNL-LA1: 8,001 at 1,024, declining to 3,512 at 32,768, then OOM.
- TNL-LA2: 7,524 at 1,024; flat through 32,768 where it achieves 7,545 TGS. OOM beyond 32,768.
The OOM boundary shifts leftward as model size increases: 0.4B models fit up to 94,208 tokens; 1B models fit up to 81,920; 3B models fit up to 32,768. This is driven by total GPU memory consumption including model parameters, optimizer states, and activations, not by the attention mechanism's per-token memory. The consistent pattern is that Lightning Attention-2 sustains flat TGS up to its memory limit, while the baselines decline sharply well before hitting OOM.
Figure 1 visualizes this data as line plots with sequence length on the x-axis (log scale) and TGS on the y-axis, with three panels (400M, 1B, 3B left to right). The visual impression is striking: Lightning Attention-2 produces a nearly horizontal line in all three panels, while FlashAttention-2 and Lightning Attention-1 produce sharply declining curves. The gap between Lightning Attention-2 and the baselines widens dramatically as sequence length increases, creating a characteristic "scissors plot" where constant-speed and declining-speed lines diverge.
Language Modeling Quality: Does Lightning Attention-2 Degrade Accuracy?
Table 2 addresses whether the algorithmic changes in Lightning Attention-2 affect model quality. Both TransNormerLLM-0.4B models — one with Lightning Attention-1, one with Lightning Attention-2 — are trained for 100,000 iterations on the same 300B token corpus with the same seed. The results:
- TNL-LA1 (Lightning Attention-1): Loss = 2.229
- TNL-LA2 (Lightning Attention-2): Loss = 2.228
The difference is 0.001 in favor of Lightning Attention-2. Given that this is a single seed with no reported variance, this difference is almost certainly within noise. The paper interprets this as:
"a marginal performance difference. Specifically, the variant with Lightning Attention-2 demonstrated a performance decrement of 0.001 compared to its counterpart with Lightning Attention-1."
The interpretation is that Lightning Attention-2 produces mathematically equivalent outputs to the per-token linear attention recurrence — the decomposition is exact, not an approximation — so any difference in loss is attributable to floating-point arithmetic order effects, not algorithmic approximation. This is an important validation: the intra/inter-block decomposition does not introduce numerical error that compounds into degraded training.
Figure 4 extends this comparison to 1B and 3B model scales, plotting training loss against billions of training tokens. Four models are compared: HGRN (purple), TNN (green), LLaMA with FlashAttention-2 (orange), and TransNormerLLM with Lightning Attention-2 (red). For both the 1B and 3B scales, TNL-LA2 achieves the lowest loss among all four models throughout the 30B token training budget, though the margins are modest. At 30B tokens for the 1B models: TNL-LA2 achieves approximately 3.35 loss, LLaMA-FA2 approximately 3.42, TNN approximately 3.50, HGRN approximately 3.55. At 30B tokens for the 3B models: TNL-LA2 achieves approximately 2.69 loss, LLaMA-FA2 approximately 2.78, TNN approximately 2.82, HGRN approximately 2.88. The ranking is consistent across both scales, with TNL-LA2 showing a 0.07–0.19 loss advantage over LLaMA-FA2 and larger gaps over TNN and HGRN.
These loss comparisons are on 2K context lengths, which is important to note: they demonstrate that Lightning Attention-2 does not harm quality at standard context lengths, but they do not directly demonstrate that the constant-speed property translates to improved training efficiency at long context lengths in terms of loss-per-FLOP or loss-per-wall-clock-time. An experiment training TNL-LA2 at 32K or 64K context length and comparing wall-clock time to LLaMA-FA2 at the same context would directly demonstrate the practical training benefit, but such an experiment is not reported.
Downstream Task Evaluation: TransNormerLLM-15B
Table 3 presents benchmark results for TransNormerLLM-15B with Lightning Attention-2 at two training checkpoints (~50B and ~100B tokens) compared to Pythia-12B at similar training volumes. This is the only evaluation at the 15B scale and the only evaluation on standard NLP benchmarks rather than training loss.
At the ~50B token checkpoint:
- CSR Average: TNL-LA2 achieves 53.28 versus Pythia-12B's 51.74 — a 1.54 percentage point advantage (approximately 3% relative improvement).
- C-Eval 0-shot: TNL-LA2 = 25.55, Pythia = 22.36 (3.19 point advantage).
- MMLU 0-shot: TNL-LA2 = 26.60, Pythia = 25.80 (0.80 point advantage).
- C-Eval 5-shot: TNL-LA2 = 26.18, Pythia = 21.43 (4.75 point advantage).
- MMLU 5-shot: TNL-LA2 = 27.50, Pythia = 26.10 (1.40 point advantage).
At the ~100B token checkpoint:
- CSR Average: TNL-LA2 = 56.76, Pythia = 54.58 — a 2.18 point advantage (approximately 4% relative improvement). The largest individual gains are on HellaSwag (61.09 vs. 58.83) and ARC-challenge (34.64 vs. 31.91).
- C-Eval 0-shot: TNL-LA2 = 26.70, Pythia = 24.00 (2.70 point advantage).
- MMLU 0-shot: TNL-LA2 = 26.90, Pythia = 24.80 (2.10 point advantage).
- C-Eval 5-shot: TNL-LA2 = 25.38, Pythia = 24.45 (0.93 point advantage).
- MMLU 5-shot: TNL-LA2 = 27.40, Pythia = 24.40 (3.00 point advantage).
Several patterns emerge. First, TNL-LA2 outperforms Pythia-12B on every single metric at both checkpoints — there are no reversals or tradeoffs. Second, the gap tends to widen from the 50B to 100B checkpoint (CSR gap grows from 1.54 to 2.18 points; MMLU 0-shot from 0.80 to 2.10 points), suggesting that TransNormerLLM may have more favorable scaling dynamics, though with only two checkpoints this cannot be confidently attributed to model architecture rather than training noise. Third, the absolute performance is modest — the paper notes that both models exceed the 25% random baseline for 4-choice multiple choice, and MMLU scores around 27 are consistent with models at this scale (Pythia-12B is a known baseline with published scores, and the paper's Pythia-12B numbers serve as a sanity check that the evaluation pipeline is correctly configured).
A limitation acknowledged implicitly by the paper is that TransNormerLLM-15B training was incomplete at the time of writing:
"Given that the comprehensive pre-training phase is scheduled to span three months, we hereby present the most recent results from the latest checkpoint"
The model has processed only ~100B of a planned 1.3T+ tokens — roughly 7.7% of the planned training. The final model quality is unknown, and the current results may not be representative of convergence behavior. The paper reports this transparently, but it means the downstream evaluation is best interpreted as a "no regression" check rather than a demonstration of competitive final performance.
Ablation Studies and Robustness Checks
The paper conducts essentially no formal ablation studies on Lightning Attention-2 itself. There are no experiments varying block size B, no comparisons of different intra-block computation strategies, no analysis of numerical precision effects (fp16 vs. bf16 vs. fp32), no sensitivity analysis of the decay parameter λ, and no comparison of different tiling strategies or SRAM allocation schemes. This is a notable absence for a systems paper — the design space for the tiling decomposition (how large should B be? What is the tradeoff between intra-block cost scaling as O(B²) and inter-block state update frequency scaling as O(n/B)?) is entirely unexplored.
What the paper provides instead are comparative evaluations against alternative methods, which serve a similar function to ablations by demonstrating that the specific combination of design choices in Lightning Attention-2 outperforms methods that make different choices:
Lightning Attention-1 vs. Lightning Attention-2 (implicit ablation of right-product inter-block): The comparison between TNL-LA1 and TNL-LA2 across Table 1 and Figure 1 is effectively an ablation of the inter-block computation strategy. Lightning Attention-1 uses tiling with left-product throughout (both intra- and inter-block), while Lightning Attention-2 uses left-product intra-block and right-product inter-block. The difference in scaling behavior — declining TGS vs. constant TGS — directly attributes the linear scaling to the right-product inter-block computation. This is the closest thing to a core ablation in the paper, but it conflates the algorithmic change (left-product to right-product for inter-block) with the implementation change (Triton kernel redesign), making it impossible to attribute the improvement solely to the algorithm.
FlashAttention-2 vs. Lightning Attention-2 (implicit ablation of linear vs. softmax attention): The comparison demonstrates the practical advantage of linear attention over optimized softmax attention at long sequences, but this is more of a baseline comparison than an ablation — it validates the motivation for the entire research direction rather than informing specific design choices within Lightning Attention-2.
Quality preservation: Table 2's comparison with Lightning Attention-1 demonstrates that the algorithmic decomposition does not introduce meaningful numerical error — this is a validation that the exact mathematical equivalence is maintained in floating-point arithmetic. However, the single-seed comparison with no variance estimate weakens this claim.
Architecture comparisons in Figure 4 (HGRN, TNN): These comparisons demonstrate that TransNormerLLM with Lightning Attention-2 is competitive with other efficient architectures in terms of training loss, but provide no information about Lightning Attention-2 specifically — the attention kernel is only one component of the TransNormerLLM architecture, and the loss differences could just as easily reflect architectural differences (layer structure, normalization, feedforward design) rather than attention quality.
What is notably missing: The paper would be substantially strengthened by (1) a sweep over block sizes B = {32, 64, 128, 256} measuring TGS and memory to identify the optimal tradeoff, (2) an ablation using left-product for inter-block with the same Triton implementation to isolate the algorithmic contribution from the IO-awareness contribution, (3) precision studies showing whether fp16 accumulation of the KV state introduces numerical drift at very long sequences, and (4) profiling data (e.g., from NVIDIA Nsight) showing the fraction of time spent on intra-block computation, inter-block computation, KV state updates, and HBM/SRAM data movement, to verify that the IO-awareness claims are realized. The paper's qualitative claims about IO-awareness and memory hierarchy exploitation are not backed by quantitative profiling or bandwidth utilization measurements.
Critical Assessment
The central claim of the paper is that Lightning Attention-2 is "the first linear attention implementation that enables linear attention to realize its theoretical computational benefits" — specifically, maintaining constant training speed regardless of sequence length. The experiments genuinely demonstrate this: the TGS data in Table 1 and Figure 1 show unmistakably flat scaling for Lightning Attention-2 across a 92× range of sequence lengths (1K to 92K for the 400M model), while the baselines degrade sharply. This is a strong empirical result.
However, the paper makes several more specific claims that warrant closer scrutiny against what was actually tested.
Claim: "constant training speed" — demonstrated, with a boundary condition. The TGS for Lightning Attention-2 is flat within ±2% across all sequence lengths tested, but only up to the point where GPU memory is exhausted. The 400M model remains flat to 94,208 tokens; the 1B model to 81,920; the 3B model to 32,768. The "unlimited sequence length" in the title is thus qualified by the hardware constraint acknowledged in the introduction footnote: "the sequence length may still be limited by hardware constraints, such as the GPU memory." This qualification is important and honestly stated, but "unlimited sequence length" in the title creates an expectation of scale far beyond what is demonstrated — 94K tokens is long by current standards but is not "unlimited," and models hitting OOM at 32K (3B) or 82K (1B) on 80GB GPUs reveals that memory scaling, not just compute scaling, is a practical limit. The paper's forward-looking mention of "sequence parallelism" (Section 5) to overcome hardware constraints acknowledges this but provides no data.
Claim: "faster than other attention mechanisms" — supported for the specific baselines tested, but the baseline set is narrow. FlashAttention-2 represents the state of the art for softmax attention; Lightning Attention-1 represents the prior state of the art for linear attention. Both are appropriate and strong baselines. However, the paper does not compare against other linear attention implementations that use chunk-wise or block-parallel strategies, such as GLA (Yang et al., 2023) or the RetNet chunk-wise algorithm (Sun et al., 2023b). The "Discussion" section in 3.2.2 acknowledges these methods and asserts that Lightning Attention-2 differs by being IO-aware and handling the backward pass, but no empirical comparison is provided. Without measuring GLA or RetNet's TGS on the same hardware, the claim of being "the first" to achieve constant speed cannot distinguish between being the first to implement a known approach with IO-awareness versus being the first to conceive of the approach itself. If GLA or RetNet, when implemented in Triton with IO-awareness, also achieve flat TGS curves, then Lightning Attention-2's contribution is primarily the IO-aware Triton implementation, not the algorithmic decomposition. This would still be a valuable contribution but would shift the novelty attribution.
Claim: "significantly faster than other attention mechanisms" — the speedup magnitude is conditional on sequence length. At 1K sequence length, Lightning Attention-2 is slightly slower than Lightning Attention-1 (38,615 vs. 41,789 TGS on 400M model) and comparable to FlashAttention-2 (38,615 vs. 35,931). The dramatic speedups (9.5× over FlashAttention-2, 6.4× over Lightning Attention-1) only manifest at 94K sequence length. This means the practical benefit depends entirely on the target sequence length: for applications using 2K–4K contexts (the current dominant paradigm), the speedup is negligible or slightly negative. The paper's title emphasizes "handling unlimited sequence lengths," but the value proposition is specifically for regimes where sequence length exceeds ~4K — a regime that, while growing in importance, is not yet the standard use case. This doesn't weaken the technical contribution but does contextualize the practical impact.
Claim: "without sacrificing accuracy" — weakly supported. Table 2 shows a 0.001 loss difference on a single model at one scale with a single seed. This demonstrates that Lightning Attention-2 does not catastrophically degrade quality, but it is insufficient to claim equivalence with statistical confidence. A proper validation would include: multiple seeds, loss confidence intervals, perplexity on a held-out validation set (not just training loss), and ideally perplexity measurements at long sequence lengths where the KV state has been accumulated over many blocks, which would surface any numerical drift in the recurrence. Table 3 shows that a 15B TransNormerLLM model with Lightning Attention-2 outperforms Pythia-12B on downstream tasks, but this comparison confounds the attention mechanism with the entire model architecture, training data, and training procedure — it validates TransNormerLLM as an architecture more than Lightning Attention-2 specifically.
Missing experiment — long-sequence training efficiency: The paper's central motivation is enabling training on long sequences from scratch. Yet no experiment actually demonstrates this: Table 2 and Figure 4 train at 2K context length, and Table 3's model trains at 6,144 context length but reports only downstream accuracy, not training time or efficiency. The natural experiment would be to train two models at, say, 32K context length — one with Lightning Attention-2 and one with FlashAttention-2 — and compare both the wall-clock training time and the resulting loss/perplexity as a function of tokens processed. This would directly quantify the practical training benefit. The TGS measurements (Table 1) demonstrate that Lightning Attention-2 processes more tokens per second at long sequences, but whether this translates to faster convergence to a given loss remains unmeasured — a model with slower per-token processing might achieve lower loss per token (e.g., softmax attention might learn more efficiently than linear attention), offsetting the throughput advantage. This efficiency-quality tradeoff is central to the practical value proposition and is entirely unexplored.
Missing experiment — memory scaling with sequence length: Figure 3's lower panels show memory footprint for the attention module, but Table 1's OOM entries reveal that total GPU memory (model parameters + optimizer states + activations) is the binding constraint. An analysis decomposing memory consumption into attention-related vs. non-attention components would clarify whether Lightning Attention-2's constant memory footprint for the KV state (O(d²) regardless of sequence length) meaningfully extends the maximum trainable sequence length compared to FlashAttention-2, or whether activation memory from other layers dominates.
Missing baseline — larger model with FlashAttention-2: The paper compares equal-size models with different attention mechanisms. A complementary analysis would compare, say, a 400M TransNormerLLM with Lightning Attention-2 at long sequences against a larger (e.g., 1B) LLaMA with FlashAttention-2 at shorter sequences, to determine whether the long-sequence capability of the linear attention model compensates for any quality gap relative to a larger softmax attention model that can only handle short sequences. This tradeoff (model scale vs. context length) is practically relevant but unexplored.
The "first" claim requires qualification. Section 2.2 and the Discussion in Section 3.2.2 acknowledge that GLA and RetNet use similar chunk-wise approaches, but argue that Lightning Attention-2 is distinct in being IO-aware and handling both forward and backward passes. Without empirical comparison against these methods, the distinction rests on the paper's characterization of those methods' limitations (e.g., "GLA uses parallel computations for each block, which leads to higher memory usage"). If these characterizations are accurate, Lightning Attention-2 would indeed be the first practically constant-speed implementation; if not, the novelty is primarily in the IO-aware Triton engineering. The paper's contribution would still be significant either way — an open-source, Triton-implemented, IO-aware linear attention kernel with constant training speed is a valuable artifact regardless of algorithmic novelty — but the framing would differ.
Bottom line: The experiments convincingly demonstrate that Lightning Attention-2 achieves the primary claimed behavior — constant training speed with sequence length — for the TransNormerLLM architecture on A100 GPUs at scales up to 3B parameters and 94K tokens. The evidence for preserved accuracy is adequate but minimal, the evidence for practical training efficiency gains (loss vs. wall-clock time) is absent, and the baselines, while strong, could be broadened to include other contemporary linear attention implementations. The paper's core empirical result is solid and important; the claims around it are partially substantiated and partially extrapolated.
6. Limitations and Trade-offs
1. The "Constant Speed" Claim Holds Only While GPU Memory Lasts — and Memory Runs Out Quickly at Scale
The assumption or constraint. The paper's title and abstract promise "handling unlimited sequence lengths" and "consistent training and inference speed regardless of input sequence length." However, the authors include a crucial footnote in the introduction:
"However, the sequence length may still be limited by hardware constraints, such as the GPU memory."
This is not a minor caveat — it directly contradicts the "unlimited" claim by acknowledging that physical GPU memory imposes a hard ceiling on sequence length regardless of algorithmic efficiency. The empirical evidence in Table 1 makes this concrete: the 400M model operates successfully at 94,208 tokens, but the 1B model hits Out-Of-Memory (OOM) at this same length, and the 3B model OOMs beyond 32,768 tokens. These are not theoretical limits — they are the actual measured failure points on 80GB A100 GPUs.
The consequence. A practitioner evaluating Lightning Attention-2 for training on genuinely long sequences (hundreds of thousands to millions of tokens) would discover that the constant-speed property is only achievable up to a memory wall that moves leftward as model size increases. For the 3B model, the maximum trainable sequence length is 32,768 tokens — this is longer than typical 2K–4K contexts, but it is far from "unlimited." The paper provides no analysis of what fraction of the OOM is attributable to attention activations versus other components (model parameters, optimizer states, feedforward activations, LayerNorm statistics). If attention-related memory is a small fraction of total memory, then even a perfectly memory-efficient attention kernel cannot meaningfully extend maximum sequence length — the bottleneck lies elsewhere.
What evidence exists in the paper. Table 1 shows the OOM boundaries explicitly. The 0.4B model sustains constant TGS through 94,208 tokens; the 1B model through 81,920 tokens (OOM at 94,208); the 3B model through 32,768 tokens (OOM at 65,536). Figure 3 shows forward/backward attention module memory footprint growing with sequence length (Lightning Attention-2: forward ~4 GB to ~12 GB from 1K to 131K sequence; backward ~8 GB to ~22 GB), but this is measured in isolation for the attention module, not for a full training setup. The paper does not decompose the total GPU memory consumption during training into attention vs. non-attention components, making it impossible to determine whether Lightning Attention-2's memory efficiency for the attention computation materially extends the viable sequence length relative to FlashAttention-2 when all other memory costs are accounted for.
Mitigation status. The paper briefly states in the Conclusion that "we intend to introduce sequence parallelism in conjunction with Lightning Attention-2, which aims to facilitate the training of extra-long sequences, effectively overcoming existing hardware constraints." This is forward-looking and provides no implementation, evaluation, or even design sketch. Sequence parallelism (distributing the sequence dimension across multiple GPUs) is a well-known technique but introduces communication overhead that could compromise the constant-speed property. The paper provides no evidence that the combination of Lightning Attention-2 with sequence parallelism would preserve the flat TGS curve or be practically feasible.
2. The Accumulated KV State Is Exact in Theory, but Floating-Point Numerical Drift at Extreme Lengths Is Uncharacterized
The assumption or constraint. Lightning Attention-2's mathematical derivation (Equations 3–10) is exact — the block-level decomposition produces outputs identical to the per-token recurrence under infinite-precision arithmetic. The paper relies on this exact equivalence to claim that Lightning Attention-2 introduces no approximation error. Table 2 provides minimal evidence: a single 0.4B model trained for 100K iterations at 2K context length shows a 0.001 loss difference between Lightning Attention-1 and Lightning Attention-2, which the paper attributes to "marginal performance difference" within floating-point noise.
The consequence. The KV state in Lightning Attention-2 is accumulated iteratively — each block's contribution is added to a persistent d × d matrix, which is then repeatedly scaled by λ^B (a decay factor < 1). Over many blocks (e.g., 1,024 blocks for 131K sequence length with B = 128), this accumulation involves 1,024 successive multiply-add operations on the same d × d matrix. In floating-point arithmetic (particularly fp16 or bf16, which are standard for training efficiency), repeated accumulation can cause loss of precision — small contributions from early blocks may be lost when added to a much larger accumulated state, and the repeated decay multiplication can compound rounding errors. The result would be that early tokens in very long sequences have effectively zero contribution to later outputs, not because of the intentional λ decay, but because their contributions are numerically flushed to zero during accumulation. This is a failure mode that only manifests at sequence lengths far beyond the 2K context used in the paper's quality evaluation.
What evidence exists in the paper. None. Table 2 evaluates at 2K context length, where the number of block updates is small (e.g., 16 blocks for B = 128). Figure 4 trains at 2K context length. Table 3 evaluates a 15B model trained at 6,144 context length on downstream tasks, but reports only task accuracy, not perplexity at different context positions or any numerical analysis of KV state fidelity. The paper does not specify the floating-point precision used for the KV state accumulation, does not report whether mixed-precision training (fp16 forward/backward with fp32 master weights) applies to the attention state, and does not measure perplexity as a function of token position within long sequences to detect degradation for early tokens. A perplexity breakdown by position (e.g., comparing loss on the first 1K tokens vs. the last 1K tokens of a 64K sequence) would directly reveal whether numerical drift causes information loss for early context.
Mitigation status. Not addressed. The paper provides no analysis of numerical stability, no precision recommendations, and no ablation comparing fp16 vs. bf16 vs. fp32 KV state accumulation. This is a significant gap because linear attention's core promise — maintaining access to distant context — depends entirely on the KV state faithfully preserving information from early tokens. If numerical drift silently discards that information at long sequences, the constant-speed property is achieved at the cost of the very long-range modeling capability that motivates the approach. Future work on linear attention at extreme sequence lengths will need to characterize and mitigate this, but the paper provides no foundation for doing so.
3. The Block Size B — a Critical Hyperparameter — Is Unexplored, Leaving the Performance Model Incomplete
The assumption or constraint. The entire Lightning Attention-2 algorithm depends on a block size B that controls the tradeoff between intra-block and inter-block computation. The intra-block cost scales as O(B²d) (the left-product attention within each B × B block). The inter-block cost scales as O(nd²/B) (one KV state update per block, with T = n/B blocks). The total forward pass complexity is O(nBd + nd²/B) — the first term from intra-block attention (n/B blocks, each costing O(B²d)), the second from inter-block accumulation (n/B KV updates, each costing O(d²)). This expression has a minimum with respect to B when B ~ d, suggesting an optimal block size that balances local attention cost against state update frequency. Yet the paper provides no analysis, sweep, or even explicit specification of B.
The consequence. A practitioner implementing Lightning Attention-2 faces an unguided choice for a hyperparameter that directly controls both correctness (B determines the maximum intra-block context window for exact left-product attention) and performance (B controls the tradeoff between SRAM usage, intra-block FLOPs, and inter-block update frequency). Too small a B increases the number of blocks T = n/B, increasing the frequency of KV state updates (each of which reads and writes the d × d persistent state) and potentially making state update overhead the dominant cost. Too large a B increases the intra-block cost quadratically and risks overflowing SRAM (since the intra-block computation materializes B × B and B × d matrices). The optimal B likely depends on d (head dimension), SRAM capacity, and the relative throughput of matrix multiplication vs. element-wise operations on the specific GPU architecture. Without guidance, an implementer might choose a suboptimal B and leave substantial performance on the table, or worse, choose a B that causes SRAM spills to HBM, destroying the IO-awareness that is central to the method's speed.
What evidence exists in the paper. None. The paper does not state the block size used in any experiment. Algorithm 1 and Algorithm 2 list B as an input parameter but do not provide values or selection criteria. The "Discussion" section in Section 3.2.2 compares Lightning Attention-2 to GLA and RetNet on algorithmic grounds but provides no quantitative characterization of the B-dependent performance profile. The TGS data in Table 1 implicitly reflects whatever B was chosen, but since B is unknown, the results cannot be interpreted in terms of the algorithmic tradeoff — we cannot distinguish between "Lightning Attention-2 is fast because the algorithm is good" and "Lightning Attention-2 is fast because B was well-tuned for these specific models and sequence lengths."
Mitigation status. Not addressed. The paper does not acknowledge B as a tunable hyperparameter, does not discuss the B-dependence of the complexity model, and leaves no guidance for practitioners. A sweep over B = {32, 64, 128, 256} measuring TGS and memory at multiple sequence lengths would provide the empirical foundation for a block size selection heuristic. Without this, the method is less reproducible and less practically useful than it could be.
4. The "First-to-Achieve" Claim Rests on Unvalidated Characterizations of Prior Work, Not Empirical Comparisons
The assumption or constraint. The paper repeatedly claims to be "the first linear attention implementation that enables linear attention to realize its theoretical computational benefits" (abstract). It distinguishes Lightning Attention-2 from prior chunk-wise methods — specifically Gated Linear Attention (GLA, Yang et al., 2023) and RetNet (Sun et al., 2023b) — by asserting that those methods do not achieve the same constant-speed property due to specific limitations. For GLA, the paper states it "uses parallel computations for each block, which leads to higher memory usage" and implies it lacks IO-awareness. For RetNet, the paper acknowledges a similar chunk-wise forward pass but states it "does not consider IO-aware or the backward pass."
The consequence. If these characterizations of prior work are accurate, Lightning Attention-2 makes a genuine algorithmic contribution — the first method to combine block-wise recurrence with IO-awareness and backward pass support. But if GLA or RetNet, when implemented with comparable engineering effort (Triton kernels, IO-aware tiling), could also achieve constant training speed, then Lightning Attention-2's contribution is primarily the engineering artifact (the Triton implementation) rather than a novel algorithmic insight. This distinction matters for both intellectual credit and practical guidance: if the key insight is algorithmic (intra/inter-block decomposition), future work should attribute the idea to this paper; if the key insight is that linear attention can be made fast with IO-awareness and any reasonable chunk-wise decomposition works, then the credit should be shared with prior chunk-wise methods, and the practical takeaway is "implement your chunk-wise linear attention in Triton with IO-awareness" rather than "use this specific decomposition."
What evidence exists in the paper. The paper provides no empirical comparison against GLA or RetNet. The characterizations in the Discussion section of 3.2.2 are qualitative and unsubstantiated. There is no measurement of GLA's TGS scaling, no analysis of its memory usage, and no demonstration that it fails to achieve constant speed. Similarly, RetNet's backward pass limitation is asserted but not demonstrated — the paper does not evaluate whether RetNet's autograd backward pass (as implemented in its open-source release) has different scaling behavior from Lightning Attention-2's hand-designed backward pass. The paper's baselines are limited to FlashAttention-2 (softmax attention) and Lightning Attention-1 (the direct predecessor), both of which the paper convincingly outperforms, but neither of which represents the closest prior art in chunk-wise linear attention.
Mitigation status. Not addressed. The paper does not acknowledge the absence of GLA/RetNet comparisons as a limitation, does not explain why they were excluded, and does not suggest future work to benchmark against them. The "first" claim remains an assertion about prior work's inadequacy rather than a demonstrated fact. To be fair, GLA was a concurrent preprint and may not have had a stable open-source implementation at the time of Lightning Attention-2's development, making direct comparison difficult. But the paper should acknowledge this uncertainty rather than implying the comparison was made.
5. Long-Sequence Training Efficiency Is Demonstrated Only as Throughput, Not as Convergence Speed or Model Quality
The assumption or constraint. The paper's core value proposition is enabling training on long sequences from scratch. The evidence for this consists entirely of (1) TGS measurements showing constant per-token throughput at long sequence lengths (Table 1, Figure 1) and (2) a 0.001 loss difference relative to Lightning Attention-1 at 2K context length (Table 2). The paper does not train any model at long sequence lengths and measure the resulting model quality, perplexity, or downstream task performance relative to a baseline trained at the same long context length with a competing attention method.
The consequence. A practitioner deciding whether to adopt Lightning Attention-2 for long-context pretraining faces an evidence gap: higher throughput (tokens per second) does not guarantee faster convergence to a target loss or better final model quality. It is possible that linear attention learns less efficiently per token than softmax attention — the absence of the softmax nonlinearity and the use of exponential decay rather than learned attention weights might mean that more tokens must be processed to achieve the same modeling capability. If linear attention requires, say, 2× more tokens to reach the same perplexity as softmax attention, a 4× throughput advantage would still yield a net 2× wall-clock speedup, which would be valuable but less dramatic than the throughput numbers alone suggest. Conversely, if linear attention requires 10× more tokens (an extreme scenario), the throughput advantage could be entirely negated.
Similarly, training at longer context lengths does not automatically produce better long-context modeling. The model might learn to ignore distant context (relying on the λ decay to effectively truncate attention), in which case training at 32K context length might produce a model no better at long-range reasoning than one trained at 4K. Without evaluating perplexity or downstream task performance as a function of context position (e.g., perplexity on tokens at position 30K within a 32K sequence vs. position 1K), there is no evidence that the theoretical ability to attend over long contexts translates to actual long-range learning.
What evidence exists in the paper. Table 2 compares Lightning Attention-1 and Lightning Attention-2 at 2K context length — this validates correctness but says nothing about long-sequence training benefits. Figure 4 compares multiple architectures at 1B and 3B scales at 2K context length — same issue. Table 3 evaluates a 15B model trained at 6,144 context length, but reports only aggregate downstream task accuracy, not perplexity by position or long-range reasoning benchmarks that would isolate the benefit of training on longer contexts. The paper provides no experiment where sequence length is varied (e.g., train models at 2K, 8K, 32K contexts all other things equal) and both wall-clock time and model quality are measured.
Mitigation status. Not addressed. The paper does not frame this as a limitation or propose future experiments to close the gap. The Conclusion focuses on extending sequence length further via sequence parallelism rather than on validating that longer sequences actually improve model quality in proportion to the additional compute. This is the most significant practical gap in the paper's evaluation, because it leaves open the question of whether Lightning Attention-2's impressive throughput at long sequences translates to practical training benefits that justify the architectural commitment to linear attention over optimized softmax attention.
6. The Generalization of Results Beyond TransNormerLLM and MATH-Style Tasks Is Unknown
The assumption or constraint. All experiments are conducted exclusively with the TransNormerLLM architecture using the NormAttention variant of linear attention (Equation 1). The paper does not evaluate Lightning Attention-2 with other linear attention variants (e.g., the 1+elu activation from Katharopoulos et al., 2020b; the cosine-based approximation from Qin et al., 2022b; the random feature approach from Peng et al., 2021), nor does it apply the tiling strategy to other model architectures that use linear attention (e.g., RetNet, RWKV, Mamba-style state-space models). All language modeling and downstream task evaluations use a proprietary, undescribed training corpus; no standard benchmarks like The Pile, C4, or WikiText are reported. The only public benchmark evaluation is on commonsense reasoning and multiple-choice tasks in Table 3, which are standard but represent a narrow slice of LLM capabilities.
The consequence. The constant-speed property demonstrated in the paper may be specific to TransNormerLLM's particular linear attention formulation. The NormAttention mechanism (which eschews softmax entirely in favor of a simple dot-product attention with normalization) is one of many linear attention variants, and the efficiency of the intra/inter-block decomposition may depend on features of this formulation — the specific form of the decay factor λ, the absence of a kernel function, the use of LayerNorm on the output. Other linear attention mechanisms might introduce operations that break the clean separation between intra-block and inter-block computation (e.g., data-dependent gating that couples the recurrence state to token-level features), or might require additional normalization that changes the memory access pattern. Without evaluating the approach on multiple linear attention architectures, the paper cannot claim to have solved the cumsum problem for linear attention in general.
Additionally, the single architecture, single corpus, and limited benchmark coverage mean the results may not transfer to other domains (code generation, multilingual text, scientific reasoning) or other model families. The downstream evaluation in Table 3 shows TransNormerLLM-15B outperforming Pythia-12B, but this comparisons confounds the attention mechanism with the entire model architecture, training data, and tokenizer — we cannot attribute the gains to Lightning Attention-2 specifically.
What evidence exists in the paper. All experiments use TransNormerLLM. Table 2, Figure 4, and Table 3 all report results for this single architecture family. The attention module micro-benchmarks in Figure 3 are synthetic (measuring runtime and memory of the attention operation in isolation) and do not validate the tiling approach with different linear attention formulations. The paper does not provide ablation experiments showing that the constant-speed property is robust to changes in the linear attention mechanism (e.g., different activation functions, different decay schemes).
Mitigation status. Not addressed. The paper does not claim generality beyond TransNormerLLM, but nor does it explicitly constrain its claims to this architecture. The abstract states "Lightning Attention-2, the first linear attention implementation that enables linear attention to realize its theoretical computational benefits" — this implies applicability to linear attention broadly, not just to one specific variant. The paper does not suggest future work to validate the approach on other linear attention architectures, nor does it discuss which properties of NormAttention the tiling strategy depends on. Practitioners using different linear attention mechanisms (RetNet with its multi-scale decay, Mamba with its selective state space, RWKV with its token-shift and channel-mixing) cannot assume the gains transfer without explicit validation.
7. Implications and Future Directions
How This Work Changes the Landscape
Lightning Attention-2 changes the landscape for efficient transformer research not by proposing a new theoretical mechanism — linear attention has existed since 2020 — but by closing the theory-practice gap that has prevented linear attention from being practically viable for long-sequence training in the causal setting. This is primarily a systems and engineering breakthrough with conceptual ramifications, rather than a new mathematical insight: the core algorithmic idea (intra-block left-product, inter-block right-product) is a spatial decomposition of a known computation, and its significance lies in demonstrating that this decomposition makes the theoretical O(n) complexity realizable on actual hardware for the first time.
The shift this causes can be understood along three dimensions:
First, it removes the central objection to linear attention as a research program. Since 2022, when Hua et al. identified the cumsum bottleneck, a reasonable skeptic could argue that linear attention's theoretical advantage was illusory — that the recurrent KV state, while mathematically elegant, created computational patterns that were fundamentally hostile to GPU execution, and that the constant factors would always favor highly-optimized softmax attention (FlashAttention) at practical sequence lengths. Lightning Attention-2 refutes this definitively. The flat TGS curves in Figure 1 — 38,000 TGS at 1K, 38,000 TGS at 92K — are an existence proof that linear attention can be implemented with genuinely constant per-token cost on GPU hardware. This changes the burden of proof: the question is no longer "can linear attention be made fast?" but "how do we build models that fully exploit linear attention's now-demonstrated efficiency?"
This makes linear attention architectures (TransNormerLLM, RetNet, RWKV, Mamba, GLA) a substantially more attractive research bet than they were before. Prior to this paper, a team choosing between investing in softmax attention + FlashAttention engineering versus linear attention + custom kernels faced genuine uncertainty about whether linear attention could ever catch up in wall-clock speed. The paper's evidence — 9.5× faster than FlashAttention-2 at 94K sequence length on a 400M model, 6.4× faster at 82K on a 1B model — strongly suggests that for long-sequence regimes, linear attention is not merely competitive but dominant, and the gap widens with sequence length. This should redirect engineering effort toward linear attention kernels and architectures.
Second, it reframes the cumsum problem as one of granularity, not algorithmic structure. The paper's key diagnostic move — recognizing that cumsum is slow not because accumulation is inherently expensive, but because it was being performed at per-token granularity — changes how one thinks about designing recurrent computations for GPUs. The insight that coarsening the recurrence to block granularity eliminates the bottleneck while preserving correctness applies far beyond linear attention. Any model with a sequential state update (state-space models, recurrent neural networks, linear RNNs) faces the same tension between the mathematical convenience of per-token recurrence and the hardware inefficiency of fine-grained state manipulation. Lightning Attention-2 provides a template: use the per-token recurrence locally (within blocks that fit in SRAM, where state updates are cheap because the state is small relative to block size) and a coarsened recurrence globally (across blocks, where the number of updates is n/B rather than n). This is a design pattern that could be applied to Mamba's selective state-space recurrence, RWKV's token-shift mechanism, or any architecture where state is a d × d or d × d_state matrix.
Third, it establishes backward-awareness as a first-class requirement for efficient attention. The paper's critique of RetNet — "does not consider IO-aware or the backward pass" — and GLA — "does not consider IO-aware or the backward pass" — implicitly defines a standard: a complete solution must handle forward, backward, IO, and memory efficiency simultaneously. This is methodologically important because the field has historically tolerated forward-only demonstrations (e.g., inference optimizations that don't support training) or backward passes handled by autograd (which may be correct but inefficient). Lightning Attention-2's hand-designed backward pass, with its two traversals and dKV accumulator, shows that the backward pass requires as much algorithmic design as the forward pass when the computation involves bidirectional state dependencies (KV going forward, dKV going backward). Future efficient attention proposals that ignore the backward pass will need to justify why, rather than treating it as an afterthought.
It also resolves a tension in the literature around linear attention's practicality. Prior to this work, the state of evidence was contradictory: linear attention papers claimed O(n) complexity and demonstrated competitive perplexity, but empirical observations from practitioners often showed disappointing wall-clock speeds, especially in causal mode. Hua et al. (2022) had explicitly identified cumsum as the problem, but Lightning Attention-1 (the prior state-of-the-art) hadn't solved it — it achieved IO-awareness but retained quadratic complexity by using left-product throughout. The field faced a "yes it works / no it doesn't" stalemate. Lightning Attention-2 resolves this by showing that the negative observations were accurate — prior implementations were bottlenecked — but that the bottleneck was implementation-specific, not fundamental. This reconciliation is valuable because it allows the community to move from debate about whether linear attention can work to research on how to use it best.
However, the magnitude of the shift should be calibrated carefully. This is not a paradigm shift in the sense of attention mechanisms — it does not introduce a new attention formulation, a new class of architectures, or a new learning principle. It is closer to the contribution of FlashAttention: a systems breakthrough that makes an existing algorithmic idea practical at scale, thereby redirecting research investment and enabling new applications. FlashAttention made quadratic softmax attention fast enough to power the GPT-4 era; Lightning Attention-2 makes linear attention fast enough that it could power a next generation of natively long-context models. The appropriate analogy is that FlashAttention is to softmax attention what Lightning Attention-2 is to linear attention — the implementation that unlocks the approach's potential.
Some research directions become more attractive in light of this result:
- Architecture co-design with linear attention kernels. Now that a performant kernel exists, optimizing model architectures specifically for linear attention's computational properties (head dimension, decay parameterization, gating mechanisms) becomes higher-leverage, because architecture improvements can be evaluated at realistic long-sequence scales.
- Training from scratch on very long contexts. The paper's capability demonstration is throughput, not long-context training itself; actually training models on book-length or codebase-length sequences from scratch becomes feasible and can test whether native long-context pretraining yields qualitatively different capabilities.
- Distributed sequence parallelism for linear attention. The paper acknowledges OOM as a constraint and points to sequence parallelism; sequence-parallel linear attention has different communication patterns than sequence-parallel softmax attention (the KV state, being
d × d, is much smaller than the attention matrix), which may enable more efficient distribution strategies.
Some directions become less urgent:
- Further optimization of left-product tiling for linear attention. Lightning Attention-1 represented this approach; Lightning Attention-2 shows it's fundamentally limited by quadratic inter-block cost. Research effort should shift to block-recurrent decompositions rather than continued refinement of left-product tiling.
- Kernel function design as the primary axis of innovation. The paper's results suggest that for linear attention, implementation efficiency (how you structure the computation) matters far more for practical speed than the specific choice of kernel function (1+elu vs. cosine vs. identity), since all kernel functions face the same cumsum problem and benefit from the same decomposition.
Follow-Up Research This Work Enables
Characterize numerical stability of block-recurrent KV accumulation at extreme sequence lengths, and design mitigation strategies if needed. The paper provides no analysis of whether the iterative KV state accumulation — KV_{t+1} = λ^B KV_t + (λ^B Λ^{-1} K_{t+1})^⊤ V_{t+1} repeated thousands of times — remains numerically faithful in fp16/bf16 at sequence lengths beyond 131K tokens. A concrete experiment would train a TransNormerLLM model at 2K, 8K, 32K, and 131K context lengths (all with Lightning Attention-2) and measure perplexity as a function of token position within the sequence. If early tokens in 131K sequences show elevated perplexity compared to the same tokens in 2K sequences (where the KV state is reset more frequently), that indicates information loss from numerical drift. If confirmed, mitigations include fp32 KV state accumulation (at additional memory and bandwidth cost), periodic KV state renormalization, or modified decay schedules that bound the dynamic range of the accumulated state. This is newly tractable because Lightning Attention-2 makes training at 131K context length feasible — prior implementations would have been impractically slow.
Quantify the training-efficiency-quality tradeoff between linear and softmax attention at long context lengths. The paper demonstrates that Lightning Attention-2 processes more tokens per second than FlashAttention-2 at long sequences, but does not measure whether linear attention learns as efficiently per token. A controlled experiment would train two models of equal parameter count (e.g., 1B parameters) on the same corpus at 32K context length — one TransNormerLLM with Lightning Attention-2, one LLaMA with FlashAttention-2 — and measure both wall-clock time to reach a target validation perplexity and the final perplexity. If linear attention requires more tokens to reach the same perplexity (e.g., because the exponential decay is less expressive than learned softmax attention weights), the throughput advantage is partially offset. The experiment would provide a single multiplier (e.g., "linear attention achieves 4× throughput but requires 1.3× more tokens, yielding 3.1× effective speedup") that practitioners can use for cost modeling. This is newly tractable because Lightning Attention-2 makes 32K-context training for a 1B model practical on a modest GPU budget.
Benchmark Lightning Attention-2 against GLA and RetNet chunk-wise implementations to determine whether the constant-speed property is uniquely enabled by the intra/inter-block decomposition or is achievable by any chunk-wise linear attention with sufficient IO-engineering. The paper claims to be "the first" but provides no empirical comparison against its closest prior art. A definitive experiment would implement three attention kernels in the same framework (Triton, same hardware, same precision) — Lightning Attention-2, GLA's Block-Parallel Algorithm, and RetNet's chunk-wise retention — and measure TGS scaling from 1K to 131K on identical model architectures. If all three achieve flat TGS curves, the algorithmic novelty of Lightning Attention-2 is diminished and the contribution is primarily in IO-aware engineering; if only Lightning Attention-2 is flat (GLA is quadratic due to parallel chunk interactions, RetNet degrades due to backward pass inefficiency), the paper's algorithmic contribution is validated. This experiment would also produce a Rosetta Stone for chunk-wise linear attention implementations, helping the community understand which design choices matter most. It is enabled by Lightning Attention-2's open-source Triton implementation, which provides a reference for what well-engineered linear attention looks like.
Generalize the intra/inter-block decomposition to data-dependent gating mechanisms, as in GLA and Mamba. Lightning Attention-2's decomposition relies on the decay factor λ being a constant scalar — this makes the block-level recurrence KV_{t+1} = λ^B KV_t + ... simple and precomputable. Modern linear attention variants (GLA, Mamba) use data-dependent gating where the decay varies per token and per channel, making the recurrence state-dependent and the block-level aggregation non-trivial. A research question is whether the intra/inter-block decomposition can be extended to these settings — perhaps by using an approximate block-level decay (e.g., the geometric mean of per-token decays within the block) for the inter-block term, with the exact per-token decay applied within the intra-block term, turning Lightning Attention-2 into an approximation rather than an exact algorithm. A concrete experiment would implement Lightning Attention-2 for GLA with approximate block-level decay, measure the approximation error (L2 distance between approximate and exact outputs) as a function of block size and sequence length, and determine whether the approximation error remains below training noise levels for practical configurations. This would determine whether the Lightning Attention-2 approach generalizes beyond constant-decay linear attention or is specific to that setting.
Design and evaluate sequence-parallel training protocols specialized for block-recurrent linear attention. The paper's OOM boundaries in Table 1 (3B at 32K, 1B at 82K) show that GPU memory, not compute, is the binding constraint for long sequences. Sequence parallelism — distributing the sequence dimension across GPUs — is the natural solution, but standard sequence parallelism for softmax attention involves all-to-all communication of the n × n attention matrix, which is expensive. Linear attention with Lightning Attention-2's decomposition has a more favorable communication pattern: each GPU can independently process its assigned sequence chunk, accumulating a local KV state, and only the d × d KV state (not the full attention matrix) needs to be communicated between GPUs to maintain the global recurrence. A concrete experiment would train a 7B model at 131K sequence length distributed across 8 GPUs using sequence parallelism with Lightning Attention-2, measure the scaling efficiency (TGS as a function of GPU count), and identify the communication bottleneck. This is a natural extension of the paper's stated future direction and would directly address the OOM constraint that currently limits sequence length.
Stress-test whether native long-context pretraining with Lightning Attention-2 produces measurably better long-range reasoning than short-context pretraining with length extrapolation. The paper's motivation is enabling training on long sequences from scratch, but it provides no evidence that doing so actually improves model capabilities. A rigorous test would pretrain two TransNormerLLM models to equal token counts but different context lengths — e.g., 2K context on 100B tokens vs. 32K context on 100B tokens (with appropriately chunked data so total tokens match) — and evaluate on long-range reasoning benchmarks: SCROLLS, NarrativeQA, Zero-SCROLLS, or synthetic tasks requiring retrieval of information from specific positions within long documents. If the 32K-trained model substantially outperforms the 2K-trained model on these benchmarks (beyond what would be expected from the 2K model with a length-extrapolation technique like Position Interpolation), it validates the core premise that native long-context training matters. If performance is similar, it suggests that current architectures don't exploit long contexts even when trained on them, which would redirect research toward architectural innovations that encourage long-range attention utilization rather than kernel optimization.
Implement Lightning Attention-2 for the FlashAttention-2 API to enable drop-in replacement in existing transformer codebases. The current implementation is embedded in the TransNormerLLM codebase and uses TransNormer-specific attention mechanics (NormAttention, the decay factor λ). A useful engineering contribution would be a standalone Lightning Attention-2 kernel that implements the standard scaled_dot_product_attention interface (accepting Q, K, V tensors with optional causal mask) but uses the intra/inter-block decomposition internally, with the decay factor λ exposed as a configurable parameter or learnable per-head parameter. This would allow researchers using standard transformer libraries (HuggingFace, PyTorch) to swap softmax attention for Lightning Attention-2 with a single line change, dramatically lowering the barrier to experimentation with linear attention at long contexts. The paper's Triton implementation provides the reference; the engineering question is how to handle the architectural differences (no softmax, presence of decay, NormAttention's output normalization) in a way that integrates cleanly with existing model code.
Practical Applications and Downstream Use Cases
Training LLMs on book-length and codebase-length contexts from scratch. The most direct application enabled by Lightning Attention-2 is the ability to pretrain language models on full-length documents without truncation or chunking. For legal document analysis, a model pretrained on entire contracts (50K–100K tokens) rather than 2K-chunked versions would learn dependencies that span the full document structure. The paper's throughput numbers (38,000 TGS on 400M model at 92K context, constant across all lengths) mean that pretraining on 100K-token sequences costs the same per token as pretraining on 1K-token sequences — the decision to use long contexts becomes a data-engineering choice rather than a cost-engineering choice. For a concrete deployment: a 1B-parameter TransNormerLLM trained on 100B tokens at 32K context length would require approximately 1,250 GPU-hours on A100s (using the paper's ~20,000 TGS figure for 1B at 32K), compared to perhaps 4,000 GPU-hours with FlashAttention-2 at the same context length where TGS drops to ~5,000. The 3×+ reduction in training cost could make long-context pretraining economically viable for teams that previously couldn't afford it.
Real-time inference over streaming data with state reuse. A deployed chatbot or document analysis system that processes a long conversation history or a growing document can exploit Lightning Attention-2's KV state persistence. During autoregressive generation, the KV state (d × d per head) encapsulates all previous context; when a new user message arrives, rather than recomputing attention over the entire conversation history from scratch (quadratic cost in conversation length), the system can load the saved KV state and continue generation with O(d²) per-token cost. The paper's forward pass runtime of ~200 ms at 131K sequence length (Figure 3) already includes the blocking overhead; a production inference system that caches KV states between user turns could achieve latency that is independent of conversation length. For a 100-turn conversation where each turn averages 200 tokens, this reduces per-turn attention cost from O(20,000²) to O(128²) per token (where d=128), a speedup that grows with conversation length. The constant-speed property ensures that even conversations spanning hours of interaction remain computationally tractable.
Large-scale multimodal pretraining where visual tokens dominate sequence length. Multimodal models that process high-resolution images or video generate enormous token counts — a single 4K video frame can produce thousands of visual tokens, and a minute of video at 1 FPS generates 60 frames × thousands of tokens = sequence lengths easily exceeding 100K. Lightning Attention-2's constant TGS at these sequence lengths (validated up to 94K at 400M, 82K at 1B) means that adding more visual tokens or more frames does not increase the per-token attention cost — the attention computation remains constant-speed regardless of whether the sequence contains 1,000 text tokens or 100,000 visual tokens. This removes a major cost barrier to scaling multimodal pretraining to higher resolutions, longer videos, or richer visual representations. A practical deployment scenario: a video-language model that processes 10-minute lecture videos (600 frames × 256 visual tokens/frame = 153,600 visual tokens, plus text) would be infeasible with quadratic attention but becomes trainable with Lightning Attention-2 at the same per-token cost as processing a single image. The paper's results don't directly evaluate this use case (all experiments are text-only), but the attention module micro-benchmarks in Figure 3 demonstrate the necessary scaling behavior — runtime grows linearly with sequence length rather than quadratically — which is the prerequisite for multimodal long-sequence training.