🚀 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
and
4 days→18 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
Therefore, the wall requires:
72 worker-days
For 9 workers:
72÷9=8
So:
8 days
For a 4-day deadline:
72÷4=18
So:
18 workers
The final response is direct, consistent, and mathematically complete.
⚖️ Before vs After
Table with columns: Aspect, Before Fine-Tuning, After Fine-Tuning| 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 |
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:
Table with columns: Metric, Purpose| 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 |
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.