AtMan: Understanding Transformer Predictions Through Memory Efficient Attention Manipulation

Björn Deiseroth, Mayukh Deb, Samuel Weinbach, Manuel Brack, Patrick Schramowski, Kristian Kersting

As generative transformer models grow to tens or hundreds of billions of parameters, understanding why they produce a specific output becomes both more critical and more difficult. Traditional explainability (XAI) methods often hit a wall: they are either too slow or require massive amounts of GPU memory.

A new paper from researchers at Aleph Alpha and TU Darmstadt introduces ATMAN (Attention Manipulation), a memory-efficient, modality-agnostic method for explaining transformer predictions. By shifting the focus from gradients to clever attention perturbations, ATMAN makes it possible to generate explanations for massive models in production environments where traditional methods fail.

TL;DR

ATMAN provides high-quality explanations for large-scale generative transformers at almost no additional memory cost. By perturbing attention scores instead of using backpropagation, it bypasses the memory bottlenecks of gradient-based methods while outperforming them on key benchmarks.

What Problem Does This Paper Address?

The current state-of-the-art for transformer explainability relies on gradient-based methods. These require backpropagation, which necessitates caching activations from the forward pass. This "caching" can consume nearly twice as much GPU memory as the model itself. For a 30B or 100B parameter model, this overhead makes XAI practically impossible on standard hardware.

Alternative "perturbation" methods (like LIME or SHAP) treat the model as a black box and modify the input to see how the output changes. However, these usually require thousands of forward passes to be accurate, making them prohibitively slow for transformers with long sequences.

Methods

ATMAN bridges the gap between these two approaches. Instead of perturbing the raw input or calculating gradients, it manipulates the attention mechanism during the forward pass.

  1. Attention Suppression: ATMAN applies a "suppression factor" to the pre-softmax attention scores of specific tokens. If suppressing a token significantly increases the cross-entropy loss of the target output, that token is deemed highly relevant.
  2. Correlated Token Suppression: In modalities like images, information is spread across many redundant patches. ATMAN uses cosine similarity in the embedding space to identify and suppress semantically related tokens simultaneously. This drastically reduces the number of perturbations needed to find the "essence" of a prediction.
  3. Parallelization: Unlike backpropagation, which is inherently sequential, ATMAN’s perturbations are independent. They can be batched together, allowing the model to evaluate the relevance of many tokens in a single parallelized step.
The integration of ATMAN into the transformer architecture. Modifier factors are applied to attention scores before the causal mask.

Datasets

The authors evaluated ATMAN across multiple modalities and model sizes:

  • Text: The SQuAD (Stanford Question Answering Dataset) was used to test language reasoning.
  • Vision-Language: OpenImages and GQA were used for Visual Question Answering (VQA) and visual reasoning tasks.
  • Models: Experiments were conducted on GPT-J (6B), MAGMA (6B, 13B, 30B), and BLIP, demonstrating the method's scalability and architecture agnosticism.

Key Insights and Ideas

  • Memory is the Bottleneck: The primary contribution isn't just a better explanation, but a deployable one. ATMAN’s memory usage is nearly identical to a standard forward pass, whereas gradient methods (like Chefer et al.) quickly exceed the 80GB limit of an A100 GPU as model size increases.
  • Embedding Space as a Proxy: Using cosine similarity in the embedding space to group tokens (especially image patches) is a highly effective way to handle the high dimensionality of transformer inputs without needing expensive search algorithms.
  • Steering Predictions: The paper demonstrates that by amplifying or suppressing specific tokens in the attention map, one can "steer" the model's generative direction (e.g., making it focus more on "math" vs. "soccer" in a prompt).
Figure 2: (a) Illustration of the proposed explainability method. First, we collect the original cross-entropy score of the target tokens (1). Then we iterate and suppress one token at a time, indicated by the red box ( ), and track changes in the cross-entropy score of the target token (2). (b) Manipulation of the attention scores, highlighted in blue, steers the model’s prediction into a different contextual direction. Note that we found measuring of such proper generative directions to perform better than radical token-masking, as we show later (c.f. Fig. 11). (Best viewed in color.)

Key Results

  • Superior Accuracy: On the SQuAD dataset, ATMAN achieved a Mean Average Precision (mAP) of 73.7, outperforming the gradient-based SOTA (72.7). On OpenImages, it reached 65.5 mAP, significantly higher than the competition.
  • Scalability: ATMAN successfully provided explanations for a 30B parameter MAGMA model, a feat that caused gradient-based methods to crash due to Out-of-Memory (OOM) errors.
  • Efficiency: While a single backprop pass is faster than multiple forward passes, ATMAN’s parallelizability means that with a batch size of 16, it can generate full image explanations in roughly 1-3 seconds—fast enough for many production use cases.
Scaling behavior: ATMAN's memory usage remains nearly constant and low compared to gradient-based methods which fail on larger models.

Limitations and Future Work

While ATMAN is a major step forward, the authors note a few areas for improvement:

  • Hyperparameter Sensitivity: The suppression factor ($f$) and similarity threshold ($\kappa$) were fixed empirically. These might need tuning for different tasks or model architectures.
  • Layer-wise Uniformity: Currently, ATMAN applies the same manipulation to every layer. The authors suggest that exploring layer-specific manipulations might reveal more about how concepts form throughout the network.
  • Interactive AI: The authors see ATMAN as a foundation for "Explanatory Interactive Machine Learning," where humans can use these relevance maps to provide feedback and correct model behavior in real-time.

Summary updated

BibTeX
@inproceedings{deiseroth2023atman,
  author = {Björn Deiseroth and Mayukh Deb and Samuel Weinbach and Manuel Brack and Patrick Schramowski and Kristian Kersting},
  title = {{AtMan: Understanding Transformer Predictions Through Memory Efficient Attention Manipulation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=PBpEb86bj7},
}
Figure