Introduction
Large Language Models (LLMs) have demonstrated remarkable capabilities in complex reasoning and long-context processing. However, as sequence lengths grow, the computational and memory costs—particularly the Key-Value (KV) cache—become prohibitive. IAM (Inference through Attention Mapping) introduces a novel approach to mitigate these costs by leveraging the structural similarities between models of different scales within the same family.
The Bottleneck: KV Cache and Resource Consumption
The primary challenge in scaling LLM inference is the KV cache, which stores previous token states to prevent redundant computations. In long-context scenarios, this cache can consume significant GPU memory, limiting throughput and maximum sequence length. While existing methods like $H_2O$ focus on pruning unimportant tokens within a single model, IAM explores the potential of using external information from smaller, faster "sibling" models to optimize larger ones.
Methodology: Borrowing Attention
The core hypothesis of IAM is that models within the same family (e.g., Qwen2-0.5B and Qwen2-72B) exhibit highly correlated attention patterns. IAM exploits this scale-invariance through a two-stage process:
- Prefill Stage (Mapping): The input prompt is processed by both a Small Language Model (SLM) and the target Large Language Model (LLM). By calculating the cosine similarity between their attention matrices, the system identifies which SLM layers can effectively represent specific LLM layers.
- Decode Stage (Reuse): During token generation, the LLM bypasses the heavy computation of attention matrices for the mapped layers, instead reusing the pre-computed patterns from the lighter SLM.
To ensure stability, IAM utilizes a delayed establishment mechanism, allowing the mapping to settle based on sufficient context. Additionally, a brief instruction-tuning phase on the Alpaca dataset helps the LLM adapt to these "borrowed" attention patterns.
Experimental Results
The researchers evaluated IAM on the Qwen2 and LLaMA 3 series across benchmarks including MMLU, HotpotQA, and GovReport.
Memory and Speed Efficiency
IAM demonstrated significant resource savings. On average, it achieved a 22.1% reduction in KV cache usage. When combined with token-level eviction methods like $H_2O$, the savings are even more pronounced, as the two methods are orthogonal.
In terms of latency, IAM improved prefill speed (Time to First Token) by 12% to 17% and generation speed (Time Per Output Token) by approximately 11%.
Performance Retention
A critical finding is the robustness of the model under mapping. At a 30% mapping ratio, performance remained nearly identical to the baseline. Even at a 50% ratio, the model maintained high accuracy across language understanding and question-answering tasks. The consistency of the mapping remains over 91% throughout the generation process, validating the "compute once, reuse many times" strategy.
Discussion and Limitations
While IAM offers a compelling path toward efficient inference, several areas for future work remain:
- Granularity: Moving from layer-level to attention-head-level mapping could provide finer control.
- Kernel Compatibility: Current mapping requirements are incompatible with fused kernels like FlashAttention, which presents a trade-off between mapping efficiency and IO-aware optimization.
- Model Families: The technique currently requires models from the same family. Extending this to cross-family mapping (e.g., Mistral to LLaMA) is a significant open challenge.
In conclusion, IAM represents a significant step forward in LLM optimization, proving that "smaller siblings" can provide a high-fidelity blueprint for their larger counterparts, drastically reducing the environmental and financial costs of AI inference.
Summary updated