Z1: Efficient Test-time Scaling with Code

Zhaojian Yu, Yinghao Wu, Yilun Zhao, Arman Cohan, Xiao-Ping Zhang

TL;DR

This paper introduces Z1, a novel method for efficient test-time scaling in Large Language Models (LLMs) for reasoning tasks. By training on code-related reasoning trajectories and employing a "Shifted Thinking Window," Z1 significantly reduces the number of thinking tokens required for problem-solving while maintaining performance, offering a more efficient way to leverage LLMs for complex reasoning.

What Problem Does This Paper Address?

Large Language Models (LLMs) have shown impressive capabilities in complex reasoning tasks, often by scaling their test-time computation. However, this typically involves generating lengthy reasoning chains (chain-of-thought) which consume a large number of "thinking tokens." This leads to increased computational costs and can be inefficient, especially for simpler problems where extensive reasoning is unnecessary. Existing methods to mitigate this, like "budget forcing," can sometimes disrupt the reasoning process. The paper addresses the challenge of achieving efficient test-time scaling by reducing thinking token consumption without sacrificing performance, particularly in code-related reasoning tasks.

Methods

The core of Z1's approach lies in two key innovations:

  1. Z1-Code-Reasoning-107K Dataset: The authors created a new dataset comprising 107,000 simple and complex coding problems paired with their short and long reasoning trajectories. This dataset is crucial for training LLMs to adapt their reasoning depth.
  2. Shifted Thinking Window: Instead of using explicit delimiters (like <think>...</think>) to separate reasoning and answer phases, Z1 employs a "Shifted Thinking Window." This allows the model to:
  3. Generate concise reasoning and answers for simple problems.
  4. Cap the thinking tokens for complex problems and provide a hint if the limit is exceeded, guiding the model to produce an answer without excessive deliberation.

This method trains LLMs to perform "weak reasoning" on simple problems and "strong reasoning" on complex ones, thereby avoiding overthinking.

Datasets

  • Z1-Code-Reasoning-107K: A newly curated dataset of 107,000 simple and complex coding problems with short and long reasoning trajectories. This dataset was distilled from the QwQ-32B-Preview model.
  • Evaluation Benchmarks:
    • LiveCodeBench v5: A collection of programming tasks from competitive programming platforms.
  • GPQA Diamond: A dataset of PhD-level science questions.
  • MATH500: A benchmark of competition math problems.
  • BigCodeBench-Hard-Instruct: Used for evaluating LLMs on short trajectory thinking in code generation.

Key Insights and Ideas

  • Code-centric reasoning is generalizable: Fine-tuning LLMs exclusively on code-related reasoning trajectories allows them to generalize to broader reasoning tasks, suggesting that the underlying reasoning patterns are transferable.
  • Shifted Thinking Window is key to efficiency: By dynamically adjusting reasoning depth and avoiding rigid context splitting, the Shifted Thinking Window effectively reduces unnecessary thinking tokens, leading to significant efficiency gains.
  • Longer trajectories in training matter: The data ablation study suggests that training on longer reasoning trajectories enhances a model's capacity for test-time scaling, encouraging more deliberate reasoning.
  • Balancing reasoning depth: The core idea is to enable LLMs to perform "weak reasoning" for simple problems and "strong reasoning" for complex ones, a balance that significantly improves efficiency.

Key Results

  • Efficient Test-time Scaling: Z1-7B matches the performance of R1-Distill-Qwen-7B on various reasoning tasks but uses approximately 30% of its average thinking tokens.
  • Comparable Performance: Z1 models achieve comparable performance to GPT-40 on complex problems, demonstrating the effectiveness of test-time scaling with code.
  • Superiority in 7B models: Z1-7B outperforms other 7B-scale language reasoning models when trained with code-related trajectory data.
  • Generalization: Z1-7B shows strong generalization capabilities, achieving 47.5% on GPQA Diamond and 76.4% on MATH500, even when fine-tuned solely on code reasoning data.
  • Reduced Thinking Tokens: For example, on the GPQA Diamond benchmark, Z1-7B requires about half the average thinking time compared to R1-Distill-Qwen-7B, using approximately 2,000+ tokens versus over 4,096 tokens.

Limitations and Future Work

  • Dataset Scope: The current Z1-Code-Reasoning dataset primarily focuses on code-related topics. The authors suggest that future work could extend this approach by incorporating more diverse datasets covering science and mathematics to examine their impact on model performance.
  • Complex Scenarios: While Z1 can adjust reasoning length, the paper notes that in very complex scenarios, allocating a higher thinking token budget might still be necessary to ensure correctness, as seen in a failure case where Z1 was truncated.

Summary updated

BibTeX
@inproceedings{yu2025z,
  author = {Zhaojian Yu and Yinghao Wu and Yilun Zhao and Arman Cohan and Xiao-Ping Zhang},
  title = {{Z1: Efficient Test-time Scaling with Code}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2025},
}
Figure