coderian commited on
Commit
bc32515
·
verified ·
1 Parent(s): 71eb514

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +246 -0
README.md ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - tr
4
+ - en
5
+ license: apache-2.0
6
+ base_model: Qwen/Qwen2.5-1.5B
7
+ tags:
8
+ - axiom
9
+ - qwen
10
+ - qwen2
11
+ - fine-tuned
12
+ - lora
13
+ - sft
14
+ - trl
15
+ - code
16
+ - python
17
+ - text-generation
18
+ pipeline_tag: text-generation
19
+ model_type: qwen2
20
+ library_name: transformers
21
+ ---
22
+
23
+ # Axiom Python 1.5B
24
+
25
+ **Axiom Python 1.5B** is a text generation (causal language model) fine-tuned on [Qwen/Qwen2.5-1.5B](https://huggingface.co/Qwen/Qwen2.5-1.5B) with a focus on Python programming and code generation.
26
+
27
+ The model was trained using **LoRA + SFT** with the [TRL](https://github.com/huggingface/trl) library on the [CodeAlpaca_20K](https://huggingface.co/datasets/HuggingFaceH4/CodeAlpaca_20K) and [PythonCodeInstruct_18K](https://huggingface.co/datasets/iamtarun/python_code_instructions_18k_alpaca) datasets.
28
+
29
+ ## Model Details
30
+
31
+ | Property | Value |
32
+ |---|---|
33
+ | Base Model | [Qwen/Qwen2.5-1.5B](https://huggingface.co/Qwen/Qwen2.5-1.5B) |
34
+ | Architecture | Qwen2ForCausalLM |
35
+ | Parameters | ~1.5B |
36
+ | Hidden Layers | 28 |
37
+ | Hidden Size | 1536 |
38
+ | Attention Heads | 12 |
39
+ | KV Heads | 2 |
40
+ | Vocabulary Size | 151936 |
41
+ | Max Context Length | 131072 |
42
+ | Weight Dtype | float16 (FP16) |
43
+ | Training Method | LoRA (r=16, alpha=32) + SFT |
44
+ | Datasets | CodeAlpaca_20K + PythonCodeInstruct_18K |
45
+ | Languages | Turkish and English (code-focused) |
46
+
47
+ ## Installation
48
+
49
+ Install the following packages to get started:
50
+
51
+ ```bash
52
+ pip install transformers torch
53
+ ```
54
+
55
+ > If you are using a GPU, make sure you have installed a CUDA-compatible PyTorch version.
56
+
57
+ ## Usage
58
+
59
+ ### 1. Using `pipeline` (Simplest Way)
60
+
61
+ ```python
62
+ from transformers import pipeline
63
+
64
+ generator = pipeline(
65
+ "text-generation",
66
+ model="coderian/axiom-python-1.5B",
67
+ device_map="auto",
68
+ torch_dtype="auto",
69
+ )
70
+
71
+ prompt = """### Instruction:
72
+ Write a Python function that reverses the elements of a list.
73
+
74
+ ### Answer:
75
+ """
76
+
77
+ output = generator(
78
+ prompt,
79
+ max_new_tokens=256,
80
+ temperature=0.7,
81
+ top_p=0.9,
82
+ do_sample=True,
83
+ )
84
+
85
+ print(output[0]["generated_text"])
86
+ ```
87
+
88
+ ### 2. Using `AutoModelForCausalLM`
89
+
90
+ ```python
91
+ import torch
92
+ from transformers import AutoModelForCausalLM, AutoTokenizer
93
+
94
+ model_id = "coderian/axiom-python-1.5B"
95
+
96
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
97
+ model = AutoModelForCausalLM.from_pretrained(
98
+ model_id,
99
+ torch_dtype=torch.float16,
100
+ device_map="auto",
101
+ )
102
+
103
+ model.eval()
104
+
105
+ prompt = """### Instruction:
106
+ Write a Python function that adds two numbers.
107
+
108
+ ### Answer:
109
+ """
110
+
111
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
112
+
113
+ with torch.no_grad():
114
+ outputs = model.generate(
115
+ **inputs,
116
+ max_new_tokens=256,
117
+ temperature=0.7,
118
+ top_p=0.9,
119
+ do_sample=True,
120
+ pad_token_id=tokenizer.eos_token_id,
121
+ )
122
+
123
+ response = tokenizer.decode(
124
+ outputs[0][inputs["input_ids"].shape[1]:],
125
+ skip_special_tokens=True,
126
+ )
127
+
128
+ print(response)
129
+ ```
130
+
131
+ ### 3. Using the Chat Template
132
+
133
+ Since the Qwen2.5 tokenizer supports the ChatML format, you can also use the model for chat-style conversations:
134
+
135
+ ```python
136
+ import torch
137
+ from transformers import AutoModelForCausalLM, AutoTokenizer
138
+
139
+ model_id = "coderian/axiom-python-1.5B"
140
+
141
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
142
+ model = AutoModelForCausalLM.from_pretrained(
143
+ model_id,
144
+ torch_dtype=torch.float16,
145
+ device_map="auto",
146
+ )
147
+
148
+ messages = [
149
+ {"role": "system", "content": "You are Axiom, a helpful Python coding assistant."},
150
+ {"role": "user", "content": "Write a Python function to check if a number is prime."},
151
+ ]
152
+
153
+ text = tokenizer.apply_chat_template(
154
+ messages,
155
+ tokenize=False,
156
+ add_generation_prompt=True,
157
+ )
158
+
159
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
160
+
161
+ with torch.no_grad():
162
+ outputs = model.generate(
163
+ **inputs,
164
+ max_new_tokens=256,
165
+ temperature=0.7,
166
+ top_p=0.9,
167
+ do_sample=True,
168
+ pad_token_id=tokenizer.eos_token_id,
169
+ )
170
+
171
+ response = tokenizer.decode(
172
+ outputs[0][inputs["input_ids"].shape[1]:],
173
+ skip_special_tokens=True,
174
+ )
175
+
176
+ print(response)
177
+ ```
178
+
179
+ ### Recommended Generation Parameters
180
+
181
+ | Parameter | Suggested Value | Description |
182
+ |---|---|---|
183
+ | `max_new_tokens` | `512` | Maximum number of new tokens to generate |
184
+ | `temperature` | `0.7` | Lower values produce more deterministic output |
185
+ | `top_p` | `0.9` | Nucleus sampling ratio |
186
+ | `do_sample` | `True` | Enable/disable sampling |
187
+ | `repetition_penalty` | `1.05` | Reduces repetitive output |
188
+
189
+ ## Training Details
190
+
191
+ | Setting | Value |
192
+ |---|---|
193
+ | Base Model | Qwen/Qwen2.5-1.5B |
194
+ | LoRA Rank (r) | 16 |
195
+ | LoRA Alpha | 32 |
196
+ | LoRA Dropout | 0.05 |
197
+ | Target Modules | q_proj, v_proj |
198
+ | Batch Size | 32 (2 x 4 grad. accumulation) |
199
+ | Training Epochs | 1 |
200
+ | Learning Rate | 2e-4 |
201
+ | Optimizer | AdamW (fused) |
202
+ | Precision | FP16 |
203
+ | Steps | 4000 |
204
+ | Max Sequence Length | 256 |
205
+ | Adapter Location | `axiom-python-1.5B/checkpoint-4000` |
206
+
207
+ After training, the LoRA adapter was merged into the base model and released as a single file. You can also load the adapter directly using the peft library:
208
+
209
+ ```python
210
+ from peft import PeftModel
211
+ from transformers import AutoModelForCausalLM, AutoTokenizer
212
+
213
+ base = AutoModelForCausalLM.from_pretrained(
214
+ "Qwen/Qwen2.5-1.5B",
215
+ torch_dtype="auto",
216
+ device_map="auto",
217
+ )
218
+
219
+ model = PeftModel.from_pretrained(base, "path/to/adapter")
220
+ ```
221
+
222
+ ## Limitations
223
+
224
+ - It is a small 1.5B parameter model and may make mistakes on very complex and long code generation tasks.
225
+ - It was trained only on Python-focused datasets; performance in other languages is limited.
226
+ - The training data has a maximum length of 256 tokens; consistency may degrade in very long contexts.
227
+ - Generated code may not always be correct or safe. Review it before running.
228
+ - It may contain known limitations inherited from the training data regarding bias and harmful content.
229
+
230
+ ## Intended Usage Tips
231
+
232
+ - It performs best on single-line and medium-complexity Python functions.
233
+ - Lower the `temperature` value if you want stable output for code generation.
234
+ - Since the model was trained in a completion format, the `### Instruction:` / `### Answer:` template yields the highest quality output.
235
+ - For batched inference, remember to set `tokenizer.pad_token = tokenizer.eos_token`.
236
+
237
+ ## License
238
+
239
+ The base model Qwen2.5 is released under the Apache-2.0 license, and this model is also shared under the **Apache-2.0** license.
240
+
241
+ ## Resources
242
+
243
+ - Base Model: [Qwen/Qwen2.5-1.5B](https://huggingface.co/Qwen/Qwen2.5-1.5B)
244
+ - Training Library: [TRL](https://github.com/huggingface/trl)
245
+ - Dataset 1: [HuggingFaceH4/CodeAlpaca_20K](https://huggingface.co/datasets/HuggingFaceH4/CodeAlpaca_20K)
246
+ - Dataset 2: [iamtarun/python_code_instructions_18k_alpaca](https://huggingface.co/datasets/iamtarun/python_code_instructions_18k_alpaca)