Mixture of In-Context Experts Enhance LLMs' Long Context Awareness

Hongzhan Lin, Ang Lv, Yuhan Chen, Chen Zhu, Yang Song, Hengshu Zhu, Rui Yan · DOI

Introduction

Large Language Models (LLMs) have revolutionized natural language processing, yet they struggle with "uneven awareness" in long sequences. While they can process thousands of tokens, they often fail to recall information buried in the middle of a prompt—a phenomenon known as the "lost-in-the-middle" effect.

Research suggests that Rotary Position Embeddings (RoPE) are a primary culprit. RoPE creates periodic attention patterns where certain relative distances result in attention "troughs," effectively blinding the model to tokens at those specific positions. Previous solutions like Attention Buckets were computationally expensive, requiring multiple model passes, while others like Ms-PoE used static, per-head assignments that lacked the adaptability needed for evolving conversations.

To address this, researchers have introduced Mixture of In-Context Experts (MoICE), a lightweight plug-in that dynamically routes tokens to the most effective positional embedding "experts," eliminating blind spots with minimal overhead.

The MoICE Architecture

MoICE reimagines the attention mechanism by treating different RoPE angles as specialized "experts." By combining multiple angles, the model can "fill in the gaps" of its own awareness.

Comparison of Attention Buckets, Ms-PoE, and the proposed MoICE architecture.

The core components of MoICE include:

  • In-Context Experts: Each expert is defined by a specific RoPE angle. Since different angles have troughs at different positions, a set of complementary angles ensures continuous coverage across the context window.
  • Dynamic Routing: A lightweight MLP router is integrated into every attention head. For each token, the router selects the $K$ most suitable experts from a candidate set.
  • Weighted Aggregation: Attention scores from the selected experts are weighted and combined to produce the final attention score.
  • Router-Only Training: To maintain efficiency and prevent "catastrophic forgetting," the original LLM parameters are frozen. Only the tiny routers are trained for a few hundred steps using a small subset of long-context data (e.g., 1,000 entries from OpenHermes-2.5).

Evaluation and Results

The researchers evaluated MoICE across several rigorous benchmarks, including L-Eval, LongBench, and MDQA. They also conducted a from-scratch pre-training experiment on OpenWebText using a 49M parameter model to demonstrate the architecture's scalability.

Key Performance Metrics

  • Solving "Lost-in-the-Middle": In Multi-Document QA (MDQA) tasks, MoICE maintained high accuracy regardless of whether the answer was at the beginning, middle, or end of the context. Standard models typically see a significant performance drop when information is centrally located.
  • Hardware Efficiency: MoICE is significantly more memory-efficient than ensemble methods. For a Llama-2-7B model, MoICE required only 19.4 GB of GPU memory, compared to 61.8 GB for the Attention Buckets method, while also being significantly faster.
  • Generalization: The method consistently outperformed state-of-the-art techniques like Positional Interpolation across various model families, including Llama-2, Mistral, and Qwen.

Insights and Future Directions

The success of MoICE stems from its token-level flexibility. Unlike static methods that assign angles to entire heads, MoICE adjusts its expert selection dynamically as the generation progresses. This ensures that the most relevant information is always in "focus," regardless of its shifting relative position.

While MoICE requires a small amount of training for its routers, its lightweight nature and superior performance make it an attractive candidate for standard LLM architectures. Future work may explore more complex routing strategies and larger-scale pre-training to determine if these benefits compound as models grow.

Summary updated

BibTeX
@inproceedings{lin2024mixture,
  author = {Hongzhan Lin and Ang Lv and Yuhan Chen and Chen Zhu and Yang Song and Hengshu Zhu and Rui Yan},
  title = {{Mixture of In-Context Experts Enhance LLMs' Long Context Awareness}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=RcPHbofiCN},
}
Figure