Skip to main content
QUICK REVIEW

[Paper Review] Data Engineering for Scaling Language Models to 128K Context

Yao Fu, Rameswar Panda|arXiv (Cornell University)|Feb 15, 2024
Network Packet Processing and OptimizationComputer Science4 citations
TL;DR

This paper proposes a data engineering recipe for scaling LLaMA-2 language models to 128K context length via continual pretraining on 1–5 billion tokens of per-source length-upsampled data. It demonstrates that careful data mixture design—balancing domain ratios while upweighting long sequences within each domain—enables strong performance on the Needle-in-a-Haystack retrieval task, closing the gap to GPT-4 128K while maintaining short-context performance.

ABSTRACT

We study the continual pretraining recipe for scaling language models' context lengths to 128K, with a focus on data engineering. We hypothesize that long context modeling, in particular extit{the ability to utilize information at arbitrary input locations}, is a capability that is mostly already acquired through large-scale pretraining, and that this capability can be readily extended to contexts substantially longer than seen during training~(e.g., 4K to 128K) through lightweight continual pretraining on appropriate data mixture. We investigate the extit{quantity} and extit{quality} of the data for continual pretraining: (1) for quantity, we show that 500 million to 5 billion tokens are enough to enable the model to retrieve information anywhere within the 128K context; (2) for quality, our results equally emphasize extit{domain balance} and extit{length upsampling}. Concretely, we find that naively upsampling longer data on certain domains like books, a common practice of existing work, gives suboptimal performance, and that a balanced domain mixture is important. We demonstrate that continual pretraining of the full model on 1B-5B tokens of such data is an effective and affordable strategy for scaling the context length of language models to 128K. Our recipe outperforms strong open-source long-context models and closes the gap to frontier models like GPT-4 128K.

Motivation & Objective

  • To investigate how data engineering can effectively scale language models to 128K context length without architectural changes.
  • To address the challenge of enabling precise information retrieval at arbitrary positions within long contexts, especially beyond the model's original pretraining length.
  • To determine whether minimal continual pretraining on curated data can unlock long-context capabilities already partially acquired during large-scale pretraining.
  • To evaluate the trade-offs between data quantity, domain balance, and sequence length distribution in long-context adaptation.
  • To provide a practical, affordable, and effective recipe for extending open-source models to 128K context, enabling future instruction tuning.

Proposed method

  • Continual pretraining of LLaMA-2 7B and 13B models on 1–5 billion tokens of curated data, using full-attention mechanism with 64K–80K context windows.
  • Application of RoPE position embedding base adjustment to support longer context lengths without architectural changes.
  • Design of a per-source length-upsampling strategy that preserves the original domain mixture ratio while increasing the proportion of long sequences within each domain.
  • Use of FlashAttention to reduce memory usage and make long-context training feasible on academic-grade hardware.
  • Evaluation using the Needle-in-a-Haystack benchmark to measure precise retrieval performance across context lengths from 4K to 128K.
  • Comparison with strong baselines like YaRN-Mistral 128K and LongLoRA 100K to isolate the impact of data mixture design.
Figure 1: Needle-in-a-Haystack test (Kamradt, 2023 ) performance comparison. The x-axis denotes the length of the document (the “haystack”); the y-axis indicates the position that the “needle” (a short sentence) is located within the document, from 1K to 128K tokens. For example, 50% indicates that
Figure 1: Needle-in-a-Haystack test (Kamradt, 2023 ) performance comparison. The x-axis denotes the length of the document (the “haystack”); the y-axis indicates the position that the “needle” (a short sentence) is located within the document, from 1K to 128K tokens. For example, 50% indicates that

Experimental results

Research questions

  • RQ1Can a small amount of continual pretraining on carefully curated data unlock 128K context capabilities in a model pre-trained on only 4K context?
  • RQ2Does naive upsampling of long sequences in high-length domains (e.g., books) degrade performance on other domains like code or web content?
  • RQ3Is maintaining the original domain mixture ratio while upscaling long sequences within each domain more effective than domain-based upsampling?
  • RQ4How does the data mixture design affect the trade-off between long-context and short-context performance?
  • RQ5Can a data-centric approach outperform large-scale pretraining recipes in terms of efficiency and performance for long-context modeling?

Key findings

  • Continual pretraining on just 1–5 billion tokens of per-source length-upsampled data enables LLaMA-2 7B and 13B models to achieve strong performance on the Needle-in-a-Haystack test up to 128K context length.
  • The per-source length-upsampling strategy—preserving domain ratios while upscaling long sequences within each domain—results in the most balanced performance gain across domains, outperforming naive domain-based upsampling.
  • Naïve domain-based upsampling, such as over-representing books, leads to significant performance degradation in other domains like code and web content, indicating suboptimal data mixture design.
  • Models trained with the proposed recipe achieve performance comparable to GPT-4 128K on long-context retrieval, significantly outperforming strong open-source models like YaRN-Mistral 128K and LongLoRA 100K.
  • The validation loss alone is insufficient to detect performance differences; the Needle-in-a-Haystack test reveals critical disparities in long-context retrieval ability that test loss fails to capture.
  • The study demonstrates that data engineering is as crucial as model architecture or algorithmic innovation for achieving state-of-the-art long-context performance.
Figure 2: Length and domain distributions of the various data mixture strategies. We use SlimPajama (Soboleva et al., 2023 ) , an open-source reproduction of LLaMA (Touvron et al., 2023a ) pretraining data mixture, as the source dataset. The original data mixture has about 30% of documents that are
Figure 2: Length and domain distributions of the various data mixture strategies. We use SlimPajama (Soboleva et al., 2023 ) , an open-source reproduction of LLaMA (Touvron et al., 2023a ) pretraining data mixture, as the source dataset. The original data mixture has about 30% of documents that are

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.