Papers
Topics
Authors
Recent
Search
2000 character limit reached

Thinformer Express: Streaming Causal Attention

Updated 23 June 2026
  • Thinformer Express is a causal attention approximation algorithm that converts non-causal models into streaming ones through a proven sub-Gaussian thinning and meta-procedure.
  • It achieves an approximation error of O(log^(3/2)n/s) with O(s) memory and compressed computational overhead, supporting efficient long-context processing.
  • Its Triton-optimized implementation delivers significant speedups over methods like FlashAttention 2 and HyperAttention for prefill, KV-cache compression, and compute-constrained decoding.

Thinformer Express is a causal attention approximation algorithm that combines the state-of-the-art Thinformer thinning procedure with the Express meta-procedure for converting non-causal attention approximations into streaming, causal ones, while maintaining strong theoretical error guarantees. The method achieves uniform ε=O(log3/2n/s)\varepsilon = O(\log^{3/2} n / s) approximation error, O(s)O(s) memory, and O(s2log2n)O(s^2 \log^2 n) compression overhead for a sequence of length nn. Its highly optimized implementation in Triton delivers significant speedups compared to prior state-of-the-art methods such as FlashAttention 2 and HyperAttention, supporting efficient deployment for long-context prefill, KV-cache compression, and memory-/compute-constrained decoding workloads (Gong et al., 9 Jun 2026).

1. Problem Statement and Theoretical Foundations

Causal attention, foundational to sequence modeling, requires restricting each position jj to attend only to prior or current positions (iji\leq j). For query–key–value triplets (qi,ki,vi)Rd×Rd×Rd(q_i, k_i, v_i)\in \mathbb{R}^d\times\mathbb{R}^d\times\mathbb{R}^d, the exact masked (causal) attention output for qjq_j is

oj=1ji=1jexp(qjki/d)vi1ji=1jexp(qjki/d).o_j = \frac{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})\,v_i}{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})}.

Exact computation requires Θ(dn2)\Theta(d n^2) time and O(s)O(s)0 memory, making scaling to long sequences intractable for standard hardware constraints.

Coreset-based attention approximation addresses this by maintaining a compressed, weighted subset of key–value pairs, enabling an approximate attention output

O(s)O(s)1

with O(s)O(s)2 provably small for all O(s)O(s)3.

The key theoretical device is sub-Gaussian thinning: a randomized algorithm produces a weighted coreset O(s)O(s)4 with guarantees

O(s)O(s)5

for all test functions O(s)O(s)6 in a suitable RKHS, with high probability. Thinformer provides non-causal thinning with O(s)O(s)7. The Express meta-procedure converts such thinning to the causal (streaming) domain with only an O(s)O(s)8 inflation in O(s)O(s)9, yielding Thinformer Express.

2. Algorithmic Structure and Execution Phases

Thinformer Express maintains a weighted cache O(s2log2n)O(s^2 \log^2 n)0 of target size O(s2log2n)O(s^2 \log^2 n)1, supporting the following workflow for each token:

  • Coreset retrieval: Obtain O(s2log2n)O(s^2 \log^2 n)2.
  • Approximate attention formation: Compute

O(s2log2n)O(s^2 \log^2 n)3

  • Update: Call O(s2log2n)O(s^2 \log^2 n)4.

Express operates internally in three phases:

  1. Exact: Accumulates the first O(s2log2n)O(s^2 \log^2 n)5 pairs exactly.
  2. Thin: Processes subsequent input in blocks (O(s2log2n)O(s^2 \log^2 n)6 in size), performing stratified subsampling followed by ThinformerHalve to reduce block size to O(s2log2n)O(s^2 \log^2 n)7; summaries are appended to cache.
  3. Halve: When cache exceeds O(s2log2n)O(s^2 \log^2 n)8, recursively apply halving (down to O(s2log2n)O(s^2 \log^2 n)9 points), incrementing nn0.

This scheme guarantees at most nn1 points in cache and streaming update complexity nn2 halving calls per token. Thinformer’s kernel, quadratic in block size nn3, leads to total compression cost nn4.

3. Approximation Guarantees

The approximation error for Thinformer Express is rigorously characterized. Fix nn5 and run Thinformer Express with cache size nn6. With probability at least nn7, for every nn8,

nn9

where jj0, jj1, jj2, and jj3 is a small absolute constant. In big-O notation,

jj4

uniformly over all tokens. This guarantee arises by chaining sub-Gaussian error bounds across jj5 thinning stages and subsequently applying an attention-output stability lemma (Gong et al., 9 Jun 2026).

4. Resource Complexity and Asymptotics

Thinformer Express achieves asymptotically optimal scaling for memory and runtime overheads in attention computation.

Resource Scaling Notes
Memory (KV storage) jj6 At most jj7 weighted points
Per-token query jj8 Full attention over cache
Compression overhead jj9 Dominated by iji\leq j0 small halving calls per token

Total streaming compression time over iji\leq j1 tokens satisfies iji\leq j2. Memory is independent of sequence length iji\leq j3; only computational overhead grows slowly as iji\leq j4.

5. Implementation Optimizations

The combination of Triton and algorithmic design underpins Thinformer Express’s efficiency. Major optimizations include:

  • Tiling: Key–query exponentiation and halving inner loops are partitioned into iji\leq j5 tiles to maximize on-chip cache utilization.
  • Fused operations: iji\leq j6 multiplications are fused with summation, preventing formation of iji\leq j7 or iji\leq j8 matrices in high-bandwidth memory (HBM).
  • Parallelism: Same-size halving tasks are executed in parallel during offline prefill phases.
  • Double indirection: Keys and values remain contiguous in HBM, while coresets store references in shared memory, eliminating scatter/gather overhead.

Performance gains include:

  • Unmasked prefill (iji\leq j9K, (qi,ki,vi)Rd×Rd×Rd(q_i, k_i, v_i)\in \mathbb{R}^d\times\mathbb{R}^d\times\mathbb{R}^d0): Torch-compiled Thinformer (qi,ki,vi)Rd×Rd×Rd(q_i, k_i, v_i)\in \mathbb{R}^d\times\mathbb{R}^d\times\mathbb{R}^d1, Triton Thinformer (qi,ki,vi)Rd×Rd×Rd(q_i, k_i, v_i)\in \mathbb{R}^d\times\mathbb{R}^d\times\mathbb{R}^d2 faster than FlashAttention 2.
  • Masked prefill (ChatGLM2-6B-32K, (qi,ki,vi)Rd×Rd×Rd(q_i, k_i, v_i)\in \mathbb{R}^d\times\mathbb{R}^d\times\mathbb{R}^d3K, (qi,ki,vi)Rd×Rd×Rd(q_i, k_i, v_i)\in \mathbb{R}^d\times\mathbb{R}^d\times\mathbb{R}^d4 or 1024): Thinformer Express up to (qi,ki,vi)Rd×Rd×Rd(q_i, k_i, v_i)\in \mathbb{R}^d\times\mathbb{R}^d\times\mathbb{R}^d5 faster than FlashAttention 2. HyperAttention is out-of-memory above (qi,ki,vi)Rd×Rd×Rd(q_i, k_i, v_i)\in \mathbb{R}^d\times\mathbb{R}^d\times\mathbb{R}^d6K.

6. Empirical Evaluation and Benchmarks

Rigorous empirical evaluations span diverse large-language-model workloads:

(a) Long-context prefill, masked (ChatGLM2-6B-32K, (qi,ki,vi)Rd×Rd×Rd(q_i, k_i, v_i)\in \mathbb{R}^d\times\mathbb{R}^d\times\mathbb{R}^d7):

Length (qi,ki,vi)Rd×Rd×Rd(q_i, k_i, v_i)\in \mathbb{R}^d\times\mathbb{R}^d\times\mathbb{R}^d8 FlashAttn2 HyperAttn Thinf-Expr
64K 12×
128K 10× 25×
256K -- 45×
384K -- 60×
512K -- 82×

(b) KV-cache compression (Llama 3.1 8B, LongBench-E): Wrapping compressors (SnapKV, StreamingLLM, PyramidKV) with Express yields (qi,ki,vi)Rd×Rd×Rd(q_i, k_i, v_i)\in \mathbb{R}^d\times\mathbb{R}^d\times\mathbb{R}^d9–qjq_j0 reduction in attention time at preserved end-task accuracy.

(c) Memory-constrained decoding (MATH-500, DeepSeek-R1-Distill-LLama-8B):

Cache size Exact Acc. Thinf-Expr Acc.
1000 28.4% 28.3%
2000 31.2% 31.1%
4000 34.7% 34.6%
Cache size Exact Mem. Thinf-Expr Mem.
4000 100% 61%

(d) Compute-constrained decoding (same settings):

Time Exact Acc. Thinf-Expr Acc.
1.0× 34.7% 34.7%
0.75× 28.4% 28.4%
Time Exact Cost Thinf-Expr Cost
Decoding 100% 56%

Thinf-Expr matches exact accuracy with qjq_j1 of KV memory and qjq_j2 of computational cost.

7. Deployment Considerations and Parameter Selection

  • Cache size qjq_j3: Set qjq_j4 to target desired maximum approximation error qjq_j5. In practice, qjq_j6–2048 suffices for qjq_j7 up to several hundred thousand.
  • Sequence length qjq_j8: Memory usage is qjq_j9, independent of oj=1ji=1jexp(qjki/d)vi1ji=1jexp(qjki/d).o_j = \frac{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})\,v_i}{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})}.0. The only oj=1ji=1jexp(qjki/d)vi1ji=1jexp(qjki/d).o_j = \frac{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})\,v_i}{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})}.1-dependence is in the compression overhead (oj=1ji=1jexp(qjki/d)vi1ji=1jexp(qjki/d).o_j = \frac{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})\,v_i}{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})}.2 factor), negligible when oj=1ji=1jexp(qjki/d)vi1ji=1jexp(qjki/d).o_j = \frac{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})\,v_i}{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})}.3.
  • Hardware: The Triton reference implementation utilizes on-chip shared memory and contiguous HBM allocation. The algorithm is AISA-friendly. Warp specialization and FP8 are not used but can be integrated.
  • Pipeline integration:
    • Prefill: Thinformer Express is applied in all layers to compress long input contexts prior to decoding.
    • KV-cache: Generation-time storage only requires the oj=1ji=1jexp(qjki/d)vi1ji=1jexp(qjki/d).o_j = \frac{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})\,v_i}{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})}.4-sized Express cache, not the full oj=1ji=1jexp(qjki/d)vi1ji=1jexp(qjki/d).o_j = \frac{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})\,v_i}{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})}.5.
    • Decoding: Express.update is called only after computing oj=1ji=1jexp(qjki/d)vi1ji=1jexp(qjki/d).o_j = \frac{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})\,v_i}{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})}.6; halving costs per-token (oj=1ji=1jexp(qjki/d)vi1ji=1jexp(qjki/d).o_j = \frac{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})\,v_i}{\frac{1}{j}\sum_{i=1}^j \exp(q_j^\top k_i/\sqrt{d})}.7) are negligible compared to attention.

Thinformer Express thus provides an end-to-end solution for causal attention with proven error bounds, optimal memory scaling, and practical speedups for long-context and resource-constrained neural language modeling (Gong et al., 9 Jun 2026).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Thinformer Express.