Qwen2.5 Math 7 B Instruct

Qwen

Introduction

In August 2024, the Qwen2-Math series, the first in a line of mathematical large language models (LLMs), was launched. The Qwen2.5-Math series, released a month later, includes base models and instruction-tuned models such as Qwen2.5-Math-1.5B/7B/72B-Instruct, as well as a mathematical reward model, Qwen2.5-Math-RM-72B. These models are designed to solve math problems in both English and Chinese, employing Chain-of-Thought (CoT) and Tool-Integrated Reasoning (TIR) techniques. The Qwen2.5-Math series shows improved performance on mathematical benchmarks compared to its predecessor.

Architecture

The Qwen2.5-Math models leverage the CoT framework for enhanced reasoning capabilities, addressing tasks like solving equations and computing eigenvalues. They integrate TIR to improve computational accuracy and handle complex mathematical reasoning.

Training

The Qwen2.5-Math series models are instruction-tuned to support both CoT and TIR methods, achieving high scores on mathematics benchmarks. The models require transformers version 4.37.0 or later, as it includes necessary integrations for Qwen2.

Guide: Running Locally

To run Qwen2.5-Math-7B-Instruct locally, follow these steps:

  1. Install Transformers Library: Ensure your environment has transformers>=4.37.0.

  2. Load the Model:

    from transformers import AutoModelForCausalLM, AutoTokenizer
    
    model_name = "Qwen/Qwen2.5-Math-7B-Instruct"
    device = "cuda"  # Use a GPU for optimal performance
    
    model = AutoModelForCausalLM.from_pretrained(
        model_name,
        torch_dtype="auto",
        device_map="auto"
    )
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    
  3. Prepare Input: Use a prompt for the model to generate a response.

  4. Generate Output:

    prompt = "Find the value of $x$ that satisfies the equation $4x+5 = 6x+7$."
    messages = [
        {"role": "system", "content": "Please reason step by step, 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
    )
    response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
    

Suggested Cloud GPUs: Consider using cloud GPU services like AWS EC2, Google Cloud Platform, or Azure for efficient computation.

License

The Qwen2.5-Math-7B-Instruct model is released under the Apache 2.0 License. More information can be found in the license file here.

More Related APIs in Text Generation