Abstract
Modern Large Language Models (LLMs) are constrained by a fixed context window, primarily due to the quadratic computational cost of self-attention. This limitation hinders tasks requiring extensive context, such as many-shot in-context learning (ICL) and retrieval-augmented generation (RAG). We present Parallel Context Windows (PCW), a training-free method that enables off-the-shelf LLMs to process significantly longer sequences. By reusing positional embeddings across parallel windows and employing a specific attention masking strategy, PCW allows models to aggregate information from multiple context chunks during inference without retraining.
Introduction
The context window is a fundamental bottleneck for LLMs, defining the maximum number of tokens a model can process in a single pass. Increasing this window typically requires expensive retraining or architectural changes to manage the quadratic scaling of attention. This constraint is particularly problematic for many-shot ICL, where high-cardinality tasks (e.g., intent classification with 150 classes) cannot fit sufficient examples into a standard 2,048-token window. Similarly, RAG systems often struggle when forced to truncate retrieved documents to fit within the model's limits. PCW addresses these issues by allowing "frozen" models to handle extended contexts post-hoc.
Methodology
Parallel Context Windows (PCW) modifies the Transformer architecture during inference through two primary mechanisms:
- Positional Embedding Reuse: Instead of unique positions for a massive sequence, PCW divides the input into $B$ parallel windows. Each window reuses the same set of positional embeddings (e.g., starting from position 1). This signals to the model that each chunk is equally relevant to the final query.
- Sparse Attention Masking: To maintain efficiency and adhere to the model's training distribution, tokens within a window only attend to others in the same window.
- Task Token Aggregation: The "task tokens" (the query or test example) are placed at the end of the sequence. Unlike context tokens, task tokens are permitted to attend to all windows simultaneously, effectively joining the information processed in parallel.
This approach keeps the computational cost linear with respect to the number of windows, rather than quadratic, while enabling the model to "see" a much larger set of examples or documents.
Experimental Evaluation
The effectiveness of PCW was evaluated across 15 classification datasets, information extraction tasks (ATIS, SQuAD), and retrieval-based QA (Natural Questions). Testing utilized AI21’s Jurassic-1 (7B to 178B parameters) and GPT-2 models. The results highlight that PCW is particularly effective for high-cardinality tasks where the number of output classes exceeds the capacity of a single context window.
Key Results and Discussion
PCW demonstrated significant performance gains, especially as model size increased. For classification tasks with more than five classes, PCW led to average improvements of 6.7 to 7.9 points across different model scales.
On the BANKING77 intent classification dataset, accuracy rose from approximately 55% to over 70% for the 178B parameter model by leveraging the additional examples provided through parallel windows. Furthermore, PCW was found to reduce the variance typically associated with example ordering in ICL, providing a more stable performance profile. However, the method is less suited for tasks requiring inter-window reasoning, such as multi-hop QA, because the parallel windows cannot attend to each other.
Conclusion
Parallel Context Windows offer a powerful, training-free solution for extending the context capabilities of existing LLMs. By parallelizing the processing of independent context chunks, PCW enables many-shot learning and improved retrieval performance at a linear computational cost. Future work may explore brief fine-tuning to further enhance the model's ability to synthesize information across these parallel streams.
Summary updated