"APE: Faster and Longer Context-Augmented Generation via Adaptive Parallel Encoding"
Below podcast on this paper is generated with Google's Illuminate.
https://arxiv.org/abs/2502.05431
The problem is that Context-Augmented Generation (CAG) in LLMs is slow due to repeated encoding of context. Parallel encoding speeds up this process by pre-computing context representations, but it reduces accuracy. This paper introduces Adaptive Parallel Encoding (APE) to solve the accuracy issue of parallel encoding without sacrificing speed.
APE aligns the attention of parallel encoding with sequential encoding. It uses techniques that require no training. This makes CAG both fast and accurate.
-----
📌 APE offers a practical, training-free method to enhance parallel encoding. It cleverly aligns attention distribution, recovering accuracy losses inherent in parallel processing for CAG.
📌 This Adaptive Parallel Encoding method achieves a significant speedup of 4.5x by optimizing prefilling time. It makes long context and many-shot context augmented generation feasible without retraining.
📌 By using shared prefix, temperature scaling, and scaling factor, APE effectively bridges the performance gap between fast parallel encoding and accurate sequential encoding in LLMs.
----------
Methods Explored in this Paper 🔧:
→ Adaptive Parallel Encoding (APE) is introduced. APE improves parallel encoding for Context-Augmented Generation.
→ APE addresses the accuracy drop in parallel encoding compared to sequential encoding. It achieves this without model training.
→ APE uses three key mechanisms. First, it prepends a shared prefix to contexts. This shared prefix avoids issues from initial tokens.
→ Second, APE adjusts attention temperature. Lowering the temperature sharpens attention on relevant tokens.
→ Third, APE applies a scaling factor. This factor counteracts magnitude changes from temperature adjustments.
→ These steps align the attention distribution of parallel encoding with sequential encoding. This alignment recovers the accuracy of parallel encoding.
-----
Key Insights 💡:
→ Key insight is that Key-Value (KV) states from independent contexts can be combined. This is due to the "attention sink" phenomenon in LLMs.
→ However, there are misalignments between parallel and sequential encoding. These misalignments occur particularly at the initial and recent token positions within each context.
→ APE is designed to address these residual misalignments. By addressing these, APE bridges the performance gap between parallel and sequential encoding.
-----
Results 📊:
→ APE maintains 98% of sequential encoding performance on RAG tasks. This is seen on ChatRAG-Bench.
→ APE maintains 93% of sequential encoding performance on In-Context Learning tasks. This is when using the same inputs.
→ APE outperforms standard parallel encoding by 3.6% in Retrieval-Augmented Generation tasks.
→ APE outperforms standard parallel encoding by 7.9% in In-Context Learning tasks.
→ APE achieves up to 4.5× speedup in end-to-end inference. This speedup is due to a 28× reduction in prefilling time for 128K context length.