Uploaded finetuned model

  • Developed by: aliRafik
  • License: apache-2.0
  • Finetuned from model : unsloth/qwen2.5-7b-unsloth-bnb-4bit

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

🧠 Qwen2.5-7B Thinking β€” Alpaca Clean By ALI RAFIK

A fine-tuned Qwen2.5-7B model trained on the cleaned Alpaca instruction-following dataset to improve instruction following, structured responses, and reasoning-oriented task completion.

The model is released in 16-bit precision and was fine-tuned using LoRA with Unsloth.


πŸš€ Model Highlights

  • Base Model: unsloth/Qwen2.5-7B
  • Fine-Tuning Dataset: yahma/alpaca-cleaned
  • Dataset Size: ~52K instruction-following examples
  • Training Method: LoRA / PEFT
  • LoRA Rank: 16
  • Target Modules: Attention + MLP projection layers
  • Context Length: 2048
  • Precision: 16-bit
  • Optimizer: AdamW 8-bit
  • Framework: Unsloth + Hugging Face Transformers + TRL
  • Final Model: aliRafik/Qwen2.5_7B_Thinking_alpaca_Clean_16bit

🎯 Goal

The main objective of this fine-tuning run was to improve the model's ability to follow instructions and produce clear, structured, and logically organized responses.

The training focuses particularly on:

Instruction Following β†’ Reasoning β†’ Structure β†’ Clarity


πŸ“š Training Data

The model was fine-tuned on:

yahma/alpaca-cleaned

This is a cleaned version of the original Alpaca instruction-following dataset containing approximately 52K examples.

The dataset provides instruction/input/output pairs covering a broad range of tasks, helping the model improve its ability to understand an instruction and generate an appropriate response.


πŸ› οΈ Fine-Tuning Configuration

The model was fine-tuned using LoRA through Unsloth.

LoRA Configuration

r = 16
lora_alpha = 16
lora_dropout = 0
bias = "none"

Target modules:

[
    "q_proj",
    "k_proj",
    "v_proj",
    "o_proj",
    "gate_proj",
    "up_proj",
    "down_proj",
]

Training Configuration

per_device_train_batch_size = 8
gradient_accumulation_steps = 4
num_train_epochs = 1
learning_rate = 2e-5
weight_decay = 0.01
optimizer = adamw_8bit
lr_scheduler = linear
seed = 3407

Gradient checkpointing was enabled using the Unsloth implementation to improve memory efficiency during training.


πŸ“Š Before vs After Fine-Tuning

One of the clearest examples of the effect of fine-tuning comes from a simple work-rate problem.

Problem

If 6 workers can build a wall in 12 days, how many days would it take 9 workers to build the same wall, assuming they work at the same rate? Also, if the wall needs to be built in 4 days, how many workers are needed?

The correct results are:

9 workersβ†’8 days 9\text{ workers} \rightarrow 8\text{ days}

and

4 daysβ†’18 workers 4\text{ days} \rightarrow 18\text{ workers}


πŸ”΅ Before Fine-Tuning

The base Qwen2.5-7B model produced a mathematically reasonable approach, but the response contained a notable issue:

First, let's find out the work rate of one worker.

1 wall / (6 workers Γ— 12 days)
= 1/72 wall per worker per day

It then attempted to calculate the solution using individual worker rates.

However, the generated response also contained an incorrect intermediate phrase:

"how many days it would take for 92 workers..."

and the response became incomplete near the second calculation.

Observation

The model was able to identify the underlying work-rate concept, but the solution was less robust and contained an inconsistency during generation.


🟒 After Fine-Tuning

After fine-tuning on Alpaca-cleaned, the same model produced a much cleaner solution based on worker-days.

The model first establishes:

6Γ—12=72 6 \times 12 = 72

Therefore, the wall requires:

72 worker-days 72\text{ worker-days}

For 9 workers:

72Γ·9=8 72 \div 9 = 8

So:

8 days \boxed{8\text{ days}}

For a 4-day deadline:

72Γ·4=18 72 \div 4 = 18

So:

18 workers \boxed{18\text{ workers}}

The final response is direct, consistent, and mathematically complete.


βš–οΈ Before vs After

Aspect Before Fine-Tuning After Fine-Tuning
Correct approach βœ… βœ…
Final result Partially generated βœ… Complete
Reasoning structure Moderate βœ… Clear
Intermediate consistency ❌ Contains an inconsistency βœ… Consistent
Work-rate explanation βœ… βœ…
Worker-days method ❌ Not used directly βœ…
Second calculation completed ❌ Incomplete βœ…
Overall clarity Moderate ⭐⭐⭐⭐⭐
Instruction following Good βœ… Improved

Key Takeaway

The most noticeable improvement is not simply the final numerical answer.

The fine-tuned model provides a more stable, structured, and complete solution, using a simpler formulation of the problem.

This illustrates one of the goals of instruction fine-tuning:

Turn a generally capable language model into a model that follows the requested task more consistently and produces more useful outputs.


πŸ§ͺ Reproducible Inference

The same prompt can be used to compare the base and fine-tuned models.

inputs = tokenizer(
    [
        alpaca_prompt.format(
            "Explain and solve the following problem in detail.",
            "If 6 workers can build a wall in 12 days, how many days would it take 9 workers to build the same wall, assuming they work at the same rate? Also, if the wall needs to be built in 4 days, how many workers are needed?",
            ""
        )
    ],
    return_tensors="pt"
).to("cuda")

outputs = model.generate(
    **inputs,
    max_new_tokens=300,
    use_cache=True
)

print(tokenizer.batch_decode(outputs)[0])

πŸ”Ž Additional Inference Example

The same model can also be used for simpler instruction-following tasks.

messages = [
    {
        "role": "user",
        "content": "Continue the Fibonacci sequence: 1, 1, 2, 3, 5, 8"
    }
]

The fine-tuned model is intended to produce a direct continuation while following the requested format.


πŸ“ˆ What Improved?

The fine-tuning was intended to strengthen several areas:

Instruction Following

Better alignment between the requested task and the generated response.

Structured Reasoning

More organized progression from the problem statement to the solution.

Completeness

Greater tendency to finish all parts of a multi-part instruction.

Mathematical Consistency

Reduced likelihood of introducing inconsistent intermediate statements within a solution.

Clarity

More readable and practically useful explanations.


⚠️ Important Evaluation Note

The before/after example above is qualitative evidence from a single inference example, not a formal benchmark.

A proper evaluation should compare both models over a larger set of mathematical and instruction-following tasks using metrics such as:

Metric Purpose
Exact Answer Accuracy Measures final correctness
Reasoning Accuracy Measures validity of intermediate steps
Completion Rate Measures whether all requested parts are answered
Instruction Following Measures adherence to the prompt
Consistency Measures stability across similar prompts
Response Quality Measures clarity and usefulness

πŸ’Ύ Model Format

The final model was exported as a merged 16-bit model:

aliRafik/Qwen2.5_7B_Thinking_alpaca_Clean_16bit

This repository contains the merged model suitable for standard Transformer-based inference.


⚑ Why LoRA + Unsloth?

LoRA enables efficient fine-tuning by updating a relatively small set of trainable parameters instead of the entire model.

Unsloth was used to make the training process more memory-efficient and practical on consumer and cloud GPUs.

This combination makes it possible to fine-tune a 7B-parameter model with significantly lower resource requirements than full-parameter fine-tuning.


🀝 Acknowledgements

This model builds upon:

  • Qwen2.5
  • Unsloth
  • Hugging Face Transformers
  • Hugging Face TRL
  • yahma/alpaca-cleaned
  • The original Stanford Alpaca project

⚠️ Limitations

This model can still produce:

  • Incorrect mathematical reasoning
  • Arithmetic mistakes
  • Hallucinated information
  • Incomplete answers
  • Overly verbose responses
  • Incorrect interpretations of ambiguous instructions

The model should therefore be evaluated on a broader benchmark before being used in production or high-stakes applications.


⭐ Summary

Qwen2.5-7B Thinking β€” Alpaca Clean is a fine-tuned Qwen2.5-7B model trained on approximately 52K cleaned Alpaca instruction-following examples.

The goal of this project was to improve:

Instruction Following + Reasoning + Structure + Completeness

The before/after inference example demonstrates a practical improvement: the fine-tuned model produces a more consistent and complete solution to a multi-step mathematical problem, while using a simpler and clearer reasoning strategy.

Fine-tuning is not only about changing what a model knows β€” it can also change how effectively the model applies what it already knows.

Downloads last month
395
Safetensors
Model size
8B params
Tensor type
BF16
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support