AVQ-Attention-2: Adaptive Vector-Quantized Attention with Exact Local Blocks and Linear-Cost Training
Authors: Winfried van den Dool, Patrick Forré, Amir Habibian, Yuki M. Asano, Max Welling
Organizations: QUVA Lab & AMLab, University of Amsterdam · AI4Science Lab & KdV Institute, University of Amsterdam · Qualcomm AI Research, Amsterdam · FunAI Lab, University of Technology Nuremberg · AMLab, University of Amsterdam
Attention costs O(N2) in the number of tokens. Vector-quantized attention reduces this to O(NM) by clustering the N keys, attending to the M codewords instead, and its adaptive form, AVQ-attention, concentrates codebook resolution where a query's attention mass actually falls. We present AVQ-Attention-2, a better design that merges it with exact local attention and attends to the mean of each cluster's keys rather than to a codeword. We show three improvements: consistently better quality at comparable cost; training that now also costs O(NM) rather than O(N2); and an approximation accurate enough that the layer can be dropped into a pretrained transformer without fine-tuning. Across a variety of sequence lengths the result is competitive not merely with other approximate attention but with exact dense attention, running faster than FlashAttention at little to no loss in quality.
Figures & tables
Figure 1: Attention received by one query (cyan), computed four ways. Exact local attention is meant to fix the query’s own neighbourhood, but it also sharpens the rest of the map: once the tile’s own keys are computed exactly they no longer attract refinement, so the budget is spent on the rest of the image. The share of the selected parents’ keys lying inside the tile falls from 0.33 to 0.06 .
Figure 2: Four consecutive layers of a 32×32 token grid at BlockN=64 . Each layer places its boundaries where the previous layers did not have them.
Figure 3: AVQ-Attention-2 against other VQ-attention variants ( Lingle, 2024 ; van den Dool et al., 2026 ) : quality against the attention speedup over FlashAttention-2. Without any fine-tuning AVQ-Attention-2 lies above both of their fine-tuned curves, so the approximation itself is closer to dense attention. With fine-tuning it approaches the dense model, at a 1.3 – 2.0× speedup.
ADE20K (mIoU)
ImageNet-1k (top-1)
setting
ms
drop-in
fine-tuned
setting
ms
drop-in
fine-tuned
FlashAttention-2
—
0.280
45.88
46.54
—
0.180
85.82
—
MRA
b=8
1.566
31.55
45.88
b=8
1.041
83.64
85.32
Agent Attention
15×15
0.576
—
44.64
7×7
0.183
—
77.27
Mixture-of-top- k
7×7
2.162
21.38
46.17
7×7
2.139
79.95
84.76
AVQ-Attention-2
32/8/8
0.178
44.17
46.71
32/8/8
0.125
84.75
85.60
Table 1: Other efficient attention methods, as drop-in and after fine-tuning, under the same recipe. Agent Attention cannot be dropped in: its agent parameters are new and untrained. More details and additional results are in Appendix C .
ADE20K (mIoU)
ImageNet-1k (top-1)
32/8/4
32/8/8
32/8/4
32/8/8
FlashAttention-2 baseline
45.88
45.88
85.82
85.82
FlashAttention-2, fine-tuned
46.54
46.54
—
—
AVQ-attention, as published
40.38
40.83
80.24
81.29
AVQ, our training setup
41.74
43.09
73.35
76.58
+ cluster means
43.36
44.47
80.74
82.43
Table 2: Building the layer up from AVQ-attention. ADE20K mean IoU (DPT-Large, 10 epochs) and ImageNet-1k top-1 (ViT-B/8, 1 epoch) after fine-tuning, at two codebook configurations M0/P/C ; the published row is at van den Dool et al. ’s budget (4 instead of our 1 epoch on ImageNet); every other row is ours, cumulative from that row down. Without any fine-tuning AVQ2 already reaches most of its accuracy, where AVQ collapses entirely.
Figure 4: Local attention alone: quality after fine-tuning under the setup of Appendix A , against the attention speedup over FlashAttention-2. Optimised tiles beat Gilbert tiles at every setting, showing how the seemingly simple decision of how to divide tokens over tiles already gives a free win. Only our tilings are drawn as curves: Swin’s speed is not monotone in its window size, which has to do with grid padding and kernel artifacts, so its points do not order along the axis. The settings behind every point, and the exact numbers, are in Table 6 .
Figure 5: Diving-48 at N=9216 : top-1 probe accuracy of the V-JEPA 2 encoder against its throughput speedup over the original encoder. Appendix E shows our own configurations zoomed in, as well as the hyperparameters used for each point.
Encoder
drop-in
distilled
ms
Dense
88.83
—
15.9
AVQ-Attention-2
88.73
88.22
0.94
Mixture-of-top- k
73.10
85.58
5.85
Agent Attention
—
82.54
4.02
MRA
79.90
86.90
7.53
Table 3: Diving-48 at N=18432 , a V-JEPA 2 ViT-B/16 encoder with an attentive probe. On the left, every attention layer of the encoder is replaced, as a drop-in and after distillation, beside the cost of one encoder attention layer. On the right, the encoder is left dense and the probe is trained from scratch with an efficient attention method, beside the cost of one probe layer forward and backward. Every setting is in Appendix C .
Appendix figures & tables7 assets
Supplementary material from the paper’s appendix.
Appendix
Vˉm only
Vˉm and Kˉm
N
sorted
atomic
ratio
sorted
atomic
ratio
1,024
0.079
0.112
1.4×
0.106
0.276
2.6×
4,096
0.240
0.400
1.7×
0.304
0.827
2.7×
16,384
0.936
1.543
1.6×
1.113
3.043
2.7×
65,536
3.697
6.172
1.7×
4.326
11.985
2.8×
Appendix
Table 4: Quantization precompute, sorted pipeline against the original atomic scatter, accumulating value sums alone and value and key sums together. Milliseconds on one RTX 3090 in fp16; B=4 , H=16 , D=64 , M0=64 , C=8 , depth 1.
Method
Setting
ms
drop-in
fine-tuned
ADE20K, DPT-Large, N=901 (mIoU)
MRA
b=2
0.848
13.81
42.26
b=4
1.075
19.92
44.29
b=8
1.566
31.55
45.88
b=16
2.542
43.72
46.27
Agent Attention
5×5
0.237
—
41.24
Appendix
Table 5: Every setting of each baseline that we ran, against the AVQ2 row of Table 1 , repeated here for reference. One run per setting, and times are one attention layer at batch size 4.
ADE20K
ImageNet-1k
Method
Tile
mIoU
Speedup
top-1
Speedup
Swin
window 5
37.40
2.0 ×
77.50
2.4 ×
window 7
40.76
2.9 ×
80.98
2.3 ×
window 9
42.23
2.1 ×
82.15
1.7 ×
window 11
43.69
2.5 ×
83.12
2.1 ×
window 13
43.86
1.6 ×
83.81
1.4 ×
Appendix
Table 6: The numbers behind Figure 4 : every local-attention setting we train, its quality after fine-tuning, and its speedup over FlashAttention-2.
Figure 6: Every AVQ-Attention-2 configuration at N=9216 , from Figure 5 . A label gives the codebook M0/P/C and the line style the query-tile size; an arrow runs from each drop-in point to its distilled point.
Method
Setting
ms
× dense
drop-in
distilled
MRA
2 blocks per row
54.46
1.44
60.61
80.86
MRA
4 blocks per row
60.82
1.29
66.19
82.84
MRA
8 blocks per row
74.14
1.05
77.16
85.18
Agent Attention
2×4×4 pool, 32 agents
40.25
1.94
—
65.03
Agent Attention
2×8×8 pool, 128 agents
42.92
1.82
—
62.59
Agent Attention
8×4×4 pool, 128 agents
43.55
1.80
—
70.46
Appendix
Table 7: Every baseline run on Figure 5 : Diving-48 top-1 of the V-JEPA 2 encoder with an attentive probe at N=9216 , one run per setting, with the cost of the encoder beside it.
M0/P/C
drop-in
no double-counting correction
Δ
ImageNet
16/8/4
82.92
82.40
−0.52
32/4/4
83.59
82.88
−0.71
32/8/4
84.05
83.51
−0.54
32/12/4
84.38
83.63
−0.75
32/4/8
84.23
83.65
−0.58
32/8/8
84.75
84.24
−0.51
Appendix
Table 8: Drop-in accuracy of every configuration of Figure 3 , with and without the correction of Section 4.2 . ImageNet is top-1, ADE20K is mean IoU.
criterion for the top- P
ImageNet
ADE20K
V-JEPA 2
random
0.247
0.229
0.279
key variance
0.486
0.613
0.331
attention mass, Equation 3 (ours)
0.789
0.881
0.918
mass × key variance
0.815
0.910
0.921
top- P by each parent’s own reduction
0.981
0.981
0.983
sequential reference
1.000
1.000
1.000
Appendix
Table 9: Share of the error reduction the sequential reference reaches at the same budget P , per selection criterion, averaged over layers: 1 matches it, 0 is no better than refining nothing. Drop-in; M0/P/C=32/8/8 on the two image tasks and 64/16/8 at N=9216 .
Transformer attention lets models relate tokens by weighting information from other positions, enabling context-dependent sequence and multimodal processing.
The O(N2) complexity of attention over N tokens remains a computational bottleneck in transformer models. Vector-Quantized (VQ) attention reduces this to O(MN) by representing keys with M codewords, but applies uniform codebook capacity regardless of where attention mass concentrates: high-attention regions of key space may be coarsely approximated while low-attention regions waste representational capacity. We propose Adaptive Vector-Quantized (AVQ) Attention, which adaptively allocates codebook capacity based on attention importance. Starting from a small set of codewords, our method identifies the most important codes during the forward pass and refines them with pre-learned child codewords, achieving fine-grained quantization where it matters most while maintaining coarse quantization elsewhere. We develop an implementation using custom Triton kernels that enables the full adaptive refinement process, including importance scoring, child codeword insertion, and parent contribution replacement, to be carried out within the tiled computation paradigm of Flash Attention with minimal overhead. Our approach maintains O(MN) complexity while achieving improved accuracy-efficiency trade-offs compared to fixed-codebook VQ-attention.
Winfried van den dool, Patrick Forré, Amir Habibian +2
QUVA Lab, University of Amsterdam, The Netherlands · AMLab, Informatics Institute, University of Amsterdam, The Netherlands · AI4Science Lab, University of Amsterdam, The Netherlands +3
The key-value (KV) cache stores information from past tokens and is a major memory bottleneck in long-context inference. Existing quantization methods address this bottleneck by representing the KV cache uniformly with lower-precision data types and designing quantization schemes to minimize reconstruction error in the cache itself, without accounting for how that error propagates through attention mechanisms. We prove that, under a white-noise quantization model, the expected attention-aware distortion decomposes into additive key and value contributions that factor across tokens and channels. Building on transform coding and reverse water-filling, which are classical tools from signal processing and rate-distortion theory, we introduce Attention-Aware Transform Coding (AATC), which allocates bits over a calibration set to minimize attention-aware distortion. On Llama-3.1-8B-Instruct and Qwen-2.5-7B-Instruct, evaluated across LongBench, RULER, GSM8K, MMLU-Pro, and MATH-500, our method achieves near-lossless accuracy at approximately 5.8× compression, whereas each baseline degrades in at least some settings.
Hannah Laus, Claudio Mayrink Verdun, Hao Wang +2
Technical University of Darmstadt, the Technical University of Munich and the Munich Center for Machine Learning · Massachusetts Institute of Technology · Red Hat AI Innovation Team and the MIT-IBM Watson AI Lab +1
Long-context LLM decoding reads the key-value (KV) cache at every step. Loading it takes longer than computing attention over it, so throughput is bandwidth-bound. Hence, reducing the cache size can raise both decoding speed and serving capacity. The challenge is to reduce cache size while preserving the attention products, keeping reconstruction cheap, and using a fixed per-token bit count. At two bits per element, the most competitive methods rely on orthogonal transforms. However, existing techniques are either data-oblivious or use the query statistics without deriving the transform from a distortion criterion. Moreover, they rely on transforms built on top of random or Hadamard rotations, which equalize variances across entries rather than compacting energy, and fixed-width scalar quantizers, which are suboptimal at low rates. In this paper, we formulate KV cache quantization as a transform coding problem in which distortion is the error in the attention products. We derive closed-form optimal transforms for keys and values from calibration statistics, under a high-resolution model. We show that the optimal key transform is not orthogonal and satisfies a generalized Parseval relation: the attention-aware distortion becomes mean-squared error (MSE) in the transform domain. Thus, we can use MSE-optimal vector quantizers applied directly to the transformed key coefficients. To meet the fixed-width layout requirement, we show that grouping coefficients into equal-volume partitions makes equal-size codebooks attain the variable-rate optimum under the same high-resolution model. At two bits per element, our method, termed NOVA-KV, recovers most of the long-context retrieval accuracy lost by scalar quantization methods at comparable throughput.
Samuel Fernández-Menduiña, Amir Ziashahabi, Eduardo Pavez +2
Department of Electrical and Computer Engineering, University of Southern California