cs.LGSep 21, 2026

FlashBoB: I/O-Efficient Exact Backward-over-Backward for Softmax Attention

Authors: Anthony GivansMichael CrawshawMingrui Liu

Abstract

Transformer models built on the attention mechanism have become a central building block in modern deep learning, yet softmax attention remains a major bottleneck for long-context workloads. While FlashAttention makes the forward and first backward passes I/O-efficient, it does not support backward-over-backward (BoB), which enables exact differentiation through the backward pass for applications such as second-order optimization, test-time training, gradient-based memory, and meta-learning. Existing BoB implementations either materialize large intermediate tensors or exhaust GPU memory at long sequence lengths. We present FlashBoB, an exact, I/O-efficient algorithm for BoB in softmax attention that keeps computation within on-chip tiles and avoids all N×NN \times N intermediate tensors, where NN is the sequence length. The key insight is a hierarchical affine structure in the softmax double backward: two row-wise scalars determine all outputs through affine transformations. This yields a two-pass schedule with bounded on-chip static random-access memory (SRAM) usage and minimal off-chip high-bandwidth memory (HBM) traffic. FlashBoB achieves Θ(N2d2/M)Θ(N^2 d^2/M) HBM traffic (dd is the head dimension and MM is the memory size) and, within the standard FlashAttention-style score-recomputation model, matches the inherited large-cache lower bound for exact forward attention. Empirically, it scales exact attention BoB to N=262KN=262\text{K} on a single A100 80GB GPU, where prior PyTorch exact baselines fail by N=16KN=16\text{K}, and is up to 6.3×6.3\times faster than FlashBack. These results make exact second-order attention practical at long-context sequence lengths where prior implementations cannot run efficiently.

Explore similar work

Apr 26, 2026cs.LG

ELSA: Exact Linear-Scan Attention for Fast and Memory-Light Vision Transformers

Existing attention accelerators often trade exact softmax semantics, depend on fused Tensor Core kernels, or incur sequential depth that limits FP32 throughput on long sequences. We present \textbf{ELSA}, an algorithmic reformulation of online softmax attention that (i)~preserves exact softmax semantics in real arithmetic with a \emph{provable} O(ulogn)\mathcal{O}(u\log n) FP32 relative error bound; (ii)~casts the online softmax update as a prefix scan over an associative monoid (m,S,W)(m,S,W), yielding O(n)O(n) extra memory and O(logn)O(\log n) parallel depth; and (iii)~is Tensor-Core independent, implemented in Triton and CUDA C++, and deployable as a \emph{drop-in replacement} requiring no retraining or weight modification. Unlike FlashAttention-2/3, which rely on HMMA/GMMA Tensor Core instructions and provide no compatible FP32 path, ELSA operates identically on A100s and resource-constrained edge devices such as Jetson TX2 -- making it the only hardware-agnostic exact-attention kernel that reduces parallel depth to O(logn)O(\log n) at full precision. On A100 FP32 benchmarks (1K--16K tokens), ELSA delivers 1.31.3--3.5×3.5\times speedup over memory-efficient SDPA and 1.971.97--2.27×2.27\times on BERT; on Jetson TX2, ELSA achieves 1.51.5--1.6×1.6\times over Math (64--900 tokens), with 17.817.8--20.2%20.2\% throughput gains under LLaMA-13B offloading at \ge32K. In FP16, ELSA approaches hardware-fused baselines at long sequences while retaining full FP32 capability, offering a unified kernel for high-precision inference across platforms. Our code and implementation are available at https://github.com/ming053l/ELSA.
Chih-Chung Hsu, Xin-Di Ma, Wo-Ting Liao +1
Apr 16, 2026cs.LG

AdaSplash-2: Faster Differentiable Sparse Attention

Sparse attention has been proposed as a way to alleviate the quadratic cost of transformers, a central bottleneck in long-context training. A promising line of work is αα-entmax attention, a differentiable sparse alternative to softmax that enables input-dependent sparsity yet has lagged behind softmax due to the computational overhead necessary to compute the normalizer ττ. In this paper, we introduce AdaSplash-2, which addresses this limitation through a novel histogram-based initialization that reduces the number of iterations needed to compute ττ to typically 1--2. The key idea is to compute a coarse histogram of attention scores on the fly and store it in on-chip SRAM, yielding a more accurate initialization that enables fast forward and backward computation. Combined with a sparsity-aware GPU implementation that skips zero blocks with low overhead, AdaSplash-2 matches or improves per-step training time relative to FlashAttention-2 when block sparsity is moderate-to-high (e.g., >>60%), which often occurs at long-context lengths. On downstream tasks, models trained with our efficient αα-entmax attention match softmax baselines at short-context lengths and achieve substantial gains in long-context settings.
Nuno Gonçalves, Hugo Pitorro, Vlad Niculae +4
May 22, 2026cs.LG

Approaching I/O-optimality for Approximate Attention

We revisit the I/O complexity of attention in large language models. Given query-key-value matrices Q,K,VRn×dQ,K,V\in\mathbb{R}^{n\times d}, and a machine with fast memory size MM, the goal is to compute the "attention matrix" A=softmax(QK/d)VA=\text{softmax}(Q K ^{\top}/\sqrt{d}) V with the minimal number of data transfers between fast and slow memory. Existing methods in the literature, most notably FlashAttention and its variants, incur an I/O cost that depends quadratically on nn, while a trivial lower bound only requires Ω(nd)Ω(nd) I/O's to read the inputs and write the output. In this work, we present a technique for computing attention where the I/O cost only depends almost-linearly on nn in most parameter regimes. This is achieved by developing I/O-efficient algorithms inspired by the recent approximate attention framework of Alman and Song. We also prove corresponding lower bounds in each parameter regime to show that our algorithms are indeed close to I/O-optimal.
Pál András Papp, Aleksandros Sobczyk, Anastasios Zouzias