Text Generation
Transformers
Safetensors
Turkish
English
qwen2
axiom
qwen
fine-tuned
lora
sft
trl
code
python
conversational
text-generation-inference
Instructions to use coderian/axiom-python-1.5B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use coderian/axiom-python-1.5B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="coderian/axiom-python-1.5B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("coderian/axiom-python-1.5B") model = AutoModelForCausalLM.from_pretrained("coderian/axiom-python-1.5B", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use coderian/axiom-python-1.5B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "coderian/axiom-python-1.5B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "coderian/axiom-python-1.5B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/coderian/axiom-python-1.5B
- SGLang
How to use coderian/axiom-python-1.5B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "coderian/axiom-python-1.5B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "coderian/axiom-python-1.5B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "coderian/axiom-python-1.5B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "coderian/axiom-python-1.5B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use coderian/axiom-python-1.5B with Docker Model Runner:
docker model run hf.co/coderian/axiom-python-1.5B
File size: 6,736 Bytes
bc32515 | 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 | ---
language:
- tr
- en
license: apache-2.0
base_model: Qwen/Qwen2.5-1.5B
tags:
- axiom
- qwen
- qwen2
- fine-tuned
- lora
- sft
- trl
- code
- python
- text-generation
pipeline_tag: text-generation
model_type: qwen2
library_name: transformers
---
# Axiom Python 1.5B
**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.
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.
## Model Details
| Property | Value |
|---|---|
| Base Model | [Qwen/Qwen2.5-1.5B](https://huggingface.co/Qwen/Qwen2.5-1.5B) |
| Architecture | Qwen2ForCausalLM |
| Parameters | ~1.5B |
| Hidden Layers | 28 |
| Hidden Size | 1536 |
| Attention Heads | 12 |
| KV Heads | 2 |
| Vocabulary Size | 151936 |
| Max Context Length | 131072 |
| Weight Dtype | float16 (FP16) |
| Training Method | LoRA (r=16, alpha=32) + SFT |
| Datasets | CodeAlpaca_20K + PythonCodeInstruct_18K |
| Languages | Turkish and English (code-focused) |
## Installation
Install the following packages to get started:
```bash
pip install transformers torch
```
> If you are using a GPU, make sure you have installed a CUDA-compatible PyTorch version.
## Usage
### 1. Using `pipeline` (Simplest Way)
```python
from transformers import pipeline
generator = pipeline(
"text-generation",
model="coderian/axiom-python-1.5B",
device_map="auto",
torch_dtype="auto",
)
prompt = """### Instruction:
Write a Python function that reverses the elements of a list.
### Answer:
"""
output = generator(
prompt,
max_new_tokens=256,
temperature=0.7,
top_p=0.9,
do_sample=True,
)
print(output[0]["generated_text"])
```
### 2. Using `AutoModelForCausalLM`
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "coderian/axiom-python-1.5B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="auto",
)
model.eval()
prompt = """### Instruction:
Write a Python function that adds two numbers.
### Answer:
"""
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=256,
temperature=0.7,
top_p=0.9,
do_sample=True,
pad_token_id=tokenizer.eos_token_id,
)
response = tokenizer.decode(
outputs[0][inputs["input_ids"].shape[1]:],
skip_special_tokens=True,
)
print(response)
```
### 3. Using the Chat Template
Since the Qwen2.5 tokenizer supports the ChatML format, you can also use the model for chat-style conversations:
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "coderian/axiom-python-1.5B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="auto",
)
messages = [
{"role": "system", "content": "You are Axiom, a helpful Python coding assistant."},
{"role": "user", "content": "Write a Python function to check if a number is prime."},
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=256,
temperature=0.7,
top_p=0.9,
do_sample=True,
pad_token_id=tokenizer.eos_token_id,
)
response = tokenizer.decode(
outputs[0][inputs["input_ids"].shape[1]:],
skip_special_tokens=True,
)
print(response)
```
### Recommended Generation Parameters
| Parameter | Suggested Value | Description |
|---|---|---|
| `max_new_tokens` | `512` | Maximum number of new tokens to generate |
| `temperature` | `0.7` | Lower values produce more deterministic output |
| `top_p` | `0.9` | Nucleus sampling ratio |
| `do_sample` | `True` | Enable/disable sampling |
| `repetition_penalty` | `1.05` | Reduces repetitive output |
## Training Details
| Setting | Value |
|---|---|
| Base Model | Qwen/Qwen2.5-1.5B |
| LoRA Rank (r) | 16 |
| LoRA Alpha | 32 |
| LoRA Dropout | 0.05 |
| Target Modules | q_proj, v_proj |
| Batch Size | 32 (2 x 4 grad. accumulation) |
| Training Epochs | 1 |
| Learning Rate | 2e-4 |
| Optimizer | AdamW (fused) |
| Precision | FP16 |
| Steps | 4000 |
| Max Sequence Length | 256 |
| Adapter Location | `axiom-python-1.5B/checkpoint-4000` |
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:
```python
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
base = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2.5-1.5B",
torch_dtype="auto",
device_map="auto",
)
model = PeftModel.from_pretrained(base, "path/to/adapter")
```
## Limitations
- It is a small 1.5B parameter model and may make mistakes on very complex and long code generation tasks.
- It was trained only on Python-focused datasets; performance in other languages is limited.
- The training data has a maximum length of 256 tokens; consistency may degrade in very long contexts.
- Generated code may not always be correct or safe. Review it before running.
- It may contain known limitations inherited from the training data regarding bias and harmful content.
## Intended Usage Tips
- It performs best on single-line and medium-complexity Python functions.
- Lower the `temperature` value if you want stable output for code generation.
- Since the model was trained in a completion format, the `### Instruction:` / `### Answer:` template yields the highest quality output.
- For batched inference, remember to set `tokenizer.pad_token = tokenizer.eos_token`.
## License
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.
## Resources
- Base Model: [Qwen/Qwen2.5-1.5B](https://huggingface.co/Qwen/Qwen2.5-1.5B)
- Training Library: [TRL](https://github.com/huggingface/trl)
- Dataset 1: [HuggingFaceH4/CodeAlpaca_20K](https://huggingface.co/datasets/HuggingFaceH4/CodeAlpaca_20K)
- Dataset 2: [iamtarun/python_code_instructions_18k_alpaca](https://huggingface.co/datasets/iamtarun/python_code_instructions_18k_alpaca) |