Attend First, Consolidate Later: On the Importance of Attention in Different LLM Layers

Amit Ben-Artzy,Roy Schwartz
2024-10-31
Abstract:In decoder-based LLMs, the representation of a given layer serves two purposes: as input to the next layer during the computation of the current token; and as input to the attention mechanism of future tokens. In this work, we show that the importance of the latter role might be overestimated. To show that, we start by manipulating the representations of previous tokens; e.g. by replacing the hidden states at some layer k with random vectors. Our experimenting with four LLMs and four tasks show that this operation often leads to small to negligible drop in performance. Importantly, this happens if the manipulation occurs in the top part of the model-k is in the final 30-50% of the layers. In contrast, doing the same manipulation in earlier layers might lead to chance level performance. We continue by switching the hidden state of certain tokens with hidden states of other tokens from another prompt; e.g., replacing the word "Italy" with "France" in "What is the capital of Italy?". We find that when applying this switch in the top 1/3 of the model, the model ignores it (answering "Rome"). However if we apply it before, the model conforms to the switch ("Paris"). Our results hint at a two stage process in transformer-based LLMs: the first part gathers input from previous tokens, while the second mainly processes that information internally.
Computation and Language
What problem does this paper attempt to address?
The problem this paper attempts to address is: In decoder-based large language models (LLMs), is there a difference in the importance of the attention mechanism at different layers? Specifically, the authors explore whether the representation of a given token at a particular layer has different importance in the following two aspects: 1. **As the input to the current token's attention mechanism**: How the representation of the current token affects its own processing. 2. **As the input to the future token's attention mechanism**: How the representation of the current token affects the processing of subsequent tokens. The authors validate this hypothesis through a series of experiments, including: - **Replacing hidden states**: Replacing the hidden states of certain layers with random vectors or hidden states from other prompts. - **Freezing hidden states**: Freezing the hidden states of all previous tokens starting from a certain layer. - **Skipping the attention mechanism**: Completely skipping the attention mechanism from a certain layer onwards, retaining only the feedforward sublayer. Through these experiments, the authors aim to reveal whether there are two stages in the information processing of large language models: the first stage primarily gathers information from previous tokens, and the second stage primarily processes the collected information internally. This research helps to better understand the internal working mechanisms of large language models and may provide new ideas for improving model efficiency.