---
library_name: transformers
tags:
- unsloth
- trl
- grpo
license: mit
datasets:
- eagle0504/augmented_codealpaca-20k-using-together-ai-deepseek-v1
language:
- en
base_model:
- Qwen/Qwen2.5-1.5B-Instruct
---
# Qwen2.5-1.5B-Instruct Fine-Tuned on CodeAlpaca-20K with DeepSeek Augmentation
## Model Overview
This model is a fine-tuned version of **Qwen2.5-1.5B-Instruct**, designed for **instruction-following and structured reasoning**. It is trained on an **enhanced CodeAlpaca-20K dataset**, incorporating **Chain-of-Thought (CoT) reasoning** augmented by **DeepSeek AI**.
### Key Features
- **Base Model:** Qwen2.5-1.5B-Instruct
- **Fine-Tuned On:** CodeAlpaca-20K enhanced with DeepSeek-V3
- **Optimized for:** Instruction-following, structured reasoning, and problem-solving
- **Fine-tuning method:** LoRA (Low-Rank Adaptation)
- **Inference-ready:** Available on **Hugging Face** and compatible with `llama.cpp`
- **Supports GGUF:** Optimized versions for **Q4_K_M, Q8_0, Q5_K_M, and FP16**
## Model Details
- **Developed by:** [Yiqiao Yin](https://www.y-yin.io/)
- **Model Type:** Causal Language Model (Text Generation)
- **Languages:** English (`en`)
- **License:** MIT License
- **Fine-tuned from:** `Qwen/Qwen2.5-1.5B-Instruct`
- **Training Library:** `transformers` + `unsloth` + `trl`
- **Quantization:** GGUF (`Q4_K_M, Q8_0, Q5_K_M, f16`)
🔗 **Hugging Face Repository:**
👉 [Fine-tuned Qwen2.5-1.5B-Instruct](https://huggingface.co/eagle0504/qwen-2_5-1_5b-instruct-using-codealpaca-20k-enhanced-v1)
## How to Use the Model
### Using `transformers` in Python
You may need to install `bitsandbytes` by using
```bash
! pip install -U bitsandbytes
```
Then you can use the following code to run inference.
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load model and tokenizer
model_name = "eagle0504/qwen-2_5-1_5b-instruct-using-codealpaca-20k-enhanced-v1"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
# Move model to GPU if available
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
# Example inference
question = "How do I implement a binary search algorithm in Python?"
inputs = tokenizer(question, return_tensors="pt").to(device)
output = model.generate(**inputs, max_length=200)
# Decode response
print(tokenizer.decode(output[0], skip_special_tokens=True))
```
## Running the Model with `llama.cpp`
### Step 1: Install `llama.cpp`
```sh
brew install llama.cpp
```
### Step 2: Download the Model
```sh
mkdir -p ~/llama_models && cd ~/llama_models
wget https://huggingface.co/eagle0504/qwen-2_5-1_5b-instruct-using-codealpaca-20k-enhanced-v1/resolve/main/q8_0.gguf
```
### Step 3: Run the Model
```sh
llama-cli -m ~/llama_models/q8_0.gguf --interactive
```
Or you can use the following:
```sh
llama-cli -hf eagle0504/qwen-2_5-1_5b-instruct-using-codealpaca-20k-enhanced-v1:Q8_0
```
### Step 4: Test with a Prompt
```sh
llama-cli -m ~/llama_models/q8_0.gguf -p "Explain the differences between breadth-first search and depth-first search."
```
## Training Details
### Custom Reward
```python
def count_xml(text: str) -> float:
"""
Calculates a reward based on the occurrence of certain XML tags and subtracts penalties for content after closing tags.
Args:
text (str): The text string to analyze for XML tag consistency.
Returns:
float: Total reward score based on XML tag occurrence and penalties.
"""
count = 0.0
if text.count("\n") == 1:
count += 0.125
if text.count("\n\n") == 1:
count += 0.125
if text.count("\n\n") == 1:
count += 0.125
count -= len(text.split("\n\n")[-1])*0.001
if text.count("\n") == 1:
count += 0.125
count -= (len(text.split("\n")[-1]) - 1)*0.001
# Ensure `` and `` exist
if "" in text and "" in text:
count += 1.0 # Higher weight to ensure reasoning consistency
else:
count -= 1.0 # Penalize if missing
return count
```
Each component contributes to the total reward **if conditions are met**:
| Condition | Reward |
|-----------|--------|
| `"\n"` appears exactly **once** | **+0.125** |
| `"\n\n"` appears exactly **once** | **+0.125** |
| `"\n\n"` appears exactly **once** | **+0.125** |
| `"\n"` appears exactly **once** | **+0.125** |
| Both `` and `` exist anywhere | **+1.0** |
| No extra text after `""` | **No penalty** |
Total possible reward **before penalties**:
\[
0.125 + 0.125 + 0.125 + 0.125 + 1.0 = 1.5
\]
**Potential Penalties**
The function applies penalties for **extra content after `""`**:
\[
-\left( \text{length of extra text} \times 0.001 \right)
\]
If the **best case** occurs (i.e., **no extra content**), then:
- **Penalty = 0**
- **Final Reward = 1.5 (no deductions)**
---
**Best Possible Input Example**
This **ideal input** gives the highest possible reward:
```xml
Valid reasoning goes here.
Correct final answer here.
```
This means we customize the reward function so that we encourage the answer to have reasoning inside. We also know mathematically what the reward should be so we can monitor it during training process.
### Dataset Used
The model was fine-tuned on:
🔹 [`eagle0504/augmented_codealpaca-20k-using-together-ai-deepseek-v1`](https://huggingface.co/datasets/eagle0504/augmented_codealpaca-20k-using-together-ai-deepseek-v1)
This dataset contains:
- **20K augmented training samples**
- Features: `instruction`, `response`, `cot` (Chain-of-Thought)
### Training Configuration
- **Framework:** `transformers` + `unsloth` + `trl`
- **Optimization:** LoRA applied to QKV projections
- **Learning Rate:** `1e-6`
- **AdamW Optimizer (8-bit)**
- **Mixed Precision (`bf16` or `fp16`)**
- **Batch Size:** `8`
- **Max Sequence Length:** `1024`