Reducing Transformer Key-Value Cache Size with Cross-Layer Attention

Key-value (KV) caching plays an essential role in accelerating decoding for transformer-based autoregressive large language models (LLMs). However, the amount of memory required to store the KV cache can become prohibitive at long sequence lengths and large batch sizes. Since the invention of the transformer, two of the most effective interventions discovered for reducing the size of the KV cache have been Multi-Query Attention (MQA) and its generalization, Grouped-Query Attention (GQA). MQA and GQA both modify the design of the attention block so that multiple query heads can share a single key/value head, reducing the number of distinct key/value heads by a large factor while only minimally degrading accuracy. In this paper, we show that it is possible to take Multi-Query Attention a step further by also sharing key and value heads between adjacent layers, yielding a new attention design we call Cross-Layer Attention (CLA). With CLA, we find that it is possible to reduce the size of the KV cache by another 2x while maintaining nearly the same accuracy as unmodified MQA. In experiments training 1B- and 3B-parameter models from scratch, we demonstrate that CLA provides a Pareto improvement over the memory/accuracy tradeoffs which are possible with traditional MQA, enabling inference with longer sequence lengths and larger batch sizes than would otherwise be possible

Paper

References (39)

Scroll for more · 27 remaining

Similar papers

Peer review

Reviewer mqB56/10 · confidence 3/52024-07-13

Summary

To resolve the costly memory consumption of KV cache in transformer-based LLMs, this paper proposes Cross-Layer Attention (CLA). In contrast to multi-query attention (MQA) and grouped-query attention (GQA) which share KV cache across attention heads, CLA shares KV cache across contiguous layers. Pre-training experiments prove the effectiveness of CLA over MQA and GQA.

Strengths

1. The experiments are comprehensive and the design choices are clearly documented. 2. The problem studied is an important one and the approach is novel.

Weaknesses

1. Experimental results are not presented fully. Figure 3 only shows the validation perplexity for a subset of models, and Table 3 and 4 only presents the accuracy for a subset of models. I couldn't find the results elsewhere in the paper or the appendix. Presenting the results fully contributes to the holistic understanding of the effectiveness of the proposed approach. 2. Suggestions to experimental designs. The authors choose to pre-train 1B and 3B models from scratch to prove the effectiveness of CLA. It would perhaps be more convincing if the authors can choose a fully open source pre-trained model (such as OpenLLaMA) as baseline, and pre-train it with CLA to prove its effectiveness. Pre-training 1B and 3B models using a custom set of hyper-parameters and datasets is less convincing in comparison. 3. Training loss curves are missing. Training loss is important for understanding whether the models have fully converged. 4. Citation formats may be incorrect. Many references on page 10-12 only show author names, title, and year, and omit publication venue. 5. Some typos. Line 16: "which are possible" -> "which are impossible", line 18: "would otherwise be possible" -> "would otherwise be impossible".

Questions

1. Can the authors please provide some insights on why cross-layer sharing of KV cache may produce better models than GQA? The proposed method would be more convincing if some design justifications are provided. 2. Is it possible to adapt pre-trained models to using CLA through fine-tuning?

Rating

6

Confidence

3

Soundness

3

Presentation

2

Contribution

2

Limitations

Yes the authors addressed the limitations. I do not envision additional limitations.

Authorsrebuttal2024-08-07

Full Benchmarking Results for Models in our Design Space Exploration

Attached please find the full benchmarking results for the models in our 1B-scale design space exploration. (This comment accompanies our rebuttal, which could not fit the attached table due to length constraints.) |Model|$\uparrow$ hellaswag|$\uparrow$ piqa|$\uparrow$ winogrande|$\uparrow$ sciq|$\uparrow$ openbookqa|$\uparrow$ boolq|$\uparrow$ arc-e|$\downarrow$ wikitext (PPL)| |-|-|-|-|-|-|-|-|-| |H128-MHA|33.88|67.19|53.12|81.1|19|61.62|52.15|20.90| |H128-GQA4|33.82|67.79|51.62|78.6|18.6|60.73|51.47|21.38| |H128-GQA2|33.34|67.85|53.04|79.6|20|60.89|50.97|21.64| |H128-MQA|33.53|67.79|51.07|78.4|18.6|56.61|51.35|21.79| |H64-MQA|33.24|67.52|50.04|75.8|17|59.39|51.22|22.31| |H46-MQA|32.99|66.7|52.41|77.9|19.2|60.18|49.34|22.59| |H32-MQA|32.58|67.8|50.99|74.5|18.4|59.94|49.02|23.76| |H512-MQA-CLA2|33.68|67.68|52.33|77.3|18.8|55.72|52.19|22.42| |H256-MQA-CLA2|33.9|67.74|49.8|77.4|18.2|60.34|50.04|21.64| |H128-MQA-CLA2|33.29|67.63|49.88|78.3|18|59.51|49.62|21.82| |H90-MQA-CLA2|33.15|67.41|51.85|76.7|17.2|59.11|52.06|22.13| |H64-MQA-CLA2|32.71|67.36|51.7|74.9|19.4|54.68|50.88|22.43| |H256-GQA4-CLA2|33.63|66.92|51.78|78.5|18.6|60.43|51.18|21.40| |H128-GQA4-CLA2|33.64|67.74|50.59|78.1|18.6|58.78|51.09|21.66| |H128-GQA2-CLA2|33.39|67.14|52.17|77.3|19.8|59.45|51.26|21.83| |H128-MQA-CLA3|32.91|67.74|51.54|76.6|18|54.53|51.18|22.18| |H128-MQA-CLA4|32.51|67.57|51.85|75.4|18.6|59.33|51.73|22.62| |H128-MQA-CLA2-KeepEnds|33.58|68.12|52.72|76.2|19.2|60.12|51.64|21.88| |H128-MQA-CLA2-DenseFront|33.43|67.3|52.57|75.7|19.4|49.14|50.88|22.09| |H128-MQA-CLA2-DenseBack|32.71|66.65|51.7|76.5|17.4|59.69|50.51|22.8|

Reviewer mqB52024-08-08

Thank you to the authors for the detailed response. My concerns have mostly been addressed. I think the additional clarifications and experimental results are a great addition to the paper. I have adjusted my initial rating accordingly.

Authorsrebuttal2024-08-08

Thank You

We are glad that we were able to address the reviewer's questions, and thank them for their response.

Reviewer skpH7/10 · confidence 4/52024-07-14

Summary

In this paper, the authors proposed an approach, Cross-Layer Attention (CLA), to accelerate the autoregressive generation procedure of Large Language Models. Going beyond multi-query attention, the main idea of CLA is to share the Key-Value caches among attention layers. Intuitively, this idea is straightforward to further reduce the size of the KV cache that must be stored during generation. The authors conducted several experiments covering different model sizes and combinations between CLA and GQA/MQA to verify the effectiveness of the CLA module.

Strengths

1. The problem this paper aims to tackle has great significance in real-world applications of LLMs. 2. Overall, the proposed CLA approach is simple and easy to implement, which is friendly for practical engineering. The paper is also easy to follow. 3. **Efficiency**: from the experimental results, the CLA module can achieve further acceleration beyond MQA/GQA approaches across different model sizes. 4. **Performance**: it is interesting to see that the cross-layer sharing of KV caches does not hurt the performance of LLMs a lot, which further serves as support evidence that the CLA approach can be applied in practice.

Weaknesses

1. **The comprehensiveness of experiments can be further improved.** - **Model sizes**: the current version of this paper only verifies the effectiveness of CLA on 1B and 3B Transformer language models. Although the experimental results demonstrate that CLA does not bring performance drop on real-world tasks for these two model sizes, it is also questionable whether modern LLMs with >10 and > 100 billion parameters could still use this approach to achieve better accuracy-efficiency. After all, there exist many approaches that are only effective on small-scale architectures in the literature. It is also understandable that the computational resources are restrictions for conducting such verification experiments, but I think it would be a great plus for improving the quality of this work. - **Design choices**: in Table 1 and Appendix B, the authors listed a bunch of Non-CLA baselines and MQA/GQA+CLA2/CLA3/CLA4 models. However, CLA-only models are not compared. It would be questionable whether CLA can only be used with MQA/GQA together.

Questions

1. In lines 139-141, could you explain why using separately-learnable affine layer-norm parameters for the KV projection blocks and Q blocks in attention? 2. Similar to Sec 3.2.2, how is the robustness of CLA against other hyper-parameters like batch size?

Rating

7

Confidence

4

Soundness

3

Presentation

3

Contribution

3

Limitations

The authors discussed limitations of this work in Sec 4.

Reviewer skpH2024-08-10

Thank you for your responses. Although I still think the potential of this work should be further evaluated by using models of larger sizes, I understand the limitations of computational resources. I choose to raise my rating to 7.

Reviewer 8ZcC8/10 · confidence 5/52024-07-27

Summary

This paper introduces a new KV cache compression technique by sharing KV cache cross-layers called CLA. It can be integrated with most of the existing KV cache compression technique like MQA, GQA, and quantization. When applying over GQA, CLA can further reduces KV cache size by 2× while maintaining similar accuracy. Experiments with 1B- and 3B-parameter models show that CLA offers better memory/accuracy trade-offs, allowing models to handle longer sequences and larger batch sizes.

Strengths

- Simple and effective idea. It introduces an orthogonal dimension to the existing KV Cache compression methods. It can easily be integrated with existing KV cache techniques, like MQA/GQA, quantization, token eviction. - The writing and presentation is easy to follow - The proposed Cross-Layer Attention (CLA) does not require custom implementation and easily be deployed for any end-devices.

Weaknesses

I personally like this paper and vote for acceptance. However, I think the experimental design could be improved to make it more solid: - Only Wikitext Perplexity is reported, which is a weak indicator of LLM ability. While I understand that LLM evaluation is challenging and time-consuming, I suggest the authors also report the MMLU score, even if only on a subset. - Can CLA work under continuous pretraining scenarios like GQA? Namely, can a pretrained LLM be continuously tuned into a CLA-based model, even though the compression ratio might not be as high in this case? I ask this because pretraining LLMs is extremely expensive, as seen with models like Llama 3.1. It is risky and costly to train another open-sourced CLA model from scratch. If we can adapt existing models into CLA-based models, this paper could have a much greater impact. - One of the main motivations for KV Cache compression is long-context inference. However, long-context tasks like few-shot learning or multi-doc QA are much harder than the "short" tasks. I understand that long-context evaluation is challenging for pretrained models due to lack of alignment. Still, I think the authors could show some passkey retrieval results, as this task does not require much alignments.

Questions

Check Weaknesses point 2

Rating

8

Confidence

5

Soundness

3

Presentation

3

Contribution

4

Limitations

No major limitations.

Reviewer 8ZcC2024-08-09

Thank you for your clarification. I am satisfied with the response. Good Luck!

Program Chairsdecision2024-09-25

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC