[!Warning]
🚨 Qwen2.5-Math 主要通过 CoT 和 TIR 支持解决英文和中文数学问题。我们不建议将这个系列的模型用于其他任务。
2024年8月,我们发布了家族中的第一个数学LLMs系列 - Qwen2-Math。一个月后,我们对其进行了升级,并开源了 Qwen2.5-Math 系列,包括基础模型 Qwen2.5-Math-1.5B/7B/72B,指令调优模型 Qwen2.5-Math-1.5B/7B/72B-Instruct,以及数学奖励模型 Qwen2.5-Math-RM-72B。
与仅支持使用思维链(CoT)解决英文数学问题的 Qwen2-Math 系列不同,Qwen2.5-Math 系列已扩展为支持使用 CoT 和工具集成推理(TIR)解决中英文数学问题。与 Qwen2-Math 系列相比,Qwen2.5-Math 系列模型在中英文数学基准测试中使用 CoT 的性能有了显著提升。

虽然 CoT 在增强 LLMs 推理能力方面发挥着重要作用,但它在实现计算精度和处理复杂数学或算法推理任务方面面临挑战,例如求解二次方程的根或计算矩阵的特征值。TIR 可以进一步提高模型在精确计算、符号操作和算法操作方面的熟练程度。Qwen2.5-Math-1.5B/7B/72B-Instruct 在使用 TIR 的 MATH 基准测试中分别达到了 79.7、85.3 和 87.8。
更多详细信息,请参考我们的 博客文章 和 GitHub 仓库。
transformers>=4.37.0 适用于 Qwen2.5-Math 模型。推荐使用最新版本。[!Warning]
🚨 这是必须的,因为transformers从4.37.0版本开始集成了 Qwen2 代码。
关于 GPU 内存和相应吞吐量的要求,请参见 Qwen2 的类似结果 这里。
[!Important]
Qwen2.5-Math-1.5B-Instruct 是用于聊天的指令模型;
Qwen2.5-Math-1.5B 是一个基础模型,通常用于完成和少量样本推理,是微调的更好起点。
Qwen2.5-Math 可以像 Qwen2.5 一样进行部署和推理。下面是一个代码示例,展示了如何使用 transformers 中的聊天模型:
from transformers import pipeline
# Instantiate the chat pipeline
chat_pipeline = pipeline('text-generation', model='Qwen/Qwen2.5-Math-1.5B-Instruct')
# Ask a question to the model
question = "What is the integral of 2x?"
print(chat_pipeline(question))from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "Qwen/Qwen2.5-Math-1.5B-Instruct"
device = "cuda" # the device to load the model onto
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
prompt = "Find the value of $x$ that satisfies the equation $4x+5 = 6x+7$."
# CoT
messages = [
{"role": "system", "content": "Please reason step by step, and put your final answer within \\boxed{}."},
{"role": "user", "content": prompt}
]
# TIR
messages = [
{"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
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]如果您发现我们的工作对您有所帮助,欢迎引用我们的成果。
@article{yang2024qwen25mathtechnicalreportmathematical,
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}
}当然,请您提供需要翻译的英文文本以及期望的中文风格(通俗、专业、优雅或流畅),我将为您进行翻译。由于您没有提供具体的英文文本,我无法直接进行翻译。请提供文本,我将按照您的要求进行翻译。