InfiniteICL: Breaking the Limit of Context Window Size via Long Short-term Memory Transformation

Bowen Cao, Deng Cai, Wai Lam · OpenReview

Abstract

In-context learning (ICL) is critical for large language models (LLMs), but its effectiveness is constrained by finite context windows, particularly in ultra-long contexts. To overcome this, we introduce InfiniteICL, a framework that parallels context and parameters in LLMs with short- and long-term memory in human cognitive systems, focusing on transforming temporary context knowledge into permanent parameter updates. This approach significantly reduces memory usage, maintains robust performance across varying input lengths, and theoretically enables infinite context integration through the principles of context knowledge elicitation, selection, and consolidation. Evaluations demonstrate that our method reduces context length by 90% while achieving 103% average performance of full-context prompting across fact recall, grounded reasoning, and skill acquisition tasks. When conducting sequential multi-turn transformations on complex, real-world contexts (with length up to 2M tokens), our approach surpasses full-context prompting while using only 0.4% of the original contexts. These findings highlight InfiniteICL's potential to enhance the scalability and efficiency of LLMs by breaking the limitations of conventional context window sizes.

The Context Paradox

Large Language Models (LLMs) currently face a "context paradox." While users increasingly require models to process massive datasets—such as entire codebases, legal archives, or research libraries—the underlying Transformer architecture makes this prohibitively expensive. The quadratic scaling of attention mechanisms and the linear growth of the KV cache mean that longer contexts demand exponential hardware resources and often suffer from diminishing performance returns as the model "gets lost" in the middle of the prompt.

Existing solutions typically rely on context compression (removing "unimportant" tokens) or context distillation (summarization). However, these methods frequently lose critical nuances as the input size grows. InfiniteICL proposes a paradigm shift: instead of attempting to expand the model's "short-term memory" (the context window), we should transform that information into the model’s "long-term memory" (its internal weights).

The InfiniteICL Framework

Inspired by the human circadian rhythm—where daily experiences are consolidated into long-term memories during sleep—InfiniteICL utilizes a three-stage process to move knowledge from the prompt into the parameters:

  1. Context Knowledge Elicitation: Rather than feeding raw text directly, the model is steered to generate a "transfer set." This set includes task-specific Q&A pairs, multi-step reasoning chains, and open-ended summaries derived from the context.
  2. Path Selection: To ensure high-quality learning, the framework employs a "perplexity discrepancy" strategy. By identifying samples where the gap between context-aware and context-free predictions is highest, the system isolates the specific information the model did not previously know, filtering out redundant or noisy data.
  3. Memory Consolidation: The model undergoes a brief "test-time" fine-tuning. Using Forward KL divergence, the model’s parameters are updated so that its unconditional output matches the context-conditioned output of the original teacher model. Effectively, the model "learns" the context so it no longer needs to see it in the prompt to utilize the information.

Experimental Results

Efficiency and Performance

In single-turn tasks, InfiniteICL reduced the required context length by 90% while achieving 103% average performance relative to full-context prompting. This suggests that the consolidation process not only preserves information but may actually help the model organize and apply it more effectively than raw prompting.

Scaling to the Extreme

When tested on the LongBench v2 benchmark, which features real-world contexts up to 2 million tokens, InfiniteICL demonstrated remarkable stability. While traditional compression methods like SnapKV or LLMLingua often see performance collapse at this scale, InfiniteICL used only 0.4% of the original context tokens to outperform full-context prompting. The researchers found that for an 8K context window model, the "sweet spot" for processing and digesting information is in 5K-token chunks.

Reasoning vs. Recall

The study found that InfiniteICL prioritizes comprehension over rote memorization. While it achieved a 74% recovery rate on simple fact recall compared to full-context prompting, it excelled in reasoning and skill acquisition, reaching up to 123% recovery. This indicates that the parameter-update process is particularly well-suited for complex cognitive tasks.

Key Insights

  • Parameters as Storage: The core innovation is treating the entire parameter set of a Transformer as the state of a meta-recurrent neural network. Updating weights is not just fine-tuning; it is a method of high-density information storage.
  • Quality Over Quantity: Performance peaked at approximately 200 high-quality Q&A pairs. Adding more redundant data actually degraded the model's ability to consolidate knowledge, highlighting the importance of the Path Selection phase.
  • Superiority over Baselines: InfiniteICL consistently outperformed state-of-the-art compression methods. On many-shot ICL tasks, it achieved scores in the 80s, whereas traditional compression baselines often struggled to exceed 30.

Limitations and Future Directions

The primary trade-off for InfiniteICL is computational cost. Gradient-based fine-tuning (even using LoRA) is more intensive than simple inference. While it significantly reduces KV cache memory requirements, it introduces a "training" overhead during the consolidation phase.

Future research will focus on expanding the variety of architectures tested beyond Llama-3-8B and exploring the use of hypernetworks. Hypernetworks could potentially generate parameter updates instantly, removing the need for iterative gradient descent and making the memory transformation process near-instantaneous.

Summary updated

BibTeX
@inproceedings{cao2025infiniteicl,
  author = {Bowen Cao and Deng Cai and Wai Lam},
  title = {{InfiniteICL: Breaking the Limit of Context Window Size via Long Short-term Memory Transformation}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
  url = {https://openreview.net/forum?id=jWcPDWhVWa},
}
Figure