Update README.md

#1
by karim0010 - opened
Files changed (1) hide show
  1. README.md +123 -8
README.md CHANGED
@@ -1,3 +1,4 @@
 
1
  ---
2
  language:
3
  - en
@@ -8,28 +9,142 @@ tags:
8
  - qwen
9
  - qlora
10
  - custom-finetune
 
 
11
  datasets:
12
  - iamtarun/python_code_instructions_18k_alpaca
13
  base_model: Qwen/Qwen2.5-Coder-1.5B-Instruct
14
  ---
15
 
16
- # Qwen2.5-Coder-1.5B-python-MyTune (Fine-tuned by Karim)
 
 
17
 
18
- ## ๐Ÿ“Œ Model Description
19
- This model is a highly optimized, fine-tuned version of `Qwen/Qwen2.5-Coder-1.5B-Instruct`. It has been specifically trained to understand complex algorithmic instructions and generate clean, efficient, and highly accurate **Python** code.
20
 
21
- The training architecture utilized the **QLoRA** (Quantized Low-Rank Adaptation) method. This approach ensures high parameter efficiency, allowing the model to acquire new coding skills while preserving the robust logical reasoning capabilities of the original base weights.
 
 
 
 
 
 
 
 
22
 
23
  ## ๐Ÿ“Š Training Data
 
24
  The model was fine-tuned on a carefully curated subset of the [iamtarun/python_code_instructions_18k_alpaca](https://huggingface.co/datasets/iamtarun/python_code_instructions_18k_alpaca) dataset. This dataset provides high-quality Python coding instructions, algorithmic challenges, and their corresponding structured solutions.
25
 
26
  ## ๐ŸŽฏ Intended Use
 
27
  This model is designed to assist software engineers, data scientists, and quantitative analysts with:
28
  - Generating Python scripts from natural language prompts.
29
  - Solving complex algorithmic problems.
30
  - Writing data engineering and mathematical logic code.
31
 
32
- ## โš™๏ธ Training Hardware
33
- - **Compute:** Google Colab T4 GPU (16GB VRAM)
34
- - **Precision:** Mixed Precision (4-bit Base + float16 Adapters)
35
- - **Method:** PEFT / QLoRA Integration
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
  ---
3
  language:
4
  - en
 
9
  - qwen
10
  - qlora
11
  - custom-finetune
12
+ - code
13
+ - ollama
14
  datasets:
15
  - iamtarun/python_code_instructions_18k_alpaca
16
  base_model: Qwen/Qwen2.5-Coder-1.5B-Instruct
17
  ---
18
 
19
+ # ๐Ÿค– Qwen2.5-Coder-1.5B-python-MyTune
20
+
21
+ **Fine-tuned with โค๏ธ by Karim**
22
 
23
+ Welcome to **Qwen2.5-Coder-1.5B-python-MyTune**! This is a highly optimized, fine-tuned version of `Qwen/Qwen2.5-Coder-1.5B-Instruct`, specifically engineered to understand complex algorithmic instructions and generate clean, efficient, and highly accurate **Python** code.
 
24
 
25
+ ## ๐Ÿ“Œ Model Overview
26
+
27
+ The training architecture utilized the **QLoRA** (Quantized Low-Rank Adaptation) method. This approach ensures high parameter efficiency, allowing the model to acquire advanced coding skills while preserving the robust logical reasoning capabilities of the original base weights.
28
+
29
+ - **Base Model:** Qwen/Qwen2.5-Coder-1.5B-Instruct
30
+ - **Language:** English / Python
31
+ - **Training Method:** PEFT / QLoRA Integration
32
+ - **Precision:** Mixed Precision (4-bit Base + float16 Adapters)
33
+ - **Compute:** Google Colab T4 GPU (16GB VRAM)
34
 
35
  ## ๐Ÿ“Š Training Data
36
+
37
  The model was fine-tuned on a carefully curated subset of the [iamtarun/python_code_instructions_18k_alpaca](https://huggingface.co/datasets/iamtarun/python_code_instructions_18k_alpaca) dataset. This dataset provides high-quality Python coding instructions, algorithmic challenges, and their corresponding structured solutions.
38
 
39
  ## ๐ŸŽฏ Intended Use
40
+
41
  This model is designed to assist software engineers, data scientists, and quantitative analysts with:
42
  - Generating Python scripts from natural language prompts.
43
  - Solving complex algorithmic problems.
44
  - Writing data engineering and mathematical logic code.
45
 
46
+ ---
47
+
48
+ ## ๐Ÿš€ Quick Start: How to Use
49
+
50
+ You can easily load and run this model locally or on a cloud server using either the standard Hugging Face `transformers` library, or deploy it instantly using **Ollama** for local inference.
51
+
52
+ ### Option A: Local Deployment via Ollama (Recommended for Speed)
53
+
54
+ Run this model entirely on your local machine without internet connection using Ollama!
55
+
56
+ **Step 1: Download the Model Files**
57
+ First, download the safetensors weights to a local directory:
58
+ ```bash
59
+ pip install -U huggingface_hub
60
+ huggingface-cli download karim0010/Qwen2.5-Coder-1.5B-python-MyTune --local-dir ./my_qwen_model
61
+
62
+ ```
63
+
64
+ **Step 2: Create a `Modelfile**`
65
+ In the same folder, create a file named `Modelfile` (no extension) and paste the following ChatML configuration:
66
+
67
+ ```dockerfile
68
+ FROM ./my_qwen_model
69
+
70
+ TEMPLATE """{{ if .System }}<|im_start|>system
71
+ {{ .System }}<|im_end|>
72
+ {{ end }}{{ if .Prompt }}<|im_start|>user
73
+ {{ .Prompt }}<|im_end|>
74
+ {{ end }}<|im_start|>assistant
75
+ """
76
+
77
+ PARAMETER stop "<|im_start|>"
78
+ PARAMETER stop "<|im_end|>"
79
+ PARAMETER temperature 0.3
80
+ PARAMETER top_p 0.9
81
+
82
+ ```
83
+
84
+ **Step 3: Compile and Run**
85
+ Build the model in Ollama and start chatting:
86
+
87
+ ```bash
88
+ ollama create karim-coder -f ./Modelfile
89
+ ollama run karim-coder
90
+
91
+ ```
92
+
93
+ *Now you can ask it to write Python code right in your terminal!*
94
+
95
+ ---
96
+
97
+ ### Option B: Python Inference (Hugging Face Transformers)
98
+
99
+ If you prefer integrating the model directly into your Python pipeline, use the following code.
100
+
101
+ **1. Install Dependencies**
102
+
103
+ ```bash
104
+ pip install transformers torch accelerate
105
+
106
+ ```
107
+
108
+ **2. Inference Script**
109
+
110
+ ```python
111
+ import torch
112
+ from transformers import AutoModelForCausalLM, AutoTokenizer
113
+
114
+ # Define the repository
115
+ model_id = "karim0010/Qwen2.5-Coder-1.5B-python-MyTune"
116
+
117
+ # Load Tokenizer and Model
118
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
119
+ model = AutoModelForCausalLM.from_pretrained(
120
+ model_id,
121
+ torch_dtype=torch.float16,
122
+ device_map="auto",
123
+ trust_remote_code=True
124
+ )
125
+
126
+ # Prepare the prompt using the ChatML template
127
+ instruction = "Write a complete and clean Python function to calculate the Fibonacci sequence up to a given number 'n'."
128
+ prompt = f"<|im_start|>user\n{instruction}<|im_end|>\n<|im_start|>assistant\n"
129
+
130
+ # Tokenize inputs
131
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
132
+
133
+ # Generate code
134
+ print("Generating code...")
135
+ outputs = model.generate(
136
+ inputs["input_ids"],
137
+ attention_mask=inputs["attention_mask"],
138
+ max_new_tokens=256,
139
+ temperature=0.3, # Low temperature is recommended for accurate coding
140
+ top_p=0.9,
141
+ do_sample=True,
142
+ pad_token_id=tokenizer.eos_token_id
143
+ )
144
+
145
+ # Decode and print the result
146
+ response = tokenizer.decode(outputs[0][len(inputs["input_ids"][0]):], skip_special_tokens=True)
147
+ print("\n--- Output ---")
148
+ print(response.strip())
149
+
150
+ ```