Update README.md
Browse files
README.md
CHANGED
@@ -4,199 +4,194 @@ tags:
|
|
4 |
- unsloth
|
5 |
- trl
|
6 |
- grpo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
---
|
8 |
|
9 |
-
#
|
10 |
|
11 |
-
|
12 |
|
|
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
## Model Details
|
16 |
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
|
|
20 |
|
21 |
-
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
- **Shared by [optional]:** [More Information Needed]
|
26 |
-
- **Model type:** [More Information Needed]
|
27 |
-
- **Language(s) (NLP):** [More Information Needed]
|
28 |
-
- **License:** [More Information Needed]
|
29 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
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 |
-
## Bias, Risks, and Limitations
|
62 |
-
|
63 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
64 |
-
|
65 |
-
[More Information Needed]
|
66 |
-
|
67 |
-
### Recommendations
|
68 |
-
|
69 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
70 |
-
|
71 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
72 |
-
|
73 |
-
## How to Get Started with the Model
|
74 |
-
|
75 |
-
Use the code below to get started with the model.
|
76 |
-
|
77 |
-
[More Information Needed]
|
78 |
|
79 |
## Training Details
|
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 |
-
#### Summary
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
## Model Examination [optional]
|
139 |
-
|
140 |
-
<!-- Relevant interpretability work for the model goes here -->
|
141 |
-
|
142 |
-
[More Information Needed]
|
143 |
-
|
144 |
-
## Environmental Impact
|
145 |
-
|
146 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
147 |
-
|
148 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
149 |
-
|
150 |
-
- **Hardware Type:** [More Information Needed]
|
151 |
-
- **Hours used:** [More Information Needed]
|
152 |
-
- **Cloud Provider:** [More Information Needed]
|
153 |
-
- **Compute Region:** [More Information Needed]
|
154 |
-
- **Carbon Emitted:** [More Information Needed]
|
155 |
-
|
156 |
-
## Technical Specifications [optional]
|
157 |
-
|
158 |
-
### Model Architecture and Objective
|
159 |
-
|
160 |
-
[More Information Needed]
|
161 |
-
|
162 |
-
### Compute Infrastructure
|
163 |
-
|
164 |
-
[More Information Needed]
|
165 |
-
|
166 |
-
#### Hardware
|
167 |
-
|
168 |
-
[More Information Needed]
|
169 |
-
|
170 |
-
#### Software
|
171 |
-
|
172 |
-
[More Information Needed]
|
173 |
-
|
174 |
-
## Citation [optional]
|
175 |
-
|
176 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
177 |
-
|
178 |
-
**BibTeX:**
|
179 |
-
|
180 |
-
[More Information Needed]
|
181 |
-
|
182 |
-
**APA:**
|
183 |
-
|
184 |
-
[More Information Needed]
|
185 |
-
|
186 |
-
## Glossary [optional]
|
187 |
-
|
188 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
189 |
-
|
190 |
-
[More Information Needed]
|
191 |
-
|
192 |
-
## More Information [optional]
|
193 |
-
|
194 |
-
[More Information Needed]
|
195 |
-
|
196 |
-
## Model Card Authors [optional]
|
197 |
-
|
198 |
-
[More Information Needed]
|
199 |
-
|
200 |
-
## Model Card Contact
|
201 |
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
- unsloth
|
5 |
- trl
|
6 |
- grpo
|
7 |
+
license: mit
|
8 |
+
datasets:
|
9 |
+
- eagle0504/augmented_codealpaca-20k-using-together-ai-deepseek-v1
|
10 |
+
language:
|
11 |
+
- en
|
12 |
+
base_model:
|
13 |
+
- Qwen/Qwen2.5-1.5B-Instruct
|
14 |
---
|
15 |
|
16 |
+
# Qwen2.5-1.5B-Instruct Fine-Tuned on CodeAlpaca-20K with DeepSeek Augmentation
|
17 |
|
18 |
+
## Model Overview
|
19 |
|
20 |
+
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**.
|
21 |
|
22 |
+
### Key Features
|
23 |
+
- **Base Model:** Qwen2.5-1.5B-Instruct
|
24 |
+
- **Fine-Tuned On:** CodeAlpaca-20K enhanced with DeepSeek-V3
|
25 |
+
- **Optimized for:** Instruction-following, structured reasoning, and problem-solving
|
26 |
+
- **Fine-tuning method:** LoRA (Low-Rank Adaptation)
|
27 |
+
- **Inference-ready:** Available on **Hugging Face** and compatible with `llama.cpp`
|
28 |
+
- **Supports GGUF:** Optimized versions for **Q4_K_M, Q8_0, Q5_K_M, and FP16**
|
29 |
|
30 |
## Model Details
|
31 |
|
32 |
+
- **Developed by:** [Yiqiao Yin](https://www.y-yin.io/)
|
33 |
+
- **Model Type:** Causal Language Model (Text Generation)
|
34 |
+
- **Languages:** English (`en`)
|
35 |
+
- **License:** MIT License
|
36 |
+
- **Fine-tuned from:** `Qwen/Qwen2.5-1.5B-Instruct`
|
37 |
+
- **Training Library:** `transformers` + `unsloth` + `trl`
|
38 |
+
- **Quantization:** GGUF (`Q4_K_M, Q8_0, Q5_K_M, f16`)
|
39 |
|
40 |
+
🔗 **Hugging Face Repository:**
|
41 |
+
👉 [Fine-tuned Qwen2.5-1.5B-Instruct](https://huggingface.co/eagle0504/qwen-2_5-1_5b-instruct-using-codealpaca-20k-enhanced-v1)
|
42 |
|
43 |
+
## How to Use the Model
|
44 |
|
45 |
+
### Using `transformers` in Python
|
46 |
+
You may need to install `bitsandbytes` by using
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
+
```bash
|
49 |
+
! pip install -U bitsandbytes
|
50 |
+
```
|
51 |
|
52 |
+
Then you can use the following code to run inference.
|
53 |
+
```python
|
54 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
55 |
+
import torch
|
56 |
|
57 |
+
# Load model and tokenizer
|
58 |
+
model_name = "eagle0504/qwen-2_5-1_5b-instruct-using-codealpaca-20k-enhanced-v1"
|
59 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
60 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
61 |
|
62 |
+
# Move model to GPU if available
|
63 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
64 |
+
model.to(device)
|
65 |
|
66 |
+
# Example inference
|
67 |
+
question = "How do I implement a binary search algorithm in Python?"
|
68 |
+
inputs = tokenizer(question, return_tensors="pt").to(device)
|
69 |
+
output = model.generate(**inputs, max_length=200)
|
70 |
|
71 |
+
# Decode response
|
72 |
+
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
73 |
+
```
|
74 |
|
75 |
+
## Running the Model with `llama.cpp`
|
76 |
|
77 |
+
### Step 1: Install `llama.cpp`
|
78 |
+
```sh
|
79 |
+
brew install llama.cpp
|
80 |
+
```
|
81 |
|
82 |
+
### Step 2: Download the Model
|
83 |
+
```sh
|
84 |
+
mkdir -p ~/llama_models && cd ~/llama_models
|
85 |
+
wget https://huggingface.co/eagle0504/qwen-2_5-1_5b-instruct-using-codealpaca-20k-enhanced-v1/resolve/main/q8_0.gguf
|
86 |
+
```
|
87 |
|
88 |
+
### Step 3: Run the Model
|
89 |
+
```sh
|
90 |
+
llama-cli -m ~/llama_models/q8_0.gguf --interactive
|
91 |
+
```
|
92 |
|
93 |
+
Or you can use the following:
|
94 |
|
95 |
+
```sh
|
96 |
+
llama-cli -hf eagle0504/qwen-2_5-1_5b-instruct-using-codealpaca-20k-enhanced-v1:Q8_0
|
97 |
+
```
|
98 |
|
99 |
+
### Step 4: Test with a Prompt
|
100 |
+
```sh
|
101 |
+
llama-cli -m ~/llama_models/q8_0.gguf -p "Explain the differences between breadth-first search and depth-first search."
|
102 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
## Training Details
|
105 |
|
106 |
+
### Custom Reward
|
107 |
+
|
108 |
+
```python
|
109 |
+
def count_xml(text: str) -> float:
|
110 |
+
"""
|
111 |
+
Calculates a reward based on the occurrence of certain XML tags and subtracts penalties for content after closing tags.
|
112 |
+
|
113 |
+
Args:
|
114 |
+
text (str): The text string to analyze for XML tag consistency.
|
115 |
+
|
116 |
+
Returns:
|
117 |
+
float: Total reward score based on XML tag occurrence and penalties.
|
118 |
+
"""
|
119 |
+
count = 0.0
|
120 |
+
if text.count("<think>\n") == 1:
|
121 |
+
count += 0.125
|
122 |
+
if text.count("\n</think>\n") == 1:
|
123 |
+
count += 0.125
|
124 |
+
if text.count("\n<answer>\n") == 1:
|
125 |
+
count += 0.125
|
126 |
+
count -= len(text.split("\n</answer>\n")[-1])*0.001
|
127 |
+
if text.count("\n</answer>") == 1:
|
128 |
+
count += 0.125
|
129 |
+
count -= (len(text.split("\n</answer>")[-1]) - 1)*0.001
|
130 |
+
|
131 |
+
# Ensure `<think>` and `</think>` exist
|
132 |
+
if "<think>" in text and "</think>" in text:
|
133 |
+
count += 1.0 # Higher weight to ensure reasoning consistency
|
134 |
+
else:
|
135 |
+
count -= 1.0 # Penalize if missing
|
136 |
+
|
137 |
+
return count
|
138 |
+
```
|
139 |
+
|
140 |
+
Each component contributes to the total reward **if conditions are met**:
|
141 |
+
|
142 |
+
| Condition | Reward |
|
143 |
+
|-----------|--------|
|
144 |
+
| `"<think>\n"` appears exactly **once** | **+0.125** |
|
145 |
+
| `"\n</think>\n"` appears exactly **once** | **+0.125** |
|
146 |
+
| `"\n<answer>\n"` appears exactly **once** | **+0.125** |
|
147 |
+
| `"\n</answer>"` appears exactly **once** | **+0.125** |
|
148 |
+
| Both `<think>` and `</think>` exist anywhere | **+1.0** |
|
149 |
+
| No extra text after `"</answer>"` | **No penalty** |
|
150 |
+
|
151 |
+
Total possible reward **before penalties**:
|
152 |
+
\[
|
153 |
+
0.125 + 0.125 + 0.125 + 0.125 + 1.0 = 1.5
|
154 |
+
\]
|
155 |
+
|
156 |
+
**Potential Penalties**
|
157 |
+
The function applies penalties for **extra content after `"</answer>"`**:
|
158 |
+
\[
|
159 |
+
-\left( \text{length of extra text} \times 0.001 \right)
|
160 |
+
\]
|
161 |
+
If the **best case** occurs (i.e., **no extra content**), then:
|
162 |
+
- **Penalty = 0**
|
163 |
+
- **Final Reward = 1.5 (no deductions)**
|
164 |
|
165 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
+
**Best Possible Input Example**
|
168 |
+
This **ideal input** gives the highest possible reward:
|
169 |
+
|
170 |
+
```xml
|
171 |
+
<think>
|
172 |
+
Valid reasoning goes here.
|
173 |
+
</think>
|
174 |
+
|
175 |
+
<answer>
|
176 |
+
Correct final answer here.
|
177 |
+
</answer>
|
178 |
+
```
|
179 |
+
|
180 |
+
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.
|
181 |
+
|
182 |
+
### Dataset Used
|
183 |
+
The model was fine-tuned on:
|
184 |
+
🔹 [`eagle0504/augmented_codealpaca-20k-using-together-ai-deepseek-v1`](https://huggingface.co/datasets/eagle0504/augmented_codealpaca-20k-using-together-ai-deepseek-v1)
|
185 |
+
|
186 |
+
This dataset contains:
|
187 |
+
- **20K augmented training samples**
|
188 |
+
- Features: `instruction`, `response`, `cot` (Chain-of-Thought)
|
189 |
+
|
190 |
+
### Training Configuration
|
191 |
+
- **Framework:** `transformers` + `unsloth` + `trl`
|
192 |
+
- **Optimization:** LoRA applied to QKV projections
|
193 |
+
- **Learning Rate:** `1e-6`
|
194 |
+
- **AdamW Optimizer (8-bit)**
|
195 |
+
- **Mixed Precision (`bf16` or `fp16`)**
|
196 |
+
- **Batch Size:** `8`
|
197 |
+
- **Max Sequence Length:** `1024`
|