Qwen2.5-1M Technical Report

An Yang, Bowen Yu, Chengyuan Li, Dayiheng Liu, Fei Huang, Haoyan Huang, Jiandong Jiang, Jianhong Tu, Jianwei Zhang, Jingren Zhou, Junyang Lin, Kai Dang, Kexin Yang, Le Yu, Mei Li, Minmin Sun, Qin Zhu, Rui Men, Tao He, Weijia Xu, Wenbiao Yin, Wenyuan Yu, Xiafei Qiu, Xingzhang Ren, Xinlong Yang, Yong Li, Zhiying Xu, Zipeng ZhangarXiv 2025 · DOI

TL;DR

This paper introduces Qwen2.5-1M, a family of large language models capable of processing up to 1 million tokens in context. They achieve this through novel long-context pre-training and post-training techniques, coupled with an open-source, highly optimized inference framework that significantly boosts speed and reduces costs for long-context applications.

What Problem Does This Paper Address?

Large Language Models (LLMs) have revolutionized NLP, but their utility is often limited by a constrained context window. This restriction prevents them from effectively processing lengthy documents, codebases, or complex conversational histories, hindering applications in areas like in-depth research, code generation from large projects, and comprehensive document analysis. While recent models have pushed context lengths to 128K tokens, the goal of processing truly massive amounts of text, such as 1 million tokens, remains a significant challenge, requiring advancements in both model training and efficient inference.

Methods

The Qwen2.5-1M series tackles the long-context challenge with a multi-pronged approach:

  • Long-Context Pre-training:
    • Natural and Synthetic Data: A diverse corpus of natural text is augmented with synthetically generated data designed to specifically improve long-range dependency understanding. This includes tasks like "Fill in the Middle," "Keyword-Based and Position-Based Retrieval," and "Paragraph Reordering."
    • Progressive Context Length Expansion: Training progresses through five stages, gradually increasing the context length from 4096 to 262,144 tokens. This is coupled with Adaptive Base Frequency (ABF) for Rotary Position Embeddings (RoPE) to handle the extended lengths.
  • Post-Training:
    • Synthesized Long Instruction Data: To overcome the scarcity of human-annotated long-context instruction data, they use an agent-based framework to generate high-quality question-answer pairs from long documents.
  • Two-Stage Supervised Fine-Tuning (SFT): Models are first fine-tuned on short instructions to retain proficiency, then on a mixed dataset of short and long sequences to balance performance.
  • Reinforcement Learning (RL): Offline RL, similar to Direct Preference Optimization (DPO), is used to align models with human preferences, demonstrating effective generalization from short to long contexts.
  • Inference and Deployment Framework:
    • Length Extrapolation: A training-free method (Dual Chunk Attention - DCA) allows models trained on shorter contexts (e.g., 256K) to handle much longer ones (e.g., 1M) by remapping relative positional distances. Attention Scaling in YaRN is also employed.
  • Sparse Attention: MInference, a sparse attention mechanism, identifies and utilizes only critical tokens, reducing computational complexity by approximately 10x with minimal accuracy loss.
  • Chunked Prefill: This technique reduces VRAM consumption during inference by processing sequences in chunks.
  • Inference Engine Optimizations: BladeLLM, a high-performance engine, incorporates kernel optimization, dynamic chunked pipeline parallelism, and asynchronous scheduling to further boost speed and efficiency.

Datasets

  • Training Data:
    • Common Crawl, arXiv, books, code repositories.
  • Synthetically generated data for long-range dependency tasks (FIM, retrieval, reordering).
  • Agent-generated long-context question-answer pairs.
  • Evaluation Benchmarks:
    • Long-Context: Passkey Retrieval (up to 1M tokens), RULER, LV-Eval, Longbench-Chat.
  • Short-Context: MMLU-Pro, MMLU-redux, LiveBench 0831, GPQA, GSM8K, MATH, HumanEval, MBPP, MultiPL-E, LiveCodeBench, IFEval, Arena-Hard, MT-Bench.

Key Insights and Ideas

  • Synthetic data is crucial for long-context understanding: Natural text often lacks explicit long-range dependencies, making synthetic tasks essential for training models to connect distant information.
  • Progressive training is key to efficiency: Gradually increasing context length during pre-training is more cost-effective and efficient than training directly on very long sequences.
  • Length extrapolation without retraining is powerful: Techniques like DCA allow existing models to handle significantly longer contexts without expensive retraining, democratizing long-context capabilities.
  • Sparse attention is not just about speed, but also accuracy: By carefully selecting critical tokens and refining sparsity configurations, accuracy can be maintained or even improved on long-context tasks.
  • Inference engine optimization is as important as model architecture: Significant speedups and cost reductions are achieved through low-level optimizations in the inference pipeline.

Key Results

  • 1 Million Token Context: Qwen2.5-1M models successfully process and retrieve information from documents up to 1 million tokens.
  • Passkey Retrieval: Qwen2.5-14B-Instruct-1M and Qwen2.5-Turbo achieve perfect accuracy on Passkey Retrieval up to 1M tokens. Qwen2.5-7B-Instruct-1M shows only minor errors.
  • RULER Benchmark: Qwen2.5-1M models outperform GPT-4 on long-context retrieval tasks.
  • Inference Speedup: The optimized inference framework achieves a 3x to 7x prefill speedup for 1M-token contexts compared to baseline methods. Specifically, MInference with DCA and sparse refinement shows significant improvements.
  • Short-Context Performance: Qwen2.5-1M models maintain performance comparable to their 128K counterparts on short-context tasks, demonstrating no compromise in fundamental capabilities.
  • GPT-4o-mini Comparison: Qwen2.5-14B-Instruct-1M outperforms GPT-4o-mini on long-context tasks and supports contexts eight times longer.

Limitations and Future Work

  • Limitations:
    • While the 7B model shows strong performance, it exhibits minor errors in the Passkey Retrieval task at 1M tokens, indicating room for improvement in smaller models.
  • The paper notes that DCA might disrupt the "slash" pattern in sparse attention, leading to a performance drop in certain extrapolation cases, which they address with a refinement method.
  • Future Work:
    • The authors express confidence that long-context models still have significant potential for improvement.
  • They aim to develop models that excel in both short and long-context tasks, deliver substantial value in real-world scenarios, and explore more efficient training strategies, model architectures, and inference methods for resource-constrained environments.
  • They are committed to open-sourcing optimizations to drive progress in the field.

Summary updated

BibTeX
@misc{yang2025qwen,
  author = {An Yang and Bowen Yu and Chengyuan Li and Dayiheng Liu and Fei Huang and Haoyan Huang and Jiandong Jiang and Jianhong Tu and Jianwei Zhang and Jingren Zhou and Junyang Lin and Kai Dang and Kexin Yang and Le Yu and Mei Li and Minmin Sun and Qin Zhu and Rui Men and Tao He and Weijia Xu and Wenbiao Yin and Wenyuan Yu and Xiafei Qiu and Xingzhang Ren and Xinlong Yang and Yong Li and Zhiying Xu and Zipeng Zhang},
  title = {{Qwen2.5-1M Technical Report}},
  year = {2025},
  eprint = {2501.15383},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.15383},
}
Figure