atlas

Research map / Architectures and efficiency / Attention and transformers

kNN Attention Demystified: A Theoretical Exploration for Scalable Transformers

ICLR 2025 · Architectures and efficiency › Attention and transformers · approach: Sparse efficient transformers for long context

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Gives a theoretical framework for kNN attention via lazy Gumbel sampling and k-MIPS, plus sub-quadratic Markov-chain-based estimators for attention gradients, with small experiments on random inputs, toy transformers and GPT-2 XL fine-tuning.

Problem

kNN attention is used empirically to make Transformers efficient on long sequences, but its approximation guarantees are not theoretically analyzed, and approximate backward passes lack provable algorithms.

Approach

Reformulates self-attention outputs as expectations under softmax distributions, samples them sublinearly via lazy Gumbel sampling over kNN/MIPS indices, and estimates attention gradients (notably D^V) with single-step random-walk (Markov chain) simulations.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
replace exact attention with kNN Attentionself-attention on random inputs · Random inputsmemory scalabilityHelped
replace exact attention with kNN Attentionself-attention on random inputs · Random inputsruntime scalingHelped
increase k (ablation)kNN Attention · Random inputsapproximation errorHelped
use smaller k (ablation)kNN Attention · Random inputsapproximation errorHurt
vary the input scale B while k is small (ablation)kNN Attention · Random inputsapproximation errorMixed
approximate attention gradientsgradient descent with MSE loss · Attention gradients, MSEgradient approximation qualityHelped
approximate attention gradientsgradient descent with cross-entropy loss · Attention gradients, cross-entropygradient-descent convergenceHurt
replace exact attention with kNN AttentionnanoGPT character-level Transformer · Shakespeare character-level language modelingperplexityMixed
use kNN Attention for fine-tuningGPT-2 XL · Shakespeare fine-tuningfine-tuning feasibilityHelped

Surprising findings

Limitations

Experimental setup

Datasets: Shakespeare dataset random uniform matrices Q,K,V

Benchmarks: random input approximation error Shakespeare character-level perplexity

Metrics: approximation error running time memory perplexity gradient descent convergence

Baselines: naive O(n^2) attention Alman and Song attention gradient approximation

Builds on: Lazy Gumbel sampling Routing Transformer Memorizing Transformers Unlimiformer nanoGPT

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy