Attention rollout is a post-hoc interpretability method that estimates how information from each input token reaches a given output position in a transformer, by recursively multiplying the attention matrices of all layers after adjusting them for residual connections. In Explainable AI, it is one of the simplest ways to turn raw attention weights into a single token-level relevance map for a whole model.
The method was introduced by Samira Abnar and Willem Zuidema in 2020, together with a related technique called attention flow. It became widely known through Vision Transformer studies, where rollout maps over image patches resemble saliency maps and are cheap to compute because they need no gradients and no extra forward passes.
How attention rollout propagates attention through layers
Attention rollout works by treating each layer’s attention as a mixing matrix that says how much every position draws from every other position, and then chaining those matrices from the first layer to the last. The product approximates how much each output position has absorbed, directly or indirectly, from each input token.
Raw attention in one layer ignores the residual connection, which carries each token’s own representation forward unchanged. Rollout models this by adding the identity matrix to the attention matrix and renormalizing each row, so a token keeps part of its own identity at every step. Without this correction, rollout maps quickly collapse into near-uniform noise.
The computation follows the steps summarized in the table below.
| Step | Operation | Purpose |
|---|---|---|
| Head aggregation | Average (or take the maximum of) attention across heads | One matrix per layer |
| Residual adjustment | Compute 0.5 × A + 0.5 × I | Account for skip connections |
| Row normalization | Make each row sum to 1 | Keep a valid mixing distribution |
| Recursive product | Multiply layer matrices from bottom to top | Track indirect information paths |
| Readout | Take the row of the output token, such as [CLS] | Relevance score per input token |
The final row is often reshaped into a patch grid for images or shown as a heat strip over words for text. The result is a class-agnostic map: it describes where information flows, not which tokens support a particular predicted class.
Key design choices and variants
Attention rollout has several free parameters that change the resulting map, and published implementations differ more than many users expect. Reporting these choices is essential for reproducibility.
| Parameter | Common options | Effect on the map |
|---|---|---|
| Head fusion | Mean, max, min | Max highlights sharper regions |
| Residual weight | 0.5 identity is standard | Higher values keep maps more local |
| Discard ratio | Drop lowest 0-90% of weights | Reduces background noise |
| Start layer | First layer or a later one | Later starts emphasize high-level features |
| Readout token | [CLS], last token, mean | Defines which output is explained |
The original paper also proposed attention flow, which models the network as a graph with attention weights as edge capacities and solves a maximum-flow problem for each input. Attention flow often correlates better with ablation-based importance, but it is far slower, which is why rollout is the version most practitioners actually use.
How attention rollout compares with other attribution methods
Attention rollout sits between plain attention visualization and gradient-based feature attribution. It improves on looking at a single layer’s weights, yet it remains a purely structural signal that ignores value vectors, feed-forward layers and the actual predicted class.
The table places rollout next to methods that are commonly used for the same purpose.
| Method | Signal used | Class-specific | Relative cost |
|---|---|---|---|
| Raw attention visualization | One layer’s weights | No | Very low |
| Attention rollout | All layers’ weights, residual-adjusted | No | Low |
| Attention flow | Max-flow over attention graph | No | High |
| Gradient-weighted rollout | Attention × gradients | Yes | Moderate |
| Layer-wise relevance propagation | Conservation of relevance | Yes | Moderate |
| Integrated gradients | Path integral of gradients | Yes | High |
Because rollout is class-agnostic, later work combined it with gradients or relevance propagation to produce class-discriminative transformer explanations. For a question such as why the model chose label A instead of label B, a contrastive or gradient-based method is usually more appropriate.
Where attention rollout is useful
Attention rollout is most useful as a fast sanity check on what a transformer attends to across its depth. It is popular for image classifiers built on Vision Transformers, for quick audits of text classifiers and for teaching how information mixes inside self-attention.
- Model debugging: detecting that a classifier relies on watermarks, borders or tokens such as punctuation.
- Dataset audits: spotting shortcut features across many images at low cost.
- Comparison of checkpoints: observing how relevance patterns change during fine-tuning.
- Education and documentation: illustrating token mixing in model cards or reports.
A practical rule is to use rollout for exploration and hypothesis generation, and then confirm important findings with an intervention such as occlusion sensitivity, activation patching or input ablation, which tests whether the highlighted tokens actually change the output.
Limitations and faithfulness concerns
The main limitation of attention rollout is questionable faithfulness: a high rollout score shows that information could flow from a token, not that the prediction depends on it. Attention weights describe how values are mixed, but the value vectors and MLP layers that transform those values are left out entirely.
| Symptom | Likely cause | Mitigation |
|---|---|---|
| Map looks uniform | Many layers dilute attention | Apply a discard ratio or later start layer |
| Same map for every class | Method is class-agnostic | Use a gradient-weighted variant |
| Focus on special tokens | Attention sinks such as [SEP] | Inspect or exclude sink tokens |
| Map disagrees with ablation | Value norms ignored | Validate with perturbation tests |
Rollout also assumes that layers combine linearly, which ignores nonlinearities and layer normalization. These issues do not make the method useless, but they mean a rollout map is a hypothesis, not a proof, and explanation faithfulness should be checked before any conclusion reaches a decision-maker.
Stripped to the essentials
A transformer model passes information through many layers. In each layer, every word or image piece looks at the others and borrows some of their information. After many layers, it becomes hard to tell where the final answer got its information.
Attention rollout follows the trail backward. It is like tracing who passed a message to whom in a long chain of conversations. Each step records how much attention went where. Multiplying all the steps together gives a rough map of which inputs mattered most. The map is quick to make, but it shows possible paths, not proof of cause.
Where it is applied
A team building a Vision Transformer to classify skin lesion photos reaches strong validation accuracy, yet they want to know what the model looks at before a clinical pilot. They compute attention rollout with mean head fusion and a 0.9 discard ratio for 2,000 test images, which takes minutes on a single GPU.
The maps reveal that for about one in ten benign cases, relevance concentrates on a ruler marking at the image edge rather than on the lesion. Occlusion tests confirm the shortcut: covering the ruler changes the prediction. The team crops and augments the training images, retrains the model and verifies with new rollout maps and ablations that attention now centers on the lesion itself.