Structured Packing in LLM Training Improves Long Context Utilization

Konrad Staniszewski, Szymon Tworkowski, Sebastian Jaszczur, Henryk Michalewski, Lukasz Kucinski, Piotr Milos · OpenReview

Abstract

Recent advancements in long-context large language models have attracted significant attention, yet their practical applications often suffer from suboptimal context utilization. This study investigates structuring training data to enhance semantic interdependence, demonstrating that this approach effectively improves context utilization. To this end, we introduce the Structured Packing for Long Context (SPLiCe) method, which utilizes retrieval to collate mutually relevant documents into long and coherent training examples. We validate SPLiCe empirically across models of varying sizes — 3B, 7B, and 13B — achieving improved performance in long-context tasks, such as Qasper and HotpotQA. Remarkably, even brief fine-tuning with SPLiCe is sufficient to realize these benefits. Additionally, SPLiCe effectively mitigates the lost-in-middle phenomenon often observed in large models. Our comprehensive analysis of SPLiCe explores its design choices and reveals intriguing transfer effects; for instance, training on programming code enhances performance on natural language tasks.

Introduction

Modern Large Language Models (LLMs) are increasingly capable of handling massive context windows, ranging from 32K to over a million tokens. However, having a large window does not guarantee effective utilization. A persistent challenge is the "lost-in-the-middle" phenomenon, where models excel at retrieving information from the start or end of a prompt but fail when the relevant data is buried in the center.

This research posits that the root cause is the standard "Example Packing" training practice. In this paradigm, random, unrelated documents are concatenated to fill training sequences. This results in a "low dependency density," where the model rarely encounters training signals that require long-range cross-document reasoning. Consequently, the model fails to develop the necessary skills for deep context utilization.

Methods: Structured Packing for Long Context (SPLiCe)

To address this, we introduce SPLiCe (Structured Packing for Long Context). Unlike random packing, SPLiCe organizes training data to maximize semantic interdependence within a single sequence.

Comparison of standard Example Packing vs. SPLiCe (Structured Packing for Long Context).

The SPLiCe pipeline follows these steps:

  1. Seed Selection: A random document is selected from the corpus.
  2. Retrieval: A retriever (e.g., BM25, Contriever, or directory structures for code) identifies the top-$k$ most semantically similar documents.
  3. Sequence Construction: These related documents are organized (often via a tree structure) and flattened into a single training sequence.
  4. Fine-tuning: The model is fine-tuned on these structured samples, forcing it to learn how to navigate and connect information across long distances.

Experiments were conducted on 3B, 7B, and 13B models using mixtures of RedPajama, StarCoder, and StackExchange data.

Key Results

The impact of SPLiCe is most evident in long-context retrieval benchmarks.

Needle in a Haystack

In the "Needle in a Haystack" test, models must find a specific fact hidden within a long distractor text. While baseline models using standard packing struggle significantly when the "needle" is in the middle of the context, SPLiCe-tuned models achieve near-perfect accuracy across the entire 32K window.

Retrieval accuracy on the 'Needle in a Haystack' benchmark across context positions.

In-Context Learning and Real-World Tasks

SPLiCe significantly improves performance on multi-hop reasoning tasks like Qasper and HotpotQA. For instance, on the TREC classification task, a 3B model showed an 8.0 point accuracy gain with a 16K context window. Crucially, these improvements do not come at a "tax" to short-context performance; benchmarks like MMLU and GSM8K remained stable or slightly improved, suggesting that learning to use long context doesn't come at the expense of general reasoning.

Discussion and Insights

  • Dependency Density: The primary driver of long-context capability is the density of related information in training data. SPLiCe provides the necessary "practice" for the model to attend to distant but relevant tokens.
  • The Power of Code: Training on structured code data (grouped by repository) surprisingly boosts performance on natural language tasks. The inherent cross-referencing in code serves as a high-quality signal for learning long-range dependencies.
  • Efficiency: Long-context capabilities can be "unlocked" with as little as 2B to 6B tokens of fine-tuning, making it a highly efficient data-centric intervention compared to training from scratch.

Conclusion

SPLiCe demonstrates that data organization is as critical as architectural scaling for long-context LLMs. By replacing random example packing with semantically structured sequences, we can significantly improve a model's ability to utilize its entire context window, effectively solving the "lost-in-the-middle" problem and enhancing overall reasoning capabilities.

Summary updated

Abstract

Recent advancements in long-context large language models have attracted significant attention, yet their practical applications often suffer from suboptimal context utilization. This study investigates structuring training data to enhance semantic interdependence, demonstrating that this approach effectively improves context utilization. To this end, we introduce the Structured Packing for Long Context (SPLiCe) method, which utilizes retrieval to collate mutually relevant documents into long and coherent training examples. We validate SPLiCe empirically across models of varying sizes -- 3B, 7B, and 13B -- achieving improved performance in long-context tasks, such as Qasper and HotpotQA. Remarkably, even brief fine-tuning with SPLiCe is sufficient to realize these benefits. Additionally, SPLiCe effectively mitigates the lost-in-middle phenomenon often observed in large models. Our comprehensive analysis of SPLiCe explores its design choices and reveals intriguing transfer effects; for instance, training on programming code enhances performance on natural language tasks.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
TREC3B FoT SPLiCeclassification accuracy79.3+5.4 vs baselinesplit: test · params=3B
Source quote
L121: 32K │ 73.9 │ 79.3 │ 5.4~[{4.7,6.2]}~~ │ 82.9 │ 85.9 │ 3.0~[{2.6,3.6]}
Qasper7B FoT SPLiCequestion-answering score23.12-shot · params=7B
Source quote
L147: 7B_{\text{FoT}} │ 22.8 │ 23.1 │ 26.0 │ 27.3 │ 1.3~[{1.2,1.5]}
HotpotQA7B FoT SPLiCequestion-answering score27.310-shot · params=7B
Source quote
L147: 7B_{\text{FoT}} │ 22.8 │ 23.1 │ 26.0 │ 27.3 │ 1.3~[{1.2,1.5]}
Reported baseline / comparator measurements (3)
BenchmarkMethodMetricScoreProtocol / Evidence
TREC3B FoT Baseline baselineclassification accuracy73.9split: test · params=3B
Source quote
L121: 32K │ 73.9 │ 79.3 │ 5.4~[{4.7,6.2]}~~ │ 82.9 │ 85.9 │ 3.0~[{2.6,3.6]}
Qasper7B FoT Baseline baselinequestion-answering score22.82-shot · params=7B
Source quote
L147: 7B_{\text{FoT}} │ 22.8 │ 23.1 │ 26.0 │ 27.3 │ 1.3~[{1.2,1.5]}
HotpotQA7B FoT Baseline baselinequestion-answering score26.010-shot · params=7B
Source quote
L147: 7B_{\text{FoT}} │ 22.8 │ 23.1 │ 26.0 │ 27.3 │ 1.3~[{1.2,1.5]}
BibTeX
@misc{staniszewski2023structured,
  author = {Konrad Staniszewski and Szymon Tworkowski and Sebastian Jaszczur and Henryk Michalewski and Lukasz Kucinski and Piotr Milos},
  title = {{Structured Packing in LLM Training Improves Long Context Utilization}},
  year = {2023},
  eprint = {2312.17296},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.17296},
}
Figure