SANTA++: Sampling Attention through Representative Keys
Organizations: Department of Electrical and Computer Engineering University of California, Santa Barbara, CA, USA · Flucta, San Francisco, CA, USA
Abstract
Attention often concentrates on a small subset of tokens in the context, but which subset matters changes from one query to the next. To exploit this changing structure, we introduce SANTA++, a training-free stochastic attention method that uses representative keys for memory-efficient selection without scanning the entire key-value (KV) cache. Cached keys are organized into teams, and the query scores one representative from each team to decide which teams to sample. We compute exact attention scores within the sampled teams and reweight each team's contribution by the inverse of its inclusion probability. This importance sampling correction estimates attention over the full cache, with a sampling budget that lets us trade memory reads for accuracy. Remarkably, with 32 or 64 sampled teams, SANTA++ uses 16% to 22% of dense attention's KV reads and retains 94% to 99% of the dense-attention baseline's scores on LongBench v2 and HELMET's retrieval-augmented generation subset, and 85% to 91% on RULER, with Qwen2.5-7B-Instruct at 32K context. With 31 sampled teams, our GPU implementation delivers a attention speedup over the dense FlashAttention baseline at 32K context. By reducing the number of cache entries read, SANTA++ in principle complements architectures with compressed KV representations, such as multi-head latent attention. Our kernels are available at: https://github.com/OPUSLab/santapp-kernel-demo.git.
Figures & tables
| Task | Teams (k-means) | Centroid-guided sampling | Centroid-guided sampling |
|---|---|---|---|
| CWE | 1.621 | 2.806 | 3.429 |
| S-NIAH-1 | 1.248 | 2.076 | 2.827 |
| QA-1 | 1.613 | 2.429 | 3.495 |
| Method | KV (%) | Score (norm) (%) | Score (abs) (%) | |
|---|---|---|---|---|
| SDPA | – | 100.00 | 100.00 | 57.40 2.00 |
| SANTA | 128 | 50.43 | 99.13 | 56.90 2.05 |
| 256 | 50.75 | 99.04 | 56.85 2.05 | |
| 512 | 51.30 | 100.17 | 57.50 2.02 | |
| 1024 | 52.17 | 99.48 | 57.10 2.07 | |
| 2048 | 53.53 | 99.65 | 57.20 2.08 |
| Method | KV (%) | Score (norm) (%) | Score (abs) (%) | |
|---|---|---|---|---|
| SDPA | — | 100.00 | 100.00 | 31.91 2.04 |
| SANTA | 128 | 50.36 | 95.95 | 30.62 2.06 |
| 256 | 50.59 | 102.80 | 32.80 1.96 | |
| 512 | 50.97 | 106.85 | 34.10 2.04 | |
| 1024 | 51.56 | 99.84 | 31.86 1.91 | |
| SANTA ++ (k-means) | 128 | 16.68 | 99.07 | 31.61 2.01 |
| Method | KV (%) | Score (norm) (%) | Score (abs) (%) | |
|---|---|---|---|---|
| SDPA | — | 100.00 | 100.00 | 83.51 0.66 |
| SANTA | 128 | 50.32 | 99.15 | 82.80 0.64 |
| 256 | 50.54 | 99.75 | 83.31 0.67 | |
| 512 | 50.91 | 100.11 | 83.61 0.65 | |
| 1024 | 51.52 | 99.92 | 83.45 0.67 | |
| 2048 | 52.49 | 99.99 | 83.50 0.66 |
| Method | GPU launches | Median latency ( s) | Speedup vs. Flash |
|---|---|---|---|
| SANTA ++ | 5 | 63.52 | 1.69 |
| Forced Flash SDPA | 2 | 107.33 | 1.00 |
Appendix figures & tables16 assets
Supplementary material from the paper’s appendix.
Appendix
| S-NIAH-1 | S-NIAH-2 | S-NIAH-3 | MK-NIAH-1 | MK-NIAH-2 | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Method | KV (%) | Acc (%) | KV (%) | Acc (%) | KV (%) | Acc (%) | KV (%) | Acc (%) | KV (%) | Acc (%) | |
| SDPA | — | 100.00 | 100.00 0.00 | 100.00 | 100.00 0.00 | 100.00 | 100.00 0.00 | 100.00 | 100.00 0.00 | 100.00 | 98.00 2.50 |
| SANTA ++ (Teams) | 128 | 22.54 | 100.00 0.00 | 25.37 | 100.00 0.00 | 25.50 | 100.00 0.00 | 24.95 | 99.00 1.50 | 25.57 | 94.00 4.50 |
| 256 | 30.33 | 100.00 0.00 | 34.75 | 99.00 1.50 | 34.77 | 100.00 0.00 | 34.05 | 100.00 0.00 | 34.60 | 98.00 2.50 | |
| 512 | 42.60 | 100.00 0.00 | 48.49 | 100.00 0.00 | 48.19 | 100.00 0.00 | 47.63 | 100.00 0.00 | 47.78 | 95.00 4.50 | |
| Centroid-guided ( ) | 128 | 20.90 | 100.00 0.00 | 22.06 | 100.00 0.00 | 22.53 | 98.00 2.50 | 21.98 | 99.00 1.50 | 22.87 | 98.00 2.50 |
| Task | Context length | WER threshold | Heads (%) |
|---|---|---|---|
| CWE | 8192 | 82.1 [79.8, 84.9] | |
| CWE | 32768 | 80.2 [76.9, 84.8] | |
| CWE | 8192 | 54.0 [48.4, 60.7] | |
| CWE | 32768 | 49.5 [41.7, 60.7] | |
| CWE | 8192 | 22.1 [18.4, 27.0] | |
| CWE | 32768 | 23.6 [16.2, 36.4] |
| Method | KV (%) | Acc (norm) (%) | Acc (abs) (%) | |
|---|---|---|---|---|
| SDPA | – | 100.00 | 100.00 | 62.65 2.02 |
| SANTA | 128 | 51.62 | 100.24 | 62.80 2.02 |
| 256 | 52.70 | 99.60 | 62.40 2.03 | |
| 512 | 54.39 | 99.60 | 62.40 2.03 | |
| 1024 | 56.77 | 100.16 | 62.75 2.05 | |
| 2048 | 60.14 | 100.00 | 62.65 2.07 |
| Method | Natural Questions | TriviaQA | PopQA | HotpotQA | MS MARCO | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Total access (%) | Acc (%) | Total access (%) | Acc (%) | Total access (%) | Acc (%) | Total access (%) | Acc (%) | Total access (%) | Acc (%) | ||
| SDPA | – | 100.00 | 53.20 4.30 | 100.00 | 82.20 3.30 | 100.00 | 64.40 4.10 | 100.00 | 50.80 4.40 | 100.00 | 58.51 3.89 |
| SANTA | 128 | 51.62 | 54.40 4.40 | 51.55 | 82.40 3.40 | 51.79 | 63.00 4.20 | 51.51 | 51.40 4.30 | 51.72 | 59.16 3.81 |
| 256 | 52.73 | 53.80 4.40 | 52.58 | 81.80 3.40 | 52.97 | 63.80 4.20 | 52.52 | 50.20 4.50 | 52.75 | 58.03 3.75 | |
| 512 | 54.46 | 53.00 4.30 | 54.21 | 82.20 3.30 | 54.79 | 64.20 4.20 | 54.09 | 50.20 4.50 | 54.27 | 59.06 3.84 | |
| 1024 | 56.90 | 54.40 4.30 | 56.49 | 82.20 3.30 | 57.30 | 64.00 4.10 | 56.39 | 50.40 4.40 | |||
| Method | Natural Questions | TriviaQA | PopQA | HotpotQA | MS MARCO | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Total access (%) | Acc (%) | Total access (%) | Acc (%) | Total access (%) | Acc (%) | Total access (%) | Acc (%) | Total access (%) | Acc (%) | ||
| SDPA | – | 100.00 | 46.20 4.30 | 100.00 | 82.00 3.50 | 100.00 | 62.80 4.30 | 100.00 | 38.60 4.20 | 100.00 | 34.39 4.36 |
| SANTA | 128 | 50.43 | 46.40 4.30 | 50.41 | 81.00 3.50 | 50.46 | 62.20 4.20 | 50.41 | 38.00 4.30 | 50.46 | 37.63 4.60 |
| 256 | 50.77 | 45.60 4.40 | 50.71 | 81.00 3.40 | 50.81 | 62.80 4.20 | 50.71 | 38.00 4.40 | 50.77 | 35.79 4.58 | |
| 512 | 51.33 | 46.00 4.40 | 51.23 | 81.40 3.30 | 51.40 | 62.80 4.20 | 51.23 | 39.80 4.20 | 51.29 | 34.49 4.35 | |
| 1024 | 52.23 | 46.40 4.40 | 52.05 | 80.40 3.40 | 52.32 | 62.80 4.20 | 52.06 | 38.80 4.10 | |||
| S-NIAH-1 | S-NIAH-2 | S-NIAH-3 | MK-NIAH-1 | MK-NIAH-2 | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Method | KV (%) | Acc (%) | KV (%) | Acc (%) | KV (%) | Acc (%) | KV (%) | Acc (%) | KV (%) | Acc (%) | |
| SDPA | — | 100.00 | 100.00 0.00 | 100.00 | 100.00 0.00 | 100.00 | 100.00 0.00 | 100.00 | 100.00 0.00 | 100.00 | 98.80 0.90 |
| SANTA | 128 | 50.97 | 100.00 0.00 | 51.11 | 100.00 0.00 | 51.06 | 99.80 0.30 | 51.13 | 100.00 0.00 | 51.25 | 98.80 0.90 |
| 256 | 51.56 | 100.00 0.00 | 51.81 | 100.00 0.00 | 51.72 | 99.80 0.30 | 51.83 | 100.00 0.00 | 52.08 | 99.00 0.90 | |
| 512 | 52.52 | 100.00 0.00 | 52.93 | 100.00 0.00 | 52.76 | 100.00 0.00 | 52.94 | 100.00 0.00 | 53.41 | 98.20 1.10 | |
| 1024 | 53.98 | 100.00 0.00 | 54.62 | 100.00 0.00 | 54.35 | 100.00 0.00 | 54.62 | 100.00 0.00 | 55.43 | 98.20 1.10 | |
| S-NIAH-1 | S-NIAH-2 | S-NIAH-3 | MK-NIAH-1 | MK-NIAH-2 | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Method | KV (%) | Acc (%) | KV (%) | Acc (%) | KV (%) | Acc (%) | KV (%) | Acc (%) | KV (%) | Acc (%) | |
| SDPA | — | 100.00 | 100.00 0.00 | 100.00 | 100.00 0.00 | 100.00 | 98.60 1.00 | 100.00 | 99.00 0.90 | 100.00 | 93.40 2.20 |
| SANTA | 128 | 50.28 | 100.00 0.00 | 50.31 | 100.00 0.00 | 50.30 | 99.20 0.70 | 50.31 | 99.20 0.70 | 50.37 | 93.20 2.20 |
| 256 | 50.47 | 100.00 0.00 | 50.53 | 100.00 0.00 | 50.51 | 98.80 0.90 | 50.53 | 99.00 0.90 | 50.64 | 92.80 2.20 | |
| 512 | 50.81 | 100.00 0.00 | 50.91 | 100.00 0.00 | 50.87 | 98.80 0.90 | 50.90 | 99.00 0.90 | 51.12 | 93.60 2.10 | |
| 1024 | 51.37 | 100.00 0.00 | 51.53 | 100.00 0.00 | 51.45 | 98.60 1.00 | 51.51 | 99.00 0.90 | 51.92 | 93.40 2.10 | |
| Directly timed region | Median latency ( s) |
|---|---|
| Grouped representative scorer | 20.32 |
| Parallel per-query top- | 15.51 |
| Fused exact merge + GQA union | 16.16 |
| Grouped selected attention | 19.97 |
| Split-softmax reducer | 9.95 |
| Complete five-launch SANTA ++ | 63.52 |
| Kernel | CTAs | NCU dur. ( s) | Occ. (%) | Elig. | DRAM (%) | Reg./thr. |
| SANTA ++ representative scorer | 248 | 14.14 | 24.49 | 0.08 | 63.85 | 56 |
| SANTA ++ top- | 868 | 10.78 | 84.51 | 2.40 | 10.61 | 30 |
| SANTA ++ merge + union | 4 | 10.94 | 16.62 | 0.38 | 1.59 | 44 |
| SANTA ++ selected attention | 128 | 14.30 | 12.88 | 0.20 | 19.46 | 144 |
| SANTA ++ reducer | 28 | 4.80 | 8.33 | 0.05 | 11.07 | 40 |
| Flash split-KV forward | 128 | 89.92 | 8.33 | 0.10 | 83.95 | 200 |
| Method | KV (%) | Acc (norm) (%) | Acc (abs) (%) | |
|---|---|---|---|---|
| SDPA | — | 100.00 | 100.00 | 86.22 4.56 |
| SANTA ++ (Latent k-means) | 128 | 56.28 | 80.80 | 69.67 5.92 |
| 256 | 70.09 | 91.56 | 78.94 5.14 | |
| 512 | 86.18 | 98.07 | 84.56 4.72 | |
| 1024 | 101.89 | 97.81 | 84.33 5.00 |
| Method | KV (%) | Acc (norm) (%) | Acc (abs) (%) | |
|---|---|---|---|---|
| SDPA | — | 100.00 | 100.00 | 96.67 2.67 |
| SANTA ++ (Latent k-means) | 128 | 47.57 | 84.82 | 82.00 7.00 |
| 256 | 62.25 | 94.48 | 91.33 5.33 | |
| 512 | 80.34 | 100.00 | 96.67 3.00 | |
| 1024 | 98.45 | 99.31 | 96.00 3.00 |
| Method | KV (%) | Acc (norm) (%) | Acc (abs) (%) | |
|---|---|---|---|---|
| SDPA | — | 100.00 | 100.00 | 94.00 4.00 |
| SANTA ++ (Latent k-means) | 128 | 57.88 | 77.66 | 73.00 8.75 |
| 256 | 71.89 | 93.09 | 87.50 5.50 | |
| 512 | 87.67 | 98.94 | 93.00 4.75 | |
| 1024 | 102.64 | 92.55 | 87.00 7.75 |
| Method | KV (%) | Acc (norm) (%) | Acc (abs) (%) | |
|---|---|---|---|---|
| SDPA | — | 100.00 | 100.00 | 68.00 13.00 |
| SANTA ++ (Latent k-means) | 128 | 58.41 | 79.41 | 54.00 14.00 |
| 256 | 72.81 | 85.29 | 58.00 14.00 | |
| 512 | 88.50 | 94.12 | 64.00 13.00 | |
| 1024 | 103.87 | 102.94 | 70.00 13.00 |