TL;DR
HShare is a novel framework that accelerates Large Language Model (LLM) decoding by sharing the indices of "critical" Key-Value (KV) cache tokens across layers, heads, and adjacent queries. By exploiting the high similarity of attention patterns throughout the model hierarchy, HShare achieves up to an 8.6× speedup in self-attention operations and a 2.7× boost in end-to-end throughput with minimal impact on accuracy.
The Bottleneck in Long-Context LLMs
As LLMs tackle increasingly long contexts—such as document analysis or extended dialogues—the Key-Value (KV) cache becomes a massive bottleneck. To generate each new token, the model must retrieve previous tokens' KV data, leading to high memory traffic and latency.
Existing "sparse attention" methods try to solve this by identifying and loading only a small subset of "critical" tokens. However, these methods face a catch-22:
- Fixed patterns (e.g., only looking at the most recent tokens) are fast but lose historical context, hurting accuracy.
- Dynamic patterns (selecting tokens based on the current query) are accurate but introduce significant computational overhead. The model has to "re-decide" which tokens are important for every single layer and head at every step. In some cases, this selection process can consume 50% of the total runtime.
HShare addresses this "selection overhead" by asking a fundamental question: Do we really need to re-calculate token importance every single time?
The HShare Methodology
The authors introduce HShare, a hierarchical sharing framework that operates at three distinct levels to eliminate redundant calculations:
- Layer-level & Head-level Sharing: Instead of every attention head in every layer calculating its own set of critical tokens, HShare allows multiple heads and layers to share the same set of token indices.
- Query-level Sharing: Since adjacent queries (the tokens being generated) are often similar, HShare reuses the critical token indices from the previous step for $k$ consecutive steps.
- Greedy Configuration Algorithm: To decide which layers or heads should share, the authors developed a greedy algorithm. During the "prefill" phase (when the model first processes the prompt), the algorithm measures the similarity between the attention patterns of different heads and layers. It then creates a "sharing map" used during the decoding phase.
By calculating these indices once and reusing them, HShare retains the accuracy of dynamic selection while approaching the blistering speed of fixed-pattern methods.
Key Insights and Ideas
- The "Aha" Moment - Redundancy: The core insight is that critical KV tokens are remarkably consistent. If a token is important for Head A in Layer 8, it is very likely also important for Head B in Layer 8, or even for heads in Layer 9.
- Prefill Predicts Decoding: The authors discovered that the similarity patterns observed when processing the initial prompt (prefill) remain highly consistent during the subsequent generation (decoding). This allows for "online" optimization without needing to retrain the model.
- Efficiency through Sparsity: By loading the full KV cache but only accessing the shared critical indices, HShare reduces the "memory wall" problem that plagues long-context inference.
Experimental Results
The researchers evaluated HShare across a variety of tasks (GSM8K, COQA, and LongBench) using LLaMA2-7b, LLaMA3-70b, and Mistral-7b. HShare demonstrated a superior balance between speed and performance compared to state-of-the-art methods like Quest, DoubleSparse (DS), and H2O:
- Speedup: Achieved up to an 8.6× reduction in self-attention latency compared to FlashAttention-2 and a 2.7× improvement in end-to-end throughput compared to the highly optimized GPT-fast baseline.
- Accuracy: On the LongBench benchmark, HShare maintained competitive accuracy, often outperforming KV eviction methods (like StreamingLLM and H2O) and matching the performance of much slower dynamic selection methods.
- Complexity: The computational complexity for selecting critical tokens was reduced from roughly $0.0625T$ (in previous dynamic methods) to as low as $0.008T$, where $T$ is the time for dense attention.
Limitations and Future Work
- Heuristic Ratios: Currently, the "sharing ratio" (how many layers/heads share indices) is a hyperparameter set by the user. The authors note that the optimal ratio can vary by task.
- Dynamic Adaptation: Future work could involve developing a method to dynamically adjust these sharing ratios on the fly based on the complexity of the input.
- Broader Architectures: While tested on popular Transformer models, the authors suggest exploring how HShare could be adapted for other architectures like Convolutional Neural Networks (CNNs) with attention or Graph Neural Networks (GNNs).
Summary updated