NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

From 128K to 4M: Efficient Training of Ultra-Long Context Large Language Models

Chejian Xu, Wei Ping, Peng Xu, Zihan Liu, Boxin Wang, Mohammad Shoeybi, Bo Li, Bryan CatanzaroarXiv 2025 · DOI

Introduction

The demand for Large Language Models (LLMs) capable of processing massive datasets—from entire libraries to hour-long videos—is growing rapidly. However, extending the context window of these models has historically been fraught with challenges, including performance trade-offs on short-context tasks and inefficient training recipes. Researchers from NVIDIA and UIUC have introduced UltraLong-8B, a model that pushes the boundaries of context length from the standard 128K to a staggering 4 million tokens. Crucially, this extension does not come at the cost of the model's general reasoning abilities; in fact, UltraLong-8B demonstrates improved performance on standard short-context benchmarks.

The UltraLong Training Pipeline

The core of this breakthrough is a streamlined two-stage training process designed for efficiency and performance retention. Unlike previous methods that required incremental growth (e.g., 128K to 512K to 1M), the authors found that jumping directly to the target context length is more effective.

The two-stage training pipeline for UltraLong-8B, involving continued pretraining on long documents followed by high-quality short-context instruction tuning.

Stage 1: Continued Pretraining (The "Stretch")

The first stage involves training the base model (starting from Llama-3.1-8B-Instruct) on 1 billion tokens of data. The key innovation here is the upsampling of documents longer than 8K tokens. To handle the massive increase in context, the team utilized YaRN-based RoPE Scaling (Yet another RoPE extensioN), which offers superior stability for ultra-long sequences compared to standard NTK-aware scaling. Furthermore, they implemented specific document separators to help the model distinguish between distinct texts within a single 4M-token stream, while maintaining full attention across the entire sequence.

Stage 2: Instruction Tuning (The "Refinement")

Perhaps the most surprising finding is that the second stage—Supervised Fine-Tuning (SFT)—uses only short-context data (under 8K tokens). By fine-tuning on 100K high-quality examples across general, math, and coding domains (refined by GPT-4o), the researchers successfully prevented the "catastrophic forgetting" often seen when models are stretched for long context. This stage ensures the model remains "smart" and capable of complex reasoning, acting as a powerful regularizer for the knowledge gained in Stage 1.

Evaluation and Benchmarking

To rigorously test UltraLong-8B, the researchers employed a battery of benchmarks designed to push the limits of long-form retrieval and reasoning:

  • Needle in a Haystack: A standard retrieval test measuring the ability to find a specific fact hidden in a large context.
  • RULER & LV-Eval: Complex synthetic and real-world long-context benchmarks that go beyond simple retrieval.
  • InfiniteBench: Testing sequences exceeding 2 million tokens.
  • Standard Benchmarks: MMLU, MATH, GSM-8K, and HumanEval were used to monitor general intelligence and ensure no degradation in short-context performance.

Key Results and Insights

UltraLong-8B sets a new standard for long-context LLMs. It achieved a perfect 100% accuracy on the "Needle in a Haystack" test across all depths up to 4 million tokens, significantly outperforming existing models like ProLong and the base Llama 3.1.

Comparative "Needle In A Haystack" pressure testing results across various models, showing UltraLong-8B's superior performance up to 4M tokens.

One of the most significant findings is the lack of an "intelligence tax." While many long-context models suffer a 20-30% drop in general reasoning scores, UltraLong-8B actually improved its performance. Compared to the base Llama 3.1 model, its MMLU score increased from 64.83 to 66.99, and its MATH score rose from 47.22 to 55.10. This suggests that high-quality, short-form reasoning data is sufficient to maintain (and even boost) a model's cognitive capabilities even after its context window has been massively expanded.

Conclusion and Future Directions

The UltraLong-8B recipe demonstrates that massive context windows can be achieved efficiently without sacrificing general-purpose capabilities. While the training recipe is streamlined, challenges remain regarding the computational cost of inference at 4M tokens due to the quadratic nature of exact attention. Future work will likely explore integrating more efficient attention mechanisms, preference optimization (RLHF/DPO), and specialized safety alignment for ultra-long contexts to mitigate risks like hidden harmful instructions in massive prompts.

Summary updated

BibTeX
@misc{xu2025from,
  author = {Chejian Xu and Wei Ping and Peng Xu and Zihan Liu and Boxin Wang and Mohammad Shoeybi and Bo Li and Bryan Catanzaro},
  title = {{From 128K to 4M: Efficient Training of Ultra-Long Context Large Language Models}},
  year = {2025},
  eprint = {2504.06214},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.06214},
}
Figure