Attention Rollout in Vision
A transformer spreads attention across twelve layers, so one layer's map misleads. Rollout multiplies the layers into a single map from input patches to the final decision.
Why Does This Exist?
A vision transformer routes information through a dozen attention layers with residual connections around each. Reading only the last layer's attention claims the decision came from wherever the last layer looked, ignoring that the last layer looked at mixtures built by eleven earlier layers.
Rollout exists to track that flow. It models how much of each input patch reaches the final class token through every path, giving one map per image that operators can compare against Grad-CAM or saliency maps when the backbone is a transformer rather than a CNN.
Think of It Like This
Tracing river water through reservoirs
Twelve reservoirs in a chain each keep half their water and pass half downstream, mixing with local streams. Asking which spring fed the final dam by testing only the last reservoir's inlet misses eleven rounds of mixing.
Rollout is the ledger that multiplies the keep-and-pass fractions down the whole chain. The analogy stops at attention weights changing per input: reservoirs have fixed gates, while attention re-computes its mixing from the image each time.
How It Actually Works
Let layer carry attention over patches plus the class token. With residual connections, information flows through the mixed matrix , where is the identity (half rides the attention, half skips it). Rollout multiplies these mixed matrices from the first layer to the last:
Here is the attention matrix at layer , passes tokens through unchanged, is the layer count, and row for the class token gives each input patch's total flow. Read the class-token row as the map.
Worked example
A demo ViT has 12 layers over 16 patches plus the class token. Raw last-layer attention puts 0.41 of the class-token mass on the 4 dog patches. Multiplying all twelve mixed layers, rollout puts 0.68 on those patches and 0.32 elsewhere: divided by is , so rollout concentrates times more mass on the dog. The extra comes from early layers that had already gathered the ears and muzzle before the last layer looked.
Watch Out For
Reading rollout as causal proof
Rollout tracks information flow through attention, not what the model needed. The symptom is deleting the highlighted patches, watching accuracy hold, and concluding the map lied. It did not lie about flow; the model simply had redundant paths. Confirm with ablations before claiming necessity.
The Quick Version
- One attention layer misleads because residuals mix eleven earlier layers into its inputs.
- Rollout multiplies the mixed matrix across all layers into one flow map.
- On the demo image rollout puts 0.68 mass on the dog versus 0.41 raw.
- It reports flow, not necessity, so pair it with ablations.
- Use it for transformers; CNNs keep Grad-CAM.