Uploaded finetuned model

  • Developed by: aliRafik
  • License: apache-2.0
  • Finetuned from model : unsloth/qwen3-4b-thinking-2507-unsloth-bnb-4bit

This qwen3 model was trained 2x faster with Unsloth and Huggingface's TRL library.

🧠 Qwen3-4B Mathematical Reasoning Model

A mathematics-focused fine-tuned version of Qwen3-4B, designed to improve mathematical reasoning, structured problem solving, and clear step-by-step explanations.

The model is tuned on large-scale mathematical reasoning data with an emphasis on producing answers that are not only correct, but also logically structured, verifiable, and appropriately explained.


🧠 Key Highlights

  • Base Architecture: Qwen3-4B
  • Base Capability: Thinking / reasoning model
  • Dataset I: unsloth/OpenMathReasoning
  • Dataset II: Modotte/MathX-5M
  • Training Focus: Mathematical reasoning and step-by-step problem solving
  • Precision: 16-bit floating point
  • Inference: Hugging Face Transformers
  • Primary Goal: Improve mathematical accuracy, reasoning quality, and explanation quality

🎯 Model Objective

This model is designed to solve mathematical problems while maintaining a balance between:

Accuracy → Reasoning → Verification → Clarity → Appropriate Length

The goal is not simply to generate longer solutions.

A good mathematical response should use enough reasoning to establish correctness while avoiding unnecessary complexity for simple problems.


📊 Example: Comparing Prompt Styles

A simple algebra problem can demonstrate the model's reasoning behavior.

Problem

(x + 2)^2 = 0

The correct solution is:

[ \boxed{x=-2} ]

Two different prompting styles can produce noticeably different response behaviors.


🔹 Answer 1 — Concise and Appropriate Reasoning

Prompt

think hard and then Solve this pls  (x + 2)^2 = 0.

The model recognizes that a squared expression can equal zero only when the expression itself is zero:

[ x+2=0 ]

Therefore:

[ x=-2 ]

The response also correctly identifies that (-2) is a repeated root / double root and verifies the result by substitution.

Why this response is strong

For such a simple equation, the response provides the essential reasoning without introducing unnecessary solution methods.

It demonstrates:

  • Correct mathematical reasoning
  • Direct solution
  • Appropriate explanation length
  • Recognition of a repeated root
  • Simple verification

The key strength is proportional reasoning: the amount of explanation is appropriate for the difficulty of the problem.


🔹 Answer 2 — More Exhaustive Reasoning

Prompt

Solve (x + 2)^2 = 0.

The model also correctly obtains:

[ x=-2 ]

However, the response goes beyond the direct solution and additionally discusses:

  1. The repeated-root interpretation
  2. Expansion into

[ x^2+4x+4=0 ]

  1. Factoring
  2. The quadratic formula
  3. The discriminant

The discriminant is calculated as:

[ \Delta=b^2-4ac ]

[ \Delta=4^2-4(1)(4)=0 ]

which confirms the same result:

[ x=-2 ]

Why this response is useful

This response demonstrates multiple mathematical perspectives and provides more extensive verification.

However, for a very simple equation such as this one, the additional methods are not necessary.


⚖️ Answer 1 vs Answer 2

Criterion Answer 1 Answer 2
Correct final answer
Mathematical validity
Step-by-step explanation
Directness ⭐⭐⭐⭐⭐ ⭐⭐⭐
Appropriate explanation length ⭐⭐⭐⭐⭐ ⭐⭐
Verification ✅✅
Alternative methods ✅✅✅
Repeated-root recognition
Unnecessary complexity Low Higher
Best for this example Good

Key Observation

The comparison illustrates an important principle for mathematical language models:

More reasoning does not automatically mean better reasoning.

For simple mathematical problems, excessive reasoning can reduce clarity rather than improve it.

A strong model should be able to adapt its explanation to the complexity of the problem.


🚀 Inference

The model can be used with Hugging Face Transformers and the Qwen chat template.

Basic Inference

messages = [
    {"role": "user", "content": "Solve (x + 2)^2 = 0."}
]

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

from transformers import TextStreamer

_ = model.generate(
    **tokenizer(text, return_tensors="pt").to("cuda"),
    max_new_tokens=450,
    temperature=0.7,
    top_p=0.8,
    top_k=20,
    streamer=TextStreamer(tokenizer, skip_prompt=False),
)

🧠 Reasoning-Oriented Prompt

A prompt that explicitly asks the model to think carefully can encourage a more deliberate response:

messages = [
    {
        "role": "user",
        "content": "think hard and then solve this: (x + 2)^2 = 0."
    }
]

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

from transformers import TextStreamer

_ = model.generate(
    **tokenizer(text, return_tensors="pt").to("cuda"),
    max_new_tokens=600,
    temperature=0.7,
    top_p=0.8,
    top_k=20,
    streamer=TextStreamer(tokenizer, skip_prompt=False),
)

📚 Training Data

The model was tuned using large-scale mathematical reasoning datasets.

Dataset I — OpenMathReasoning

unsloth/OpenMathReasoning

Used to expose the model to high-quality mathematical reasoning and structured problem-solving examples.

Dataset II — MathX-5M

Modotte/MathX-5M

A large-scale mathematical reasoning dataset containing approximately 5 million reasoning samples, providing broad exposure to step-by-step mathematical problem solving.

Together, these datasets provide training signals across a wide range of mathematical reasoning patterns.


🔬 Training Focus

The fine-tuning process focuses on strengthening the model's ability to:

Understand

Identify the mathematical structure and requirements of the problem.

Reason

Break a problem into logical mathematical steps.

Solve

Produce the correct mathematical result.

Verify

Check the result when appropriate.

Explain

Communicate the solution clearly and in a structured way.

Adapt

Adjust the amount of explanation according to the complexity of the problem.


🧮 Mathematical Reasoning Philosophy

The model is tuned around a simple principle:

[ \boxed{\text{Better Reasoning} \neq \text{Longer Reasoning}} ]

For a simple equation, a concise derivation may be superior.

For a complex problem, a detailed derivation and verification process may be necessary.

The desired behavior is therefore useful reasoning, rather than reasoning length for its own sake.


⚙️ Generation Configuration

The example inference configuration uses:

temperature = 0.7
top_p       = 0.8
top_k       = 20

These parameters provide a sampling configuration suitable for generating varied mathematical explanations.

For deterministic evaluation and benchmarking, consider using deterministic decoding and a fixed random seed.


💾 Precision

The model uses 16-bit floating-point precision.

This provides a practical balance between numerical precision, GPU memory consumption, and inference performance.


📈 Recommended Evaluation

For mathematical reasoning models, evaluation should consider more than final-answer accuracy.

Recommended evaluation dimensions include:

Metric What it measures
Final Answer Accuracy Whether the final result is correct
Reasoning Accuracy Whether the reasoning steps are mathematically valid
Step Completeness Whether essential steps are present
Verification Quality Whether the solution is correctly checked
Conciseness Whether unnecessary reasoning is avoided
Robustness Whether the model performs consistently across prompt variations
Adaptability Whether explanation depth matches problem complexity

A strong model should ideally achieve high accuracy without unnecessarily overcomplicating simple problems.


⚠️ Limitations

Although this model is specialized for mathematical reasoning, it may still produce:

  • Arithmetic mistakes
  • Incorrect intermediate reasoning
  • Unnecessary solution steps
  • Incorrect assumptions
  • Hallucinated explanations
  • Incorrect answers on highly complex or unusual problems

For critical mathematical applications, generated solutions should be independently verified.


🤝 Intended Use

This model is intended for:

  • Mathematical reasoning research
  • Educational applications
  • Mathematical question answering
  • LLM fine-tuning experiments
  • Reasoning model research
  • Mathematical benchmark experimentation
  • Step-by-step mathematical assistance

It should not be considered a replacement for formal mathematical software or independent verification in high-stakes applications.


🙏 Acknowledgements

This model builds upon the work of:

  • Qwen3
  • Unsloth OpenMathReasoning
  • Modotte MathX-5M
  • Hugging Face Transformers

Thanks to the researchers and developers behind these projects and datasets.


⭐ Summary

This model is a Qwen3-4B-based mathematical reasoning model fine-tuned on large-scale mathematical reasoning datasets.

Its objective is to generate solutions that are:

Correct. Structured. Verifiable. Clear. Proportional to the problem.

The example above illustrates the desired distinction:

Answer 1: concise, direct, and appropriate for a simple equation.

Answer 2: mathematically valid and more exhaustive, but unnecessarily complex for the same simple problem.

The central goal is not to maximize the amount of reasoning.

The goal is to maximize the quality and usefulness of reasoning.

Downloads last month
253
Safetensors
Model size
4B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support