What Vision Transformers Attend To
Attention maps, high-norm artifact tokens and registers.
Ask a ViT where its class token looks and you get a heat map that seems to explain the prediction. For self-supervised DINO models the map outlines the object, without a single mask label. For most other large ViTs it is sprinkled with bright dots on empty sky and blank walls. Those dots turned out to be patches the network had repurposed for its own global computation, and handing it a few spare tokens, registers, cleaned up both its attention maps and its features.
What you’ll learn
- Define raw attention maps, attention rollout and attention flow, and prove that rollout maps lose their dependence on the query as depth grows when heads share where they attend.
- Describe how self-supervised ViTs' attention was shown to segment objects, and what attention maps can and cannot tell you about a prediction.
- Characterize the high-norm artifact tokens of large ViTs from the experiments of Darcet et al. (2024): where and when they appear, and what information they hold.
- Explain how registers remove the artifacts and what they change downstream, and weigh the competing accounts of what registers do: global memory, fixed attention biases, register neurons.
Reading an attention map
The simplest attention map of a ViT takes one head in the last block and reads the row of the class token: 196 weights, one per patch, reshaped to the grid and upsampled onto the image. It shows where that head, in that block, read from. It ignores everything before: by the last block each token is a mixture of many patches, mixed further by residual connections and the other heads.
Abnar & Zuidema (2020) proposed two ways to trace attention back to the input tokens. Both average the heads of each block and account for the residual connection, which carries every token's own representation forward, by mixing in the identity:
Are these better than raw attention? In a 6-layer transformer trained to predict a verb's number, the Spearman correlation between the class token's final-layer raw attention and the drop in confidence when each input word is blanked out was 0.29; for rollout it was 0.71 and for flow 0.70. Against input gradients the figures were 0.46, 0.54 and 0.61, and for a DistilBERT fine-tuned on sentiment all three stayed near 0.1. Chefer, Gur & Wolf (2021) pointed out two limits that remain: rollout returns the same map whatever class you ask about, and it cannot tell evidence for a prediction from evidence against it; their alternative propagates relevance scores for one class at a time through all the layers, attention and skip connections included. Rollout also has a structural limit, a consequence of multiplying stochastic matrices.
Take stochastic and and two rows of . Their difference is with , a vector summing to zero whose positive and negative parts each have mass . Normalizing each part gives two probability vectors :
and are mixtures of rows of , and by convexity of the norm two mixtures are never farther apart than the farthest pair of rows. So the coefficient is submultiplicative, and by induction over the blocks:
If every row of puts at least on a common token , every row of puts at least on it (for the row of itself, ). Any two rows then overlap by at least :
In a 12-block ViT, suppose every query in every block puts at least half of its head-averaged attention on one token, the same for all queries of that block (). What does the proposition guarantee about the largest total-variation distance between two tokens' rollout maps, in percent?
Show the answer
3.2 %
: whichever token you start from, its rollout map is within 3.2% of every other token's, and after 24 blocks within 0.1%. Tokens that collect attention from everywhere end up in everyone's map. This is only an upper bound: diffuse attention mixes even faster, while heads that share no common target, such as sharply local ones, are not forced to contract at all.
Attention that segments, and what it does not prove
The most striking attention maps came from self-supervision. Caron et al. (2021) trained ViTs with DINO and displayed the last block's attention from the class token, head by head: different heads covered different objects or parts, even small or partly hidden ones, with no segmentation labels at any point.
They also measured it. Thresholding a head's map to keep 60% of its attention mass gives a mask, scored against the ground-truth masks of PASCAL VOC 2012 by the Jaccard index (intersection over union). With the best head of a ViT-S/16, DINO's masks scored 45.9, a supervised ViT's 27.3 and a randomly initialized one's 22.0; ViT-S/16s trained with other self-supervised methods (MoCo-v2, BYOL, SwAV) scored in DINO's range. Such features were usable enough that LOST (Siméoni et al., 2021) localized objects without any labels from the features of a DINO ViT.
In a DINO ViT, one last-block head's class-token attention map outlines the dog in a photo. What does this establish?
- That the dog's pixels caused the model's output
- That this head, in this block, puts most of its attention weight on tokens on the dog
- That the model would fail if the dog were removed
- That the earlier blocks attended to the dog too
Show the answer
B. That this head, in this block, puts most of its attention weight on tokens on the dog
An attention map is a read pattern: it says how one head weighted the values it read. Causation, necessity and what earlier blocks did all need other evidence, such as ablations, interventions or rollout-like analyses with their own limits.
High-norm artifact tokens
DINO's clean maps turned out to be the exception. Darcet, Oquab, Mairal & Bojanowski (2024) found peaky artifacts in the attention maps of supervised ViTs (DeiT-III), text-supervised ones (OpenCLIP, an open reproduction of CLIP) and the self-supervised DINOv2: a few bright patches, usually on uniform background, that the class token attends to strongly. The original DINO showed none.
The artifacts have a simple signature. The norms of the output patch tokens of a DINOv2 ViT-g/14 are bimodal: most lie between 0 and 100, while 2.37% exceed 150, about ten times the typical norm. Taking norm above 150 as the definition of an "outlier", the authors asked where, when and in which models outliers arise, and what they contain:
| Question | Finding (DINOv2 ViT-g/14 unless stated) |
|---|---|
| Where in the image | on patches nearly identical to their four neighbors right after the patch embedding: redundant, usually background |
| Where in the network | they separate from the other tokens around block 15 of 40 |
| When in training | only after about a third of training |
| In which models | among DINOv2 sizes, only Large, Huge and giant; DeiT-III and OpenCLIP already at Base and Large; not in the original DINO |
| Local content | a linear probe predicts the patch's position with 22.8% top-1 accuracy, against 41.7% for normal tokens, and reconstructs its pixels with error 25.2 against 18.4 |
| Global content | one token used as the image representation, linear probe on ImageNet: 69.0% for an outlier, 65.8% for a normal patch, 86.0% for the class token; on Stanford Cars 85.2%, 10.8% and 91.5% |
The authors' interpretation: large, sufficiently trained models learn to recognize patches whose content is redundant and recycle their tokens as places to store, process and retrieve global information, discarding the local information that dense tasks need. They could not pin down which aspects of training produce the behavior; the pretraining method, model size and training length all play a role.
The mechanism is shared with language models. Softmax rows must sum to one, so heads need somewhere to put weight when nothing is relevant, and networks build such sinks out of a few tokens with huge activations; Attention Sinks & Massive Activations derives this. In a ViT with no spare token, the cheapest candidates are background patches. The rollout proposition explains why their effect on attention maps is so visible: tokens that draw attention from every query end up in every token's rollout map.
Think first Why would a ViT pick background patches, rather than random ones, to repurpose?
A patch that is nearly identical to its neighbors carries little information its neighbors do not already have, so overwriting its token costs the least: the local content can be recovered from the surroundings, at least for classification. The cost appears in dense tasks, where every patch token is expected to describe its own patch: segmentation and depth maps read garbage at the outliers, and methods that group patches by similarity, such as LOST, break.
Registers, and what they do
The fix is to give the network the tokens it was stealing. Darcet et al. append learnable register tokens to the input sequence, like the class token but with their outputs thrown away: only the class token and patch tokens are used, in training and at inference. The idea of extra memory tokens goes back to the Memory Transformer (Burtsev et al., 2020) in translation; here it has a concrete job.
import torch
import torch.nn as nn
class WithRegisters(nn.Module):
"""Wraps a ViT encoder: n learnable tokens join the sequence and are dropped at the output."""
def __init__(self, encoder, D, n=4):
super().__init__()
self.encoder, self.n = encoder, n
self.registers = nn.Parameter(0.02 * torch.randn(1, n, D)) # the same for every image
def forward(self, z): # z: (B, 1 + N, D), class token first, positions added
reg = self.registers.expand(len(z), -1, -1)
z = self.encoder(torch.cat([z[:, :1], reg, z[:, 1:]], dim=1))
return z[:, 0], z[:, 1 + self.n:] # class token and patch tokens; registers discardedFour registers add 4 tokens to 197 (or to 257 for a ViT-g/14 at 224 pixels), a small cost. Here, as in the released DINOv2 code, they carry no position embedding, since they stand for no place in the image.
| Model | ImageNet top-1 (linear) | ADE20K mIoU | NYUd depth RMSE (lower is better) | Object discovery, VOC 2007 (LOST corloc) |
|---|---|---|---|---|
| DINOv2 ViT-L | 84.3 → 84.8 | 46.6 → 47.9 | 0.378 → 0.366 | 35.3 → 55.4 |
| DeiT-III ViT-B | 84.7 → 84.7 | 38.9 → 39.1 | 0.511 → 0.512 | 11.7 → 27.1 |
| OpenCLIP ViT-B/16 | 78.2 → 78.1 | 26.6 → 26.7 | 0.702 → 0.661 | 38.8 → 37.1 |
In an ablation with DINOv2 ViT-L and 0 to 16 registers, one register was enough to remove the visible artifacts; dense tasks had an optimal number of registers, with most of the gain from the first, while ImageNet accuracy improved with more. Without being asked to, some registers came to attend to different objects in the scene.
What do registers do? The evidence points two ways.
- Global memory. Darcet et al.'s probes show that the outlier patches they replace hold global information, which suggests registers store it.
- Fixed attention biases. Sun, Chen, Kolter & Liu (2024) found that in DINOv2-with-registers ViT-G the massive activations sit in one register only, which also draws most of the class token's attention in the last block. Replacing every register's features in every block by their averages over 10,000 images left ImageNet accuracy within 0.2 points for all four model sizes. Inputs that never change act as a constant key and value: registers would then be learned attention sinks, the vision counterpart of language models' sinks.
- Register neurons. Jiang, Dravid, Efros & Gandelsman (2025) traced the outliers of OpenCLIP ViT-B/16 to a sparse set of MLP neurons, in the blocks where the outliers first form, that fire at the outlier positions. Copying those neurons' largest activation onto an extra, untrained token appended at test time, and zeroing them elsewhere, moves the outliers onto that token: a test-time register. Without retraining, it matched models trained with registers on several tasks and improved unsupervised object discovery by about 20 corloc points.
Not every artifact is of this kind. Yang et al. (2024) traced grid-like patterns in ViT features to the position embeddings and removed them with a learned denoiser, again without retraining the ViT.
Key takeaways
- Raw attention maps show where one head in one block reads from. Rollout multiplies head-averaged attention mixed with the identity, ; flow scores inputs by maximum flow; both tracked token-ablation importance better than raw attention in the original tests.
- Rollout is a product of stochastic matrices, so its rows contract at rate ; when heads share common targets the maps of all tokens converge, dominated by those targets.
- DINO's class-token attention segments objects without labels (Jaccard 45.9 against 27.3 for a supervised ViT-S/16 on VOC 2012), but an attention map is a hypothesis about the computation, not an explanation of the decision.
- Large ViTs trained long enough (DINOv2, DeiT-III, OpenCLIP) recycle about 2% of their tokens, on redundant background patches, into outliers with roughly ten times the typical norm that lose their local content and carry global information.
- Registers, learnable tokens whose outputs are discarded, remove the outliers and improve dense features and object discovery (DINOv2: 35.3 → 55.4 corloc); whether they act as memory or as fixed attention biases is debated, and register neurons let them be added at test time.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Attention rollout multiplies the matrices rather than the head-averaged attention alone. What does the identity term stand for?
- The class token, which attends to itself
- The residual connection, which carries each token's own representation into the next block
- The layer normalization before each block
- A correction that makes the product row-stochastic
Show the answer
B. The residual connection, which carries each token's own representation into the next block
Each block adds its attention output to its input, so information also flows straight from a token to itself. Abnar & Zuidema model that path with and renormalize, giving equal weight to the two routes.
What did linear probes reveal about the high-norm outlier tokens of DINOv2?
- They encode their own patch especially precisely, which is why their norm is large
- They are numerical noise that carries no information
- They appear on the most informative patches, such as faces and text
- They hold less information about their own position and pixels than normal tokens, and more about the image as a whole
Show the answer
D. They hold less information about their own position and pixels than normal tokens, and more about the image as a whole
Position prediction and pixel reconstruction from outliers were much worse than from normal patches, while classifying the whole image from a single outlier token was far better (85.2% against 10.8% on Stanford Cars). They sit on redundant background patches whose local content the model can afford to drop.
What happens to the outputs of the register tokens in a ViT trained with registers?
- They are discarded; only the class token and the patch tokens are used, in training and at inference
- They are averaged with the class token to form the image representation
- They are used as extra patch tokens for segmentation
- They are fed back as the registers' inputs for the next image
Show the answer
A. They are discarded; only the class token and the patch tokens are used, in training and at inference
Registers are learned inputs whose outputs nothing reads. Their only role is inside the network: attention can use them as storage or as sinks, so patch tokens no longer have to.
How do test-time registers (Jiang et al., 2025) remove the artifacts of a ViT that was trained without registers?
- By fine-tuning the model with four new learnable tokens
- By masking the outlier patches out of the attention of every block
- By appending an untrained token and moving the activations of a few register neurons onto it, zeroing them at the patches
- By lowering the softmax temperature so attention spreads more evenly
Show the answer
C. By appending an untrained token and moving the activations of a few register neurons onto it, zeroing them at the patches
A handful of MLP neurons create the high-norm outliers wherever they fire. Copying their largest activation onto an appended token and silencing them elsewhere moves the outlier onto that token, which then plays a register's role with no training at all.
Further reading
- T. Darcet, M. Oquab, J. Mairal & P. Bojanowski, "Vision transformers need registers," ICLR (2024).
- S. Abnar & W. Zuidema, "Quantifying attention flow in transformers," ACL (2020).
- M. Caron, H. Touvron, I. Misra, H. Jégou, J. Mairal, P. Bojanowski & A. Joulin, "Emerging properties in self-supervised vision transformers," ICCV (2021).
- S. Jain & B. C. Wallace, "Attention is not explanation," NAACL (2019).
- N. Jiang, A. Dravid, A. A. Efros & Y. Gandelsman, "Vision transformers don't need trained registers," NeurIPS (2025).