LongSkywork: A Training Recipe for Efficiently Extending Context Length in Large Language Models

Liang Zhao, Tianwen Wei, Liang Zeng, Cheng Cheng, Liu Yang, Lijie Wang, Chenxia Li, Xuejie Wu, Bo Zhu, Yimeng Gan, Rui Hu, Shuicheng Yan, Han Fang, Yahui ZhouarXiv 2024 · DOI

Introduction

Large Language Models (LLMs) have demonstrated remarkable capabilities, yet most remain constrained by relatively short context windows, typically ranging from 2,000 to 4,000 tokens. This "nearsightedness" limits their utility for processing extensive documents, complex codebases, or long-form conversations. Extending this window is challenging due to the scarcity of high-quality long-form supervised fine-tuning (SFT) data and the high computational cost of training on long sequences, which often degrades performance on shorter tasks.

LongSkywork introduces an efficient training "recipe" to extend the context window of LLMs to 200,000 tokens. By leveraging specialized long-context stages and novel synthetic data generation, the researchers transformed a 13B parameter model into a long-context specialist that rivals proprietary giants like Claude 2.1 and GPT-4.

Methodology: Chunking and Synthesis

The core of the LongSkywork approach lies in two innovative techniques designed to improve how models learn to attend to distant information.

Chunk Interleaved Pretraining (CIP)

Standard methods for extending context often involve concatenating multiple short documents to fill a long training window. However, this allows the model to "cheat" by focusing only on local dependencies within each short document. LongSkywork introduces Chunk Interleaved Pretraining (CIP), where documents are split into chunks of varying lengths and interleaved. This forces the model to track information across long distances to maintain coherence, effectively compelling the attention mechanism to utilize the entire context range.

Synthetic Lengthy Tables (SynL)

To overcome the lack of annotated long-context data, the authors developed Synthetic Lengthy Tables (SynL). Programs are used to generate massive tables (up to 100K tokens), followed by the generation of specific tasks:

  • Information Retrieval: Selecting specific entries based on criteria (e.g., "Select the youngest people in this table").
  • Chain-of-Thought (CoT) Reasoning: Performing calculations based on table data (e.g., calculating age differences).
  • Global Comprehension: Sorting the entire table by a specific column.
The LongSkywork training pipeline and data generation methods, highlighting Chunk Interleaved Pretraining (CIP) and Synthetic Lengthy Tables (SynL).

The Four-Stage Training Pipeline

The LongSkywork recipe follows a structured four-stage process:

  1. Regular Pretraining: The initial phase of standard LLM training.
  2. Long-context Pretraining: Adapting the model to extended positional embeddings. The RoPE (Rotary Positional Embedding) base frequency is adjusted from 10,000 to 2,600,000 using the CIP technique.
  3. Regular SFT: Standard instruction tuning to align with human preferences.
  4. Long-context SFT: A final refinement stage using the SynL data to enhance long-range information processing.

Experimental Results

The effectiveness of the LongSkywork recipe was evaluated using several benchmarks, including the industry-standard "Needle-in-a-Haystack" test, InfiniteBench, and a new real-world benchmark called Tiangong AI Reading.

Needle-in-a-Haystack Performance

In the "Needle-in-a-Haystack" test, which requires retrieving a specific piece of information buried within a large context, LongSkywork-13B achieved perfect accuracy across context spans. While the recipe targets 200K, evaluations on 100K windows show flawless retrieval performance.

Pressure testing the LongSkywork context window using the "Needle-in-a-Haystack" test, showing perfect retrieval scores (10/10) across various depths and context lengths up to 100K tokens.

Benchmark Comparisons

  • InfiniteBench: LongSkywork-13B achieved an average score of 47.5%, outperforming Moonshot (39.4%) and Claude 2.1 (44.5%) on retrieval-heavy tasks.
  • Tiangong AI Reading: On this real-world benchmark featuring 856 user-centric questions, LongSkywork-13B scored 69.24, rivaling the performance of the much larger Claude 2.1 (72.27).
  • Synthetic Data Impact: The inclusion of SynL data was transformative, raising the model's average retrieval score from 49.3% to 94.0% on specific long-context benchmarks.

Key Insights

The researchers found that the Long-context SFT stage is the most critical component of the pipeline. Remarkably, as few as 200 iterations of long-context SFT can successfully transition a standard model into a long-context specialist. Furthermore, the results suggest that controlled synthetic data can be superior to human-curated data for long-context training because it can be precisely tailored for length and complexity.

Limitations and Future Work

While LongSkywork represents a significant step forward, several challenges remain:

  1. Hallucination: The model occasionally struggles with non-answerable questions, sometimes hallucinating an answer instead of stating that the information is missing.
  2. Complex Reasoning: While retrieval is excellent, multi-step reasoning over long contexts remains difficult.
  3. Summarization: A slight dip in summarization performance was observed, likely due to the retrieval-centric nature of the synthetic table data. Future iterations will incorporate summary-focused synthetic data to address this.

In conclusion, LongSkywork provides a highly efficient and scalable recipe for extending LLM context windows, demonstrating that strategic data synthesis and interleaved training can rival the performance of much larger, proprietary systems.

Summary updated

BibTeX
@misc{zhao2024longskywork,
  author = {Liang Zhao and Tianwen Wei and Liang Zeng and Cheng Cheng and Liu Yang and Peng Cheng and Lijie Wang and Chenxia Li and Xuejie Wu and Bo Zhu and Yimeng Gan and Rui Hu and Shuicheng Yan and Han Fang and Yahui Zhou},
  title = {{LongSkywork: A Training Recipe for Efficiently Extending Context Length in Large Language Models}},
  year = {2024},
  eprint = {2406.00605},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.00605},
}
Figure