Attention rollout

On this page 7

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.

StepOperationPurpose
Head aggregationAverage (or take the maximum of) attention across headsOne matrix per layer
Residual adjustmentCompute 0.5 × A + 0.5 × IAccount for skip connections
Row normalizationMake each row sum to 1Keep a valid mixing distribution
Recursive productMultiply layer matrices from bottom to topTrack indirect information paths
ReadoutTake the row of the output token, such as [CLS]Relevance score per input token
Steps of the attention rollout computation

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.

ParameterCommon optionsEffect on the map
Head fusionMean, max, minMax highlights sharper regions
Residual weight0.5 identity is standardHigher values keep maps more local
Discard ratioDrop lowest 0-90% of weightsReduces background noise
Start layerFirst layer or a later oneLater starts emphasize high-level features
Readout token[CLS], last token, meanDefines which output is explained
Parameters that shape a rollout map

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.

MethodSignal usedClass-specificRelative cost
Raw attention visualizationOne layer’s weightsNoVery low
Attention rolloutAll layers’ weights, residual-adjustedNoLow
Attention flowMax-flow over attention graphNoHigh
Gradient-weighted rolloutAttention × gradientsYesModerate
Layer-wise relevance propagationConservation of relevanceYesModerate
Integrated gradientsPath integral of gradientsYesHigh
Attention rollout and related explanation methods

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.

SymptomLikely causeMitigation
Map looks uniformMany layers dilute attentionApply a discard ratio or later start layer
Same map for every classMethod is class-agnosticUse a gradient-weighted variant
Focus on special tokensAttention sinks such as [SEP]Inspect or exclude sink tokens
Map disagrees with ablationValue norms ignoredValidate with perturbation tests
Common problems with rollout maps

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.