CoolFace
Modelpublic

unsloth/Qwen2.5-Math-7B-Instruct

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
2likes148downloads
README.md144 linesDownload Raw Back to root
1---2base_model: Qwen/Qwen2.5-Math-7B-Instruct3language:4- en5library_name: transformers6license: apache-2.07tags:8- unsloth9- transformers10---11 12# Finetune Llama 3.1, Gemma 2, Mistral 2-5x faster with 70% less memory via Unsloth!13 14We have a Qwen 2.5 (all model sizes) [free Google Colab Tesla T4 notebook](https://colab.research.google.com/drive/1Kose-ucXO1IBaZq5BvbwWieuubP7hxvQ?usp=sharing).15Also a [Qwen 2.5 conversational style notebook](https://colab.research.google.com/drive/1qN1CEalC70EO1wGKhNxs1go1W9So61R5?usp=sharing).16 17[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/Discord%20button.png" width="200"/>](https://discord.gg/unsloth)18[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)19 20## ✨ Finetune for Free21 22All notebooks are **beginner friendly**! Add your dataset, click "Run All", and you'll get a 2x faster finetuned model which can be exported to GGUF, vLLM or uploaded to Hugging Face.23 24| Unsloth supports          |    Free Notebooks                                                                                           | Performance | Memory use |25|-----------------|--------------------------------------------------------------------------------------------------------------------------|-------------|----------|26| **Llama-3.1 8b**      | [▶️ Start on Colab](https://colab.research.google.com/drive/1Ys44kVvmeZtnICzWz0xgpRnrIOjZAuxp?usp=sharing)               | 2.4x faster | 58% less |27| **Phi-3.5 (mini)** | [▶️ Start on Colab](https://colab.research.google.com/drive/1lN6hPQveB_mHSnTOYifygFcrO8C1bxq4?usp=sharing)               | 2x faster | 50% less |28| **Gemma-2 9b**      | [▶️ Start on Colab](https://colab.research.google.com/drive/1vIrqH5uYDQwsJ4-OO3DErvuv4pBgVwk4?usp=sharing)               | 2.4x faster | 58% less |29| **Mistral 7b**    | [▶️ Start on Colab](https://colab.research.google.com/drive/1Dyauq4kTZoLewQ1cApceUQVNcnnNTzg_?usp=sharing)               | 2.2x faster | 62% less |30| **TinyLlama**  | [▶️ Start on Colab](https://colab.research.google.com/drive/1AZghoNBQaMDgWJpi4RbffGM1h6raLUj9?usp=sharing)              | 3.9x faster | 74% less |31| **DPO - Zephyr**     | [▶️ Start on Colab](https://colab.research.google.com/drive/15vttTpzzVXv_tJwEk-hIcQ0S9FcEWvwP?usp=sharing)               | 1.9x faster | 19% less |32 33- This [conversational notebook](https://colab.research.google.com/drive/1Aau3lgPzeZKQ-98h69CCu1UJcvIBLmy2?usp=sharing) is useful for ShareGPT ChatML / Vicuna templates.34- This [text completion notebook](https://colab.research.google.com/drive/1ef-tab5bhkvWmBOObepl1WgJvfvSzn5Q?usp=sharing) is for raw text. This [DPO notebook](https://colab.research.google.com/drive/15vttTpzzVXv_tJwEk-hIcQ0S9FcEWvwP?usp=sharing) replicates Zephyr.35- \* Kaggle has 2x T4s, but we use 1. Due to overhead, 1x T4 is 5x faster.36 37 38# Qwen2.5-Math-7B-Instruct39 40> [!Warning]41> <div align="center">42> <b>43> 🚨 Qwen2.5-Math mainly supports solving English and Chinese math problems through CoT and TIR. We do not recommend using this series of models for other tasks.44> </b>45> </div>46 47## Introduction48 49In August 2024, we released the first series of mathematical LLMs - [Qwen2-Math](https://qwenlm.github.io/blog/qwen2-math/) - of our Qwen family. A month later, we have upgraded it and open-sourced **Qwen2.5-Math** series, including base models **Qwen2.5-Math-1.5B/7B/72B**, instruction-tuned models **Qwen2.5-Math-1.5B/7B/72B-Instruct**, and mathematical reward model **Qwen2.5-Math-RM-72B**. 50                                                                              51Unlike Qwen2-Math series which only supports using Chain-of-Thught (CoT) to solve English math problems, Qwen2.5-Math series is expanded to support using both CoT and Tool-integrated Reasoning (TIR) to solve math problems in both Chinese and English. The Qwen2.5-Math series models have achieved significant performance improvements compared to the Qwen2-Math series models on the Chinese and English mathematics benchmarks with CoT. 52 53![](http://qianwen-res.oss-accelerate-overseas.aliyuncs.com/Qwen2.5/qwen2.5-math-pipeline.jpeg)54 55While CoT plays a vital role in enhancing the reasoning capabilities of LLMs, it faces challenges in achieving computational accuracy and handling complex mathematical or algorithmic reasoning tasks, such as finding the roots of a quadratic equation or computing the eigenvalues of a matrix. TIR can further improve the model's proficiency in precise computation, symbolic manipulation, and algorithmic manipulation. Qwen2.5-Math-1.5B/7B/72B-Instruct achieve 79.7, 85.3, and 87.8 respectively on the MATH benchmark using TIR. 56 57## Model Details58 59 60For more details, please refer to our [blog post](https://qwenlm.github.io/blog/qwen2.5-math/) and [GitHub repo](https://github.com/QwenLM/Qwen2.5-Math).61 62 63## Requirements64* `transformers>=4.37.0` for Qwen2.5-Math models. The latest version is recommended.65 66> [!Warning]67> <div align="center">68> <b>69> 🚨 This is a must because <code>transformers</code> integrated Qwen2 codes since <code>4.37.0</code>.70> </b>71> </div>72 73For requirements on GPU memory and the respective throughput, see similar results of Qwen2 [here](https://qwen.readthedocs.io/en/latest/benchmark/speed_benchmark.html).74 75## Quick Start76 77> [!Important]78>79> **Qwen2.5-Math-7B-Instruct** is an instruction model for chatting;80>81> **Qwen2.5-Math-7B** is a base model typically used for completion and few-shot inference, serving as a better starting point for fine-tuning.82> 83 84### 🤗 Hugging Face Transformers85 86Qwen2.5-Math can be deployed and infered in the same way as [Qwen2.5](https://github.com/QwenLM/Qwen2.5). Here we show a code snippet to show you how to use the chat model with `transformers`:87 88```python89from transformers import AutoModelForCausalLM, AutoTokenizer90 91model_name = "Qwen/Qwen2.5-Math-7B-Instruct"92device = "cuda" # the device to load the model onto93 94model = AutoModelForCausalLM.from_pretrained(95    model_name,96    torch_dtype="auto",97    device_map="auto"98)99tokenizer = AutoTokenizer.from_pretrained(model_name)100 101prompt = "Find the value of $x$ that satisfies the equation $4x+5 = 6x+7$."102 103# CoT104messages = [105    {"role": "system", "content": "Please reason step by step, and put your final answer within \\boxed{}."},106    {"role": "user", "content": prompt}107]108 109# TIR110messages = [111    {"role": "system", "content": "Please integrate natural language reasoning with programs to solve the problem above, and put your final answer within \\boxed{}."},112    {"role": "user", "content": prompt}113]114 115text = tokenizer.apply_chat_template(116    messages,117    tokenize=False,118    add_generation_prompt=True119)120model_inputs = tokenizer([text], return_tensors="pt").to(device)121 122generated_ids = model.generate(123    **model_inputs,124    max_new_tokens=512125)126generated_ids = [127    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)128]129 130response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]131```132 133## Citation134 135If you find our work helpful, feel free to give us a citation.136 137```138@article{yang2024qwen25mathtechnicalreportmathematical,139  title={Qwen2.5-Math Technical Report: Toward Mathematical Expert Model via Self-Improvement}, 140  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},141  journal={arXiv preprint arXiv:2409.12122},142  year={2024}143}144```