Emergent Structure in the Marginal Attention Space of Language Models
Organizations: Institute of Science and Technology Austria (ISTA)
Abstract
While representation similarity across independently trained language models is well-documented, how internal mechanics such as attention behave across models remains far less characterized. Inspired by this gap, we examine the structure of post-softmax attention weights by marginalizing over query positions, mapping them into a joint token-head "marginal attention space". Evaluating across 60+ diverse LLMs, we find that different properties emerge when reducing this space along its token and head axes. When reduced token-wise, marginal attention yields a text-intrinsic signal robustly conserved across models. To explain this property, we empirically connect marginal attention to the input-output Jacobian of the network, and prove theoretically that under a smoothness assumption, models with similar next-token distributions are guaranteed to have similar input-output Jacobian statistics. When reduced head-wise, it forms a model-private signature conserved across documents. Practically, this provides a natural way to estimate a per-head budget for key-value (KV) cache eviction, effectively decoupling model-specific budget allocation from text-intrinsic token scoring. On standard eviction benchmarks, a per-head budget precomputed offline on pretraining text, combined with a training-free token score, shows competitive performance with methods that recompute the budget on every document or train it per target. Code available at https://github.com/Flegyas/marginal-attention
Figures & tables
| cost | Qwen3-8B | Llama-3.1-8B | phi-4 | Qwen3-32B | Mistral-7B | ||||||||||||
| offline | online | 4 | 8 | 16 | 4 | 8 | 16 | 4 | 8 | 16 | 4 | 8 | 16 | 4 | 8 | 16 | |
| AdaKV + EA | 88.4 | 72.8 | 46.5 | 75.7 | 45.3 | 15.2 | 68.7 | 44.0 | 13.8 | 81.9 | 63.6 | 36.4 | 67.2 | 34.0 | 19.9 | ||
| AdaKV + KVzap | 94.0 | 89.2 | 49.9 | 94.5 | 89.3 | 63.1 | 87.8 | 77.0 | 51.6 | 95.4 | 90.0 | 50.3 | 88.3 | 70.2 | 42.1 | ||
| KVzip | 95.0 | 92.3 | 59.4 | 95.3 | 92.8 | 74.2 | 91.5 | 89.6 | 68.8 | 95.6 | 95.6 | 91.8 | 91.2 | 89.2 | 72.2 | ||
| LU-KV + EA | 90.6 | 75.2 | 58.4 | 95.1 | 91.8 | 67.0 | 92.4 | 87.9 | 69.5 | 90.2 | 72.6 | 38.2 | 91.2 | 85.1 | 61.7 | ||
| HM + EA | 95.0 | 91.8 | 73.3 | 95.1 | 92.3 | 66.3 | 91.5 | 87.8 | 68.5 | 95.2 | 93.2 | 79.1 | 90.5 | 84.3 | 65.3 | ||
Appendix figures & tables60 assets
Supplementary material from the paper’s appendix.
Appendix
| document set | models | documents | consensus of the other models | between two models |
|---|---|---|---|---|
| mix1000, all domains | 67 | 1000 | 0.8443 0.0042 | 0.7253 0.0065 |
| mix1000, natural domains | 67 | 850 | 0.8673 0.0032 | 0.7607 0.0051 |
| mix1000, generated domains | 67 | 150 | 0.6114 0.0136 | 0.4093 0.0162 |
| mix10k, all domains | 12 | 9792 | 0.7977 0.0021 | 0.6787 0.0028 |
| mix10k, natural domains | 12 | 8292 | 0.8357 0.0012 | 0.7277 0.0018 |
| mix10k, generated domains | 12 | 1500 | 0.4990 0.0064 | 0.3362 0.0060 |
| vs the other 66 | two models | ||||
|---|---|---|---|---|---|
| whole census | agreement | 0.867 0.003 | 0.761 0.005 | ||
| different document (control) | 0.015 | 0.014 | |||
| 10 pythia-410m seeds (ceiling) | 0.942 | 0.900 | |||
| pairs | mean | median | 5th to 95th | ||
| pair class | base vs its instruct | 12 | 0.968 | 0.976 | [0.924, 0.993] |
| vision vs its text model | 3 | 0.941 | 0.944 | [0.928, 0.951] |
| model | B | ref. | model | B | ref. |
|---|---|---|---|---|---|
| 01-ai/Yi-6B | 6.1 | ( 01.AI et al., 2024 ) | meta-llama/Llama-3.1-8B | 8.0 | ( Grattafiori et al., 2024 ) |
| 01-ai/Yi-6B-Chat | 6.1 | ( 01.AI et al., 2024 ) | meta-llama/Llama-3.1-8B-Instruct | 8.0 | ( Grattafiori et al., 2024 ) |
| 01-ai/Yi-9B | 8.8 | ( 01.AI et al., 2024 ) | microsoft/phi-4 | 14.7 | ( Abdin et al., 2024 ) |
| allenai/OLMo-2-0425-1B | 1.5 | ( Walsh et al., 2025 ) | mistralai/Mistral-7B-Instruct-v0.1 | 7.2 | ( Jiang et al., 2023 ) |
| allenai/OLMo-2-0425-1B-Instruct | 1.5 | ( Walsh et al., 2025 ) | mistralai/Mistral-7B-Instruct-v0.2 | 7.2 | ( Jiang et al., 2023 ) |
| allenai/OLMoE-1B-7B-0924 | 6.9 | ( Muennighoff et al., 2025 ) | mistralai/Mistral-7B-Instruct-v0.3 | 7.2 | ( Jiang et al., 2023 ) |
| characters on the axis | axis (%) | documents | vs the other 66 | two models |
| all characters | 100.0 | 850 | 0.8673 | 0.7607 |
| punctuation deleted | 90.8 | 850 | 0.8705 | 0.7664 |
| punctuation and whitespace deleted | 87.6 | 850 | 0.8734 | 0.7711 |
| punctuation only | 5.0 | 848 | 0.8648 | 0.7601 |
| whitespace only | 2.3 | 645 | 0.7336 | 0.6169 |
| a different document (control) | 100.0 | 850 | 0.0155 | 0.0139 |
| comparison | write per head | write per layer | output norm | |
|---|---|---|---|---|
| document split halves | 67 | 0.992 | 0.992 | 0.992 (66) |
| leave-one-document-out | 67 | 0.953 | 0.978 | 0.934 (66) |
| base vs derived model | 17 | 0.990 | 0.990 | 0.987 |
| same family | 55 | 0.783 | 0.783 | 0.884 |
| same architecture, different family | 108 | 0.820 | 0.820 | 0.841 |
| different architecture | 2031 | 0.373 | 0.373 | 0.436 (1965) |
| model | block | orth. | ratio | cross | rank | op. | op. orth. | |
|---|---|---|---|---|---|---|---|---|
| Qwen2.5-0.5B | value | 0.387 | 0.423 | 0.915 | 0.112 | 0.978 | 0.343 | 0.298 |
| value + key | 0.395 | 0.425 | 0.930 | 0.103 | 0.979 | 0.357 | 0.315 | |
| value + key + query | 0.376 | 0.401 | 0.935 | 0.094 | 0.977 | – | – | |
| TinyLlama-1.1B | value | 0.216 | 0.258 | 0.834 | 0.386 | 0.960 | 0.166 | 0.141 |
| value + key | 0.226 | 0.265 | 0.852 | 0.373 | 0.959 | 0.218 | 0.189 | |
| value + key + query | 0.221 | 0.258 | 0.858 | 0.360 | 0.954 | – | – |
| vs all other models | vs other families | ||||
|---|---|---|---|---|---|
| map | agreement | different document | agreement | different document | two models |
| unweighted profile | 0.8612 | 0.0334 | 0.8076 | 0.0321 | 0.7652 |
| influence, gradient length | 0.7722 | 0.0336 | 0.6768 | 0.0316 | 0.6295 |
| influence, substitution | 0.7759 | 0.0328 | 0.6828 | 0.0308 | 0.6349 |
| influence, gradient input | 0.6568 | 0.0344 | 0.5797 | 0.0318 | 0.4771 |
| target | key-value heads | 1 vs 199 | 5 vs 195 | 20 vs 180 | 100 vs 100 | top decile | prefill queries |
|---|---|---|---|---|---|---|---|
| Qwen3-8B | 288 | 0.9828 (0.9704) | 0.9952 | 0.9985 | 0.9995 | 1.0000 | 0.9624 |
| Llama-3.1-8B | 256 | 0.9830 (0.9744) | 0.9951 | 0.9985 | 0.9994 | 0.9259 | 0.9394 |
| phi-4 | 400 | 0.9836 (0.9706) | 0.9954 | 0.9986 | 0.9992 | 0.9512 | 0.9681 |
| Qwen3-32B | 512 | 0.9815 (0.9512) | 0.9952 | 0.9986 | 0.9993 | 1.0000 | 0.9656 |
| Mistral-7B | 256 | 0.9829 (0.9729) | 0.9954 | 0.9984 | 0.9994 | 1.0000 | 0.9666 |
| target | LU-KV | KVzip+ | Proportional | Prefill attention | key-value heads |
|---|---|---|---|---|---|
| Qwen3-8B | 0.81 | 0.92 | 0.96 | 0.13 | 288 |
| Llama-3.1-8B | 0.80 | 0.91 | 0.95 | 0.38 | 256 |
| phi-4 | 0.81 | 0.92 | 0.97 | 0.30 | 400 |
| Qwen3-32B | 0.80 | 0.91 | 0.98 | 0.17 | 512 |
| Mistral-7B | 0.81 | 0.93 | 0.96 | 0.42 | 256 |
| mean over targets | 0.81 | 0.92 | 0.96 | 0.28 | – |
| offline, per target | online, per document | offline time, Mistral-7B | ||
|---|---|---|---|---|
| AdaKV + EA | none | none | none | |
| AdaKV + KVzap | surrogate training on KVzip’s score | surrogate call, not counted | 4 h 14 m, one H100 | |
| KVzip | none | one extra target forward | none | |
| LU-KV + EA | per-head budget curve calibration | none | published curve | |
| HM + EA | per-head budget table, 200 pretraining documents | none | 34 min | |
| HM + Guide | the same table and a guide map | one Qwen2.5-0.5B-Instruct forward | 36 min |
| RULER, context 4096 | RULER, context 8192 | ||||
|---|---|---|---|---|---|
| Target | 4 | 8 | 16 | 8 | 16 |
| Qwen3-8B | 94.8 ( 0.2 ) | 91.9 (0.2) | 73.1 ( 0.2) | 89.1 (0.1) | 69.5 (0.4) |
| Llama-3.1-8B | 95.0 ( 0.1) | 90.8 ( 1.5 ) | 65.1 ( 1.2 ) | 86.3 ( 1.7 ) | 60.7 ( 2.1 ) |
| phi-4 | 90.8 ( 0.6 ) | 84.8 ( 3.0 ) | 66.8 ( 1.7 ) | 82.8 ( 2.1 ) | 67.3 ( 1.1 ) |
| Qwen3-32B | 95.0 ( 0.2 ) | 92.0 ( 1.2 ) | 67.6 ( 11.5 ) | 90.9 ( 1.1 ) | 66.5 ( 11.4 ) |
| Mistral-7B | 89.3 ( 1.2 ) | 83.2 ( 1.1 ) | 63.2 ( 2.2 ) | 79.7 ( 0.7 ) | 57.8 ( 3.3 ) |
| 4 | 8 | 16 | |
| AdaKV + EA | 88.4 | 72.8 | 46.5 |
| HM + EA | 95.0 | 91.8 | 73.3 |
| HM + KVzap | 94.9 | 92.0 | 73.0 |
| Proportional (reconstruction) + EA | 94.8 | 91.9 | 73.1 |
| Proportional (reading) + EA | 61.1 | 53.0 | 37.7 |
| paired difference, with its 95% interval | |||
| cost | Qwen3-8B | Llama-3.1-8B | phi-4 | Qwen3-32B | Mistral-7B | |||||||
| offline | online | 8 | 16 | 8 | 16 | 8 | 16 | 8 | 16 | 8 | 16 | |
| AdaKV + EA | 71.7 | 50.9 | 41.2 | 15.8 | 41.7 | 13.6 | 64.1 | 38.4 | 33.5 | 20.5 | ||
| AdaKV + KVzap | 86.6 | 46.5 | 86.7 | 60.5 | 70.8 | 43.9 | 88.5 | 50.3 | 67.0 | 40.2 | ||
| KVzip | 89.8 | 55.6 | 90.1 | 73.6 | 88.0 | 64.2 | 95.0 | 92.1 | 82.5 | 66.3 | ||
| LU-KV + EA | 72.9 | 55.7 | 87.7 | 62.4 | 86.5 | 68.8 | 73.3 | 38.6 | 78.8 | 58.3 | ||
| HM + EA | 89.0 | 69.1 | 88.0 | 62.8 | 84.9 | 68.4 | 92.0 | 77.9 | 80.5 | 61.1 | ||
| cost | Qwen3-8B | Llama-3.1-8B | Qwen3-32B | Mistral-7B | ||||||
| offline | online | 8 | 16 | 8 | 16 | 8 | 16 | 8 | 16 | |
| AdaKV + EA | 42.1 | 33.1 | 36.4 | 28.4 | 46.0 | 39.2 | 31.0 | 27.6 | ||
| AdaKV + KVzap | 34.0 | 23.9 | 42.0 | 34.4 | 36.8 | 19.0 | 28.5 | 20.0 | ||
| KVzip | 44.7 | 28.0 | 44.5 | 33.8 | 50.7 | 45.2 | 43.8 | 38.2 | ||
| LU-KV + EA | 46.3 | 41.1 | 45.8 | 43.0 | 48.0 | 43.4 | 42.6 | 38.8 | ||
| HM + EA | 46.2 | 39.9 | 45.6 | 40.5 | 49.9 | 44.8 | 42.3 | 39.5 | ||
Attention Mechanisms
Attention mechanisms let neural networks weight information from other tokens or regions according to relevance, enabling context-dependent processing.
See all 513 papers