Introducing Qwen2.5-Math Advancing the Frontier of Mathematical Language Models

Image for the article 'Qwen_Qwen2.5-Math-7B-Instruct_output' showing key insights of the topic.

Introduction

As we navigate an age where artificial intelligence is transforming our approach to intricate challenges, the launch of Qwen2.5-Math stands out as a pivotal development in the field of mathematical language models (LLMs). Released in September 2024, this enhanced series builds on the groundwork established by the Qwen2-Math models, which emerged just a month prior. The Qwen2.5-Math series comprises the foundational model Qwen2.5-Math-1.5B7B72B, the instruction-tuned variant Qwen2.5-Math-1.5B7B72B-Instruct, and the specialized mathematical reward model Qwen2.5-Math-RM-72B.

What distinguishes this series from its predecessors? Unlike the earlier model that primarily addressed English math problems using Chain-of-Thought (CoT) reasoning, Qwen2.5-Math introduces the innovative Tool-integrated Reasoning (TIR) technique, enabling it to effectively handle both English and Chinese math problems. This dual-language capability not only broadens the model's applicability but also significantly enhances its performance across a variety of mathematical benchmarks.

![Qwen2.5-Math Pipeline](http://qianwen-res.oss-accelerate-overseas.aliyuncs.com/Qwen2.5/qwen2.5-math-pipeline.jpeg)

The Synergy of CoT and TIR

While CoT reasoning has notably advanced the reasoning abilities of LLMs, it is essential to recognize its limitations, particularly regarding computational precision and more complex mathematical tasks. For example, challenges like determining the roots of a quadratic equation or calculating eigenvalues can be quite daunting. This is where TIR comes into play, providing a mechanism to enhance the model’s proficiency in accurate computation, symbolic manipulation, and algorithmic reasoning.

The outcomes are telling: the Qwen2.5-Math-1.5B7B72B-Instruct model achieved remarkable scores of 79.7, 85.3, and 87.8 on the MATH benchmark utilizing TIR. These impressive figures not only underscore the model's capabilities but also hint at its potential to revolutionize our approach to mathematical problem-solving through AI.

Getting Started with Qwen2.5-Math

If you’re excited to explore the capabilities of Qwen2.5-Math, here’s a concise guide to help you get started. First, ensure that your environment is properly configured:

Requirements

- Transformers: You’ll need version 4.37.0 or higher, as this version incorporates the Qwen2 codes.

For specifics on GPU memory and throughput requirements, please refer to the benchmarks available [here](https://qwen.readthedocs.io/en/latest/benchmark/speed_benchmark.html).

Quick Start Guide

To leverage the Qwen2.5-Math models, you can follow this straightforward code snippet, which illustrates how to utilize the chat model with Hugging Face Transformers:

from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "Qwen/Qwen2.5-Math-7B-Instruct"
device = "cuda"  # Specify the device for model loading

# Load the model
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",
    device_map="auto"
)

tokenizer = AutoTokenizer.from_pretrained(model_name)

# Define your prompt
prompt = "Find the value of $x$ that satisfies the equation $4x + 5 = 6x + 7$."

# Chain-of-Thought (CoT) messages
messages = [
    {"role": "system", "content": "Please reason step by step, and put your final answer within boxed."},
    {"role": "user", "content": prompt}
]

# Tool-integrated Reasoning (TIR) messages
messages_TIR = [
    {"role": "system", "content": "Please integrate natural language reasoning with programs to solve the problem above, and put your final answer within boxed."},
    {"role": "user", "content": prompt}
]

text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)

model_inputs = tokenizer([text], return_tensors="pt").to(device)
generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=512
)

# Decode the response
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]

This code snippet serves as a solid foundation for both completion tasks and few-shot inference, making it an excellent starting point for refining your applications.

Conclusion

Looking ahead, the Qwen2.5-Math series not only signifies a major technological leap but also opens new pathways for exploring the intersection of language and mathematics. Whether you are a researcher, developer, or simply curious about the potential of AI in solving mathematical problems, Qwen2.5-Math is poised to be an invaluable resource in your toolkit.

If you find this work beneficial, please consider citing it:

@article{yang2024qwen25math,
  title={Qwen2.5-Math Technical Report: Toward Mathematical Expert Model via Self-Improvement},
  author={An Yang and Beichen Zhang and Binyuan Hui and Bofei Gao and Bowen Yu and Chengpeng Li and Dayiheng Liu and Jianhong Tu and Jingren Zhou and Junyang Lin and Keming Lu and Mingfeng Xue and Runji Lin and Tianyu Liu and Xingzhang Ren and Zhenru Zhang},
  journal={arXiv preprint arXiv:2409.12122},
  year={2024}
}

With Qwen2.5-Math, the future of mathematical problem-solving through AI appears more promising than ever. Are you ready to delve into its capabilities?