File size: 7,551 Bytes
c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 a7223a0 c29d455 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
---
library_name: transformers
tags:
- unsloth
- trl
- grpo
license: mit
datasets:
- eagle0504/openai-gsm8k-enhanced-using-together-ai-deepseek-train8k-test1k-v1
language:
- en
base_model:
- Qwen/Qwen2.5-1.5B-Instruct
---
# Qwen2.5-1.5B-Instruct Fine-Tuned on GSM8K with DeepSeek Augmentation
## Model Overview
This model is a fine-tuned version of **Qwen2.5-1.5B-Instruct**, designed for **mathematical problem-solving and structured reasoning**. It is trained on an **enhanced GSM8K dataset** incorporating **Chain-of-Thought (CoT) reasoning** augmented by **DeepSeek AI**.
### Key Features
- **Base Model:** Qwen2.5-1.5B-Instruct
- **Fine-Tuned On:** GSM8K enhanced with DeepSeek-V3
- **Optimized for:** Logical problem-solving and math reasoning
- **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-openai-gsm8k-data-enhanced-with-deepseek-v2)
## 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-openai-gsm8k-data-enhanced-with-deepseek-v2"
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 = "Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May?"
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-openai-gsm8k-data-enhanced-with-deepseek-v2/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-openai-gsm8k-data-enhanced-with-deepseek-v2:Q8_0
```
### Step 4: Test with a Prompt
```sh
llama-cli -m ~/llama_models/q8_0.gguf -p "Explain quantum computing in simple terms."
```
## 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("<think>\n") == 1:
count += 0.125
if text.count("\n</think>\n") == 1:
count += 0.125
if text.count("\n<answer>\n") == 1:
count += 0.125
count -= len(text.split("\n</answer>\n")[-1])*0.001
if text.count("\n</answer>") == 1:
count += 0.125
count -= (len(text.split("\n</answer>")[-1]) - 1)*0.001
# Ensure `<think>` and `</think>` exist
if "<think>" in text and "</think>" 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 |
|-----------|--------|
| `"<think>\n"` appears exactly **once** | **+0.125** |
| `"\n</think>\n"` appears exactly **once** | **+0.125** |
| `"\n<answer>\n"` appears exactly **once** | **+0.125** |
| `"\n</answer>"` appears exactly **once** | **+0.125** |
| Both `<think>` and `</think>` exist anywhere | **+1.0** |
| No extra text after `"</answer>"` | **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 `"</answer>"`**:
\[
-\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
<think>
Valid reasoning goes here.
</think>
<answer>
Correct final answer here.
</answer>
```
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/openai-gsm8k-enhanced-using-together-ai-deepseek-train8k-test1k-v1`](https://huggingface.co/datasets/eagle0504/openai-gsm8k-enhanced-using-together-ai-deepseek-train8k-test1k-v1)
This dataset contains:
- **8K training samples**
- **1K testing samples**
- Features: `question`, `answer`, `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`
## Model Performance
### Training Loss
| Step | XML Count |
|------|-----------|
| 10 | -1 |
| 100 | -1 |
| 500 | -0.6421 |
| 750 | 0.7611 |
| 1000 | 1.0506 |
As we can see, after 1000 steps, we see the reward of XML Count is above 1, which is getting good. This took about `1h 46min 50s` on a T4 GPU in Colab with High RAM.
## Bias, Risks, and Limitations
### Potential Risks
- May **hallucinate** incorrect reasoning steps if prompts are unclear.
- Could struggle with **complex mathematical problems** outside its training data.
- **Limited generalization** to non-math reasoning tasks.
### Recommendations
- If using this model for **critical applications**, verify outputs with human review.
- For **better performance**, fine-tune on **larger datasets** with real-world numerical reasoning.
## Environmental Impact
**Estimated Carbon Emissions:**
- **Hardware Used:** NVIDIA A100 GPU
- **Training Time:** ~5 hours
- **Estimated CO2 Emitted:** ~8.2 kg CO2eq (via [ML Impact Calculator](https://mlco2.github.io/impact#compute))
## Citation
Upcoming
## Contact
For questions, suggestions, or issues, reach out via [Hugging Face Discussions](https://huggingface.co/eagle0504/qwen-2_5-1_5b-instruct-using-openai-gsm8k-data-enhanced-with-deepseek-v1/discussions).
---
🎉 **Thank you for using this model!** If you find it useful, please ⭐ it on **Hugging Face**! 🚀🔥
|