File size: 9,769 Bytes
643b1fe 5b3d066 0a2f407 65b911f 50cc58f 02ca28f 50cc58f 65b911f 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 920ff52 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 94d91fc 02ca28f e926275 02ca28f 643b1fe e926275 02ca28f 643b1fe f30ef71 e926275 02ca28f 249613c 890b33e 249613c 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 756e8dd 643b1fe 890b33e 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 756e8dd 643b1fe 890b33e 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 94d91fc ae5d944 94d91fc 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f 643b1fe e926275 7e60984 e926275 7e60984 e926275 02ca28f 643b1fe 02ca28f 643b1fe 02ca28f |
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 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
---
base_model: Qwen/Qwen2.5-Coder-1.5B-Instruct
base_model_relation: finetune
library_name: transformers
language:
- en
tags:
- code
- codeqwen
- chat
- qwen
- qwen-coder
license: gpl-3.0
datasets:
- bunyaminergen/Stable-Code-Python-SFT
pipeline_tag: text-generation
license_link: https://huggingface.co/bunyaminergen/Qwen2.5-Coder-1.5B-Instruct-SFT/blob/main/LICENSE
---
# Qwen2.5-Coder-1.5B-Instruct-SFT
The Qwen2.5-Coder-1.5B-Instruct-SFT model has been fine-tuned using Supervised Fine Tuning (SFT) method specifically to
enhance its performance in generating docstrings, a critical task in coding. Currently, it generates docstrings
following the Google style guide. For differences compared to the base (pre-trained) model, please refer to
the [Comparison](#comparison) section.
**Note**: _Since the model has only been supervised fine-tuned (SFT) for roughly 11 epochs and hasn't been enhanced with
reinforcement learning from human feedback (RLHF), it mostly generates docstrings in the Google Docstring style.
However, it might occasionally produce them in a different style. In such cases, you may need to regenerate the
docstrings once or multiple times._
**Note**: _If you would like to contribute to this repository,
please read the [CONTRIBUTING](CONTRIBUTING.md) first._
---
### TableofContents
- [Usage](#usage)
- [Comparison](#comparison)
- [Dataset](#dataset)
- [Training](#training)
- [Documentations](#documentations)
- [License](#licence)
- [Links](#links)
- [Team](#team)
- [Contact](#contact)
- [Reference](#reference)
- [Citation](#citation)
---
### Usage
#### Hugging Face
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
model_name = "bunyaminergen/Qwen2.5-Coder-1.5B-Instruct-SFT"
quant_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
quantization_config=quant_config,
device_map="auto"
)
model.eval()
messages = [
{"role": "system", "content": "You are a senior Python developer."},
{"role": "user", "content": "Give me a quick example of bubble sort in Python."}
]
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
max_new_tokens = 512
temperature = 0.9
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=max_new_tokens,
temperature=temperature,
do_sample=True,
top_p=0.95,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.eos_token_id
)
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(result)
```
---
### Comparison
#### Base Model
`System:` You are a senior Python developer..
`User:` Give me a quick an example of bubble sort in Python.
`Assistant:` Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent
elements and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted.
Here's a basic implementation of Bubble Sort in Python:
```python
def bubble_sort(arr):
n = len(arr)
# Traverse through all array elements
for i in range(n):
# Last i elements are already in place
for j in range(0, n - i - 1):
# Swap if the element found is greater than the next element
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
# Example usage:
arr = [64, 34, 25, 12, 22, 11, 90]
bubble_sort(arr)
print("Sorted array:", arr)
```
In this example:
- We define a function `bubble_sort` that takes an array as input.
- Inside the function, we use two nested loops to iterate over each pair of adjacent elements in the array.
- If the current element (`arr[j]`) is greater than the next element (`arr[j+1]`), we swap them.
- This process continues until no more swaps are needed, indicating that the array is sorted.
- Finally, we demonstrate how to use the `bubble_sort` function by sorting an array and printing the sorted result.
Bubble Sort has a time complexity of O(n^2) in the worst case scenario, making it less efficient than other sorting
algorithms like QuickSort or MergeSort. However, it is easy to understand and implement, which makes it suitable for
small data sets or educational purposes.
#### Supervised Fine Tuned Model
`System:` You are a senior Python developer.
`User:` Give me a quick an example of bubble sort in Python.
`Assistant:` Here's a simple implementation of the Bubble Sort algorithm in Python, along with its docstring following
Google Python Style Guide:
```python
def bubble_sort(arr):
"""
Bubble sorts an array of integers in ascending order.
Args:
arr (list): A list of integers to be sorted.
Returns:
list: The sorted list of integers.
Raises:
TypeError: If the input is not a list or contains non-integer elements.
Examples:
>>> bubble_sort([5, 3, 1, 4, 6])
[1, 3, 4, 5, 6]
"""
# Check if the input is a list and contains only integers
if not isinstance(arr, list) or not all(isinstance(x, int) for x in arr):
raise TypeError("Input must be a list of integers.")
n = len(arr)
# Traverse through all array elements
for i in range(n):
# Last i elements are already in place
for j in range(0, n - i - 1):
# Traverse the array from 0 to n-i-1
# Swap if the element found is greater than the next element
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return arr
```
This implementation follows the Bubble Sort algorithm, which repeatedly steps through the list, compares adjacent
elements, and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted.
This implementation includes error handling and examples for usage.
---
### Dataset
- [bunyaminergen/Stable-Code-Python-SFT](https://huggingface.co/datasets/bunyaminergen/Stable-Code-Python-SFT)
---
### Training
#### Hyperparameters
| Hyperparameter | Value |
|-----------------------------|---------------------------------------|
| Base Model | `Qwen/Qwen2.5-Coder-1.5B-Instruct` |
| Fine-tuning Method | QLoRA (Quantized Low-Rank Adaptation) |
| Task Type | `CAUSAL_LM` |
| Number of Epochs | `11` |
| Batch Size | `8` |
| Gradient Accumulation Steps | `2` |
| Effective Batch Size | `16` (8 × 2) |
| Learning Rate | `1e-4` |
| Optimizer | `AdamW` |
| Precision | `BF16 Mixed Precision` |
| Evaluation Strategy | `None` |
| Max Sequence Length | `1024 tokens` |
| Logging Steps | every `1000` steps |
| Save Checkpoint Steps | every `7200` steps |
| Output Directory | Overwritten per run |
| Experiment Tracking | `MLflow` (local tracking) |
| Experiment Name | `AssistantFineTuning` |
| MLflow Run Name | `AssistantFT` |
#### PEFT (QLoRA) Configuration
| Parameter | Value |
|-----------------|--------------------------|
| LoRA Rank (`r`) | `16` |
| LoRA Alpha | `32` |
| LoRA Dropout | `0.05` |
| Target Modules | `all-linear` |
| Modules Saved | `lm_head`, `embed_token` |
#### Dataset
- **Train/Test Split:** `90%/10%`
- **Random Seed:** `19`
- **Train Batched:** `True`
- **Eval Batched:** `True`
#### Tokenizer Configuration
- **Truncation:** Enabled (`max_length=1024`)
- **Masked Language Modeling (MLM):** `False`
#### Speeds, Sizes, Times
- **Total Training Time:** ~11 hours
- **Checkpoint Frequency:** every `7200` steps
- **Checkpoint Steps:**
- `checkpoint-7200`
- `checkpoint-14400`
- `checkpoint-21600`
- `checkpoint-28800`
- `checkpoint-36000`
- `checkpoint-39600` *(final checkpoint)*
#### Compute Infrastructure
**Hardware:**
- GPU: **1 × NVIDIA L40S (48 GB VRAM)**
- RAM: **62 GB**
- CPU: **16 vCPU**
**Software:**
- OS: **Ubuntu 22.04**
- Frameworks: **PyTorch 2.4.0**
- CUDA Version: **12.4.1**
---
### Documentations
- [CONTRIBUTING](CONTRIBUTING.md)
---
### Licence
- [LICENSE](LICENSE)
---
### Links
- [Github](https://github.com/bunyaminergen/)
- [Website](https://bunyaminergen.com)
- [Linkedin](https://www.linkedin.com/in/bunyaminergen)
---
### Team
- [Bunyamin Ergen](https://www.linkedin.com/in/bunyaminergen)
---
### Contact
- [Mail](mailto:[email protected])
---
### Reference
- This model has been fine-tuned using Supervised Fine Tuning (SFT) method from the original
model [Qwen/Qwen2.5-Coder-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-1.5B-Instruct).
---
### Citation
```bibtex
@software{ Qwen2.5-Coder-1.5B-Instruct-SFT,
author = {Bunyamin Ergen},
title = {{Qwen2.5-Coder-1.5B-Instruct-SFT}},
year = {2025},
month = {04},
}
```
---
|