Attention Rollout is a technique for explaining Transformer predictions by computing the cumulative attention an output token pays to each input token. It assumes that attention weights can be linearly combined across layers, starting from the final layer and recursively multiplying the weight matrices backward to the input, thereby accounting for the mixing of attention through residual connections.
Glossary
Attention Rollout

What is Attention Rollout?
Attention Rollout is a feature attribution method that traces the flow of information through a Transformer model by recursively multiplying attention weight matrices across all layers to quantify how input tokens influence the final output.
Unlike raw single-layer attention, rollout captures the context mixing that occurs as information propagates through the network's depth. By treating the attention mechanism as a Markov chain, it produces a single, global saliency map showing the effective attention flow, making it a computationally efficient alternative to gradient-based methods like Integrated Gradients for visualizing token importance.
Key Characteristics
Attention Rollout is a flow-based explanation method that traces how information propagates through a Transformer's self-attention layers. Unlike gradient-based methods, it relies solely on the model's attention weights to quantify token-to-token influence.
Recursive Matrix Multiplication
The core mechanism involves treating attention weights as a Markov chain of information flow. Starting from the final layer, the attention matrix is recursively multiplied by the attention matrix of the preceding layer: Ã(s) = A(s) · Ã(s+1). This computation accounts for how attention in earlier layers influences attention in later layers, effectively tracing the mixing of information across all Transformer heads and layers to produce a single rollout map from output tokens back to input tokens.
Gradient-Free Explanation
Unlike Integrated Gradients or DeepLIFT, Attention Rollout does not require backpropagating gradients through the network. It operates purely on the post-hoc attention weights extracted during a forward pass. This makes it computationally lighter than gradient-based attribution methods and applicable to models where gradient access is restricted. However, this also means it ignores the value-pathway of the Transformer, assuming attention weights alone are a faithful proxy for feature importance.
Handling Residual Connections
A critical nuance is accounting for residual connections that skip layers in Transformer architectures. The standard rollout formulation adds an identity matrix to the attention matrix to represent the skip connection: 0.5 * A(s) + 0.5 * I. This ensures that a token's own information is partially preserved as it flows through the network, preventing the rollout signal from decaying too rapidly and providing a more stable attribution map.
Multi-Head Aggregation
Transformers use multi-head self-attention, where each head learns a distinct attention pattern. Attention Rollout must aggregate these parallel streams. The standard approach is to average the attention weights across all heads in a given layer before performing the recursive multiplication. This treats each head as an equally important information pathway, though more sophisticated variants may use head-specific weighting based on relevance scores.
Visualization as Heatmaps
The final output of Attention Rollout is a token-to-token attribution matrix where each cell (i, j) represents the cumulative attention flowing from output token i to input token j. For vision Transformers, this matrix can be reshaped into a 2D heatmap overlaid on the input image, highlighting which regions the model attended to for its classification. For text, it produces saliency-like highlighting of words most influential for a prediction.
Limitations & Assumptions
Attention Rollout makes a strong assumption that attention weights linearly correlate with feature importance, which is not always true. It ignores the value vectors and the non-linear transformations of the feed-forward network. This can lead to misleading attributions when attention heads serve as no-op or information-gating mechanisms rather than direct feature selectors. For more faithful explanations, methods like LIME or SHAP may be preferred.
Frequently Asked Questions
Clear, technical answers to the most common questions about how Attention Rollout traces information flow through Transformer models for explainability.
Attention Rollout is a feature attribution method that explains Transformer model predictions by recursively multiplying attention weight matrices across all layers to trace the flow of information from the output back to the input tokens. Unlike gradient-based methods, it relies solely on the attention weights learned during training. The algorithm starts by assuming each token attends to itself with a residual connection, then iteratively multiplies the attention matrices from the final layer down to the first, accounting for the mixing of information across attention heads. The resulting rollout matrix quantifies how much each input token contributed to the final representation of every other token, producing a heatmap of token-to-token influence that can be visualized directly over the input text or image patches.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Attention Rollout is one of many techniques for interpreting Transformer predictions. These related methods provide complementary approaches to feature attribution, visualization, and model transparency.
Attention Weights vs. Attention Rollout
Raw attention weights show token-to-token relationships within a single layer, but they fail to capture how information flows across the entire network. Attention Rollout addresses this by recursively multiplying attention matrices across all layers, accounting for residual connections. This produces a more faithful representation of how input tokens influence the final output. Raw attention often highlights syntactic neighbors, while rollout reveals the true semantic pathways through the model.
Layer-wise Relevance Propagation (LRP)
LRP is a backpropagation-based attribution method that redistributes the model's prediction score backwards through the network using conservative propagation rules. Unlike Attention Rollout, which operates solely on attention matrices, LRP leverages both activations and weights to assign relevance scores to input features. LRP is particularly effective for convolutional networks and can be adapted to Transformers, offering finer-grained token attribution than rollout alone.
Gradient-Based Saliency Maps
Saliency methods compute the gradient of the output with respect to the input to identify which tokens or pixels most influence a prediction. While computationally efficient, vanilla gradients can be noisy and fail to capture saturation effects. Integrated Gradients improves on this by accumulating gradients along a path from a baseline input, satisfying the completeness axiom. Attention Rollout provides a complementary structural view that is independent of gradient computation.
SHAP for Transformer Models
SHAP (SHapley Additive exPlanations) assigns each input token a Shapley value representing its marginal contribution to the prediction. For Transformers, computing exact Shapley values is computationally prohibitive, so TransformerSHAP and other approximations use attention patterns to reduce the feature space. Attention Rollout can inform these approximations by identifying the most salient token interactions before SHAP computation begins.
Attention Flow in Encoder-Decoder Models
In encoder-decoder Transformers like T5 or BART, Attention Rollout must account for three distinct attention mechanisms: self-attention in the encoder, self-attention in the decoder, and cross-attention between them. Rollout is typically applied separately to the encoder stack to explain input processing and to the cross-attention pathway to trace how the decoder attends to encoded source tokens during generation.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us