Abstract
Multi-Layer Key-Value (MLKV) sharing is a novel approach designed to significantly reduce the memory footprint of Large Language Models (LLMs) during inference. By extending the concept of Key-Value head sharing across multiple transformer layers, MLKV achieves up to a 6x reduction in KV cache size compared to Multi-Query Attention (MQA) with negligible impact on model performance.
Introduction
The autoregressive generation process in LLMs requires storing "Keys" and "Values" from previous tokens in a KV cache to avoid redundant computations. As context lengths and batch sizes grow, this cache becomes a primary memory bottleneck, often exceeding the size of the model weights themselves. While techniques like Multi-Query Attention (MQA) and Grouped-Query Attention (GQA) mitigate this by sharing KV heads within a single layer, they are limited by the requirement of at least one KV head per layer. MLKV addresses this limitation by sharing KV heads across the depth of the model.
Methods: Multi-Layer Key-Value Sharing
MLKV generalizes the sharing mechanism found in MQA and GQA. While MQA shares a single KV head among all query heads within a layer, MLKV shares KV heads across multiple layers. This approach is motivated by the observation that successive transformer layers often perform similar computations.
As shown in the figure above, MLKV breaks the "one-head-per-layer" floor. For instance, in a 12-layer model, an MLKV-6 configuration uses only 6 KV heads, with each head shared by two adjacent layers.
Implementation via Uptraining
To validate MLKV without the cost of training from scratch, the researchers employed an "uptraining" strategy. They initialized MLKV models from pre-trained Pythia checkpoints (160M and 410M parameters) by averaging the weights of existing KV heads. These models then underwent a brief period of additional training on 5% of the original "The Pile" dataset to adapt to the shared head architecture.
Architectural Comparison
The architectural shift from standard Multi-Head Attention (MHA) to MLKV involves a fundamental change in how the attention mechanism accesses Key and Value tensors.
In MLKV, the attention block in a higher layer (Layer $m$) can directly utilize the Key and Value projections computed in a lower layer (Layer $n$), effectively bypassing the need for dedicated KV projections in the upper layer. This cross-layer dependency allows for a drastic reduction in the total number of KV heads stored in memory.
Key Results and Insights
The study yielded several critical findings across standard NLP benchmarks (ARC-e, LAMBADA, PIQA, SciQ):
- Memory Efficiency: MLKV-1 (a single KV head for the entire model) reduces cache size by 6x relative to MQA and 72x relative to MHA.
- Performance Stability: MLKV-6 achieved 49.06% average accuracy on benchmarks, nearly matching the 49.43% of MQA-12 while halving the memory requirement.
- Throughput Gains: Reduced memory usage translates directly to higher throughput. MLKV-2 supported a batch size of 940 on hardware where the baseline capped at 48.
The success of MLKV suggests that transformer layers exhibit significant redundancy in the information they store as keys and values, particularly across adjacent layers.
Limitations and Future Work
While promising, MLKV has currently been evaluated on relatively small models (up to 410M parameters). Future research is needed to determine if these savings scale to billion-parameter models like Llama. Additionally, the impact on more complex downstream tasks and the performance of models trained natively with MLKV from scratch remain areas for further exploration.
Summary updated