Thinformer Express: Streaming Causal Attention
- 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 approximation error, memory, and compression overhead for a sequence of length . 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 to attend only to prior or current positions (). For query–key–value triplets , the exact masked (causal) attention output for is
Exact computation requires time and 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
1
with 2 provably small for all 3.
The key theoretical device is sub-Gaussian thinning: a randomized algorithm produces a weighted coreset 4 with guarantees
5
for all test functions 6 in a suitable RKHS, with high probability. Thinformer provides non-causal thinning with 7. The Express meta-procedure converts such thinning to the causal (streaming) domain with only an 8 inflation in 9, yielding Thinformer Express.
2. Algorithmic Structure and Execution Phases
Thinformer Express maintains a weighted cache 0 of target size 1, supporting the following workflow for each token:
- Coreset retrieval: Obtain 2.
- Approximate attention formation: Compute
3
- Update: Call 4.
Express operates internally in three phases:
- Exact: Accumulates the first 5 pairs exactly.
- Thin: Processes subsequent input in blocks (6 in size), performing stratified subsampling followed by ThinformerHalve to reduce block size to 7; summaries are appended to cache.
- Halve: When cache exceeds 8, recursively apply halving (down to 9 points), incrementing 0.
This scheme guarantees at most 1 points in cache and streaming update complexity 2 halving calls per token. Thinformer’s kernel, quadratic in block size 3, leads to total compression cost 4.
3. Approximation Guarantees
The approximation error for Thinformer Express is rigorously characterized. Fix 5 and run Thinformer Express with cache size 6. With probability at least 7, for every 8,
9
where 0, 1, 2, and 3 is a small absolute constant. In big-O notation,
4
uniformly over all tokens. This guarantee arises by chaining sub-Gaussian error bounds across 5 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) | 6 | At most 7 weighted points |
| Per-token query | 8 | Full attention over cache |
| Compression overhead | 9 | Dominated by 0 small halving calls per token |
Total streaming compression time over 1 tokens satisfies 2. Memory is independent of sequence length 3; only computational overhead grows slowly as 4.
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 5 tiles to maximize on-chip cache utilization.
- Fused operations: 6 multiplications are fused with summation, preventing formation of 7 or 8 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 (9K, 0): Torch-compiled Thinformer 1, Triton Thinformer 2 faster than FlashAttention 2.
- Masked prefill (ChatGLM2-6B-32K, 3K, 4 or 1024): Thinformer Express up to 5 faster than FlashAttention 2. HyperAttention is out-of-memory above 6K.
6. Empirical Evaluation and Benchmarks
Rigorous empirical evaluations span diverse large-language-model workloads:
(a) Long-context prefill, masked (ChatGLM2-6B-32K, 7):
| Length 8 | FlashAttn2 | HyperAttn | Thinf-Expr |
|---|---|---|---|
| 64K | 1× | 5× | 12× |
| 128K | 1× | 10× | 25× |
| 256K | 1× | -- | 45× |
| 384K | 1× | -- | 60× |
| 512K | 1× | -- | 82× |
(b) KV-cache compression (Llama 3.1 8B, LongBench-E): Wrapping compressors (SnapKV, StreamingLLM, PyramidKV) with Express yields 9–0 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 1 of KV memory and 2 of computational cost.
7. Deployment Considerations and Parameter Selection
- Cache size 3: Set 4 to target desired maximum approximation error 5. In practice, 6–2048 suffices for 7 up to several hundred thousand.
- Sequence length 8: Memory usage is 9, independent of 0. The only 1-dependence is in the compression overhead (2 factor), negligible when 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 4-sized Express cache, not the full 5.
- Decoding: Express.update is called only after computing 6; halving costs per-token (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).