Text Generation
Transformers
Safetensors
English
qwen2.5-coder
code-generation
code-modernization
python
fine-tuned
merged-model
conversational
Instructions to use Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter
- SGLang
How to use Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter 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 "Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter" \ --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": "Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter", "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 "Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter" \ --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": "Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter with Docker Model Runner:
docker model run hf.co/Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter
File size: 13,328 Bytes
cc62ef0 b0ce2be cc62ef0 deaabff b0ce2be cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 deaabff cc62ef0 b0ce2be | 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 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | ---
license: apache-2.0
language:
- en
base_model:
- Qwen/Qwen2.5-Coder-1.5B-Instruct
pipeline_tag: text-generation
library_name: transformers
tags:
- qwen2.5-coder
- code-generation
- code-modernization
- python
- fine-tuned
- merged-model
metrics:
- loss
- accuracy
---
# Model Card for Qwen2.5-Coder-1.5B Python 3.14 QLoRA Adapter
## Model Details
### Model Description
This model is a LoRA adapter fine-tuned on top of `Qwen/Qwen2.5-Coder-1.5B-Instruct` for Python code modernization, with a focus on updating Python code toward Python 3.14-compatible syntax and practices.
The adapter was trained using QLoRA with 4-bit NF4 quantization of the frozen base model and LoRA-based parameter-efficient fine-tuning.
- **Base model:** `Qwen/Qwen2.5-Coder-1.5B-Instruct`
- **Model type:** LoRA / QLoRA adapter
- **Task:** Python code modernization
- **Primary target:** Python 3.14 modernization
- **Quantization:** 4-bit NF4
- **Nested quantization:** Enabled
- **Compute dtype:** FP16
### Model Sources
- **Base model:** `Qwen/Qwen2.5-Coder-1.5B-Instruct`
- **Adapter repository:** `Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter`
## Uses
### Direct Use
This adapter is intended to be used with the base Qwen2.5-Coder-1.5B-Instruct model to modernize Python source code toward Python 3.14.
Potential applications include:
- Modernizing legacy Python syntax
- Updating Python code to newer language features
- Refactoring older Python implementations
- Assisting developers with Python version migration
- Generating modernized Python code from older implementations
### Downstream Use
The adapter can be integrated into developer tools, code migration pipelines, educational tools, and automated code modernization workflows.
It can also be merged with the base model to create a standalone fine-tuned model.
### Out-of-Scope Use
This model is not intended to:
- Guarantee that generated code is fully compatible with every Python 3.14 environment
- Replace automated testing or human code review
- Perform security-critical code migration without validation
- Generate production-ready software without testing
- Serve as a general-purpose replacement for the original Qwen2.5-Coder model
Generated code should always be validated, tested, and reviewed before production use.
## Bias, Risks, and Limitations
The model inherits limitations from the underlying Qwen2.5-Coder model and from the fine-tuning dataset.
The model may:
- Produce syntactically incorrect code in some situations
- Introduce behavioral changes during modernization
- Apply an inappropriate modernization depending on the context
- Fail to preserve edge-case behavior
- Generate code that appears valid but requires additional testing
- Reflect biases or limitations present in the base model and training data
### Recommendations
Generated code should be:
1. Reviewed by a developer.
2. Parsed or compiled using the target Python version.
3. Tested against the original implementation's expected behavior.
4. Validated with appropriate unit and integration tests.
## How to Get Started with the Model
The adapter can be loaded together with the base model using PEFT and BitsAndBytes.
```python
import torch
from transformers import (
AutoModelForCausalLM,
AutoTokenizer,
BitsAndBytesConfig,
)
from peft import PeftModel
BASE_MODEL = "Qwen/Qwen2.5-Coder-1.5B-Instruct"
ADAPTER_MODEL = "Krishnasri2027/qwen25-coder-1.5b-python3147-nf4-adapter"
tokenizer = AutoTokenizer.from_pretrained(
ADAPTER_MODEL,
trust_remote_code=True,
)
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype=torch.float16,
)
base_model = AutoModelForCausalLM.from_pretrained(
BASE_MODEL,
quantization_config=bnb_config,
torch_dtype=torch.float16,
device_map="auto",
trust_remote_code=True,
)
model = PeftModel.from_pretrained(
base_model,
ADAPTER_MODEL,
is_trainable=False,
)
model.eval()
messages = [
{
"role": "user",
"content": "Modernize the following Python code for Python 3.14:\n\n<your Python code here>",
}
]
inputs = tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_tensors="pt",
).to(model.device)
with torch.no_grad():
outputs = model.generate(
inputs,
max_new_tokens=512,
temperature=0.2,
do_sample=False,
)
response = tokenizer.decode(
outputs[0][inputs.shape[-1]:],
skip_special_tokens=True,
)
print(response)
```
## Training Details
### Training Data
The model was fine-tuned using a chat-formatted training dataset designed for Python code modernization.
The training examples were tokenized using the Qwen2.5-Coder tokenizer and its chat template.
The configured sequence length was **256 tokens**.
Token-length analysis of the training examples produced:
| Statistic | Tokens |
|---|---:|
| Minimum | 115 |
| Maximum | 197 |
| Mean | 150.792 |
| Median | 147 |
| 95th percentile | 187 |
| 99th percentile | 197 |
| Configured sequence length | 256 |
The maximum observed sequence length of 197 tokens was below the configured 256-token sequence length, providing approximately 59 tokens of headroom.
### Training Procedure
The model was trained using **QLoRA**, keeping the quantized base model frozen while training a small set of LoRA adapter parameters.
The base model was quantized to 4-bit NF4 using BitsAndBytes with nested/double quantization.
LoRA adapters were applied to:
- `q_proj`
- `k_proj`
- `v_proj`
- `o_proj`
- `gate_proj`
- `up_proj`
- `down_proj`
#### Training Hyperparameters
| Parameter | Value |
|---|---:|
| Base model | Qwen/Qwen2.5-Coder-1.5B-Instruct |
| Fine-tuning method | QLoRA |
| Quantization | 4-bit NF4 |
| Nested quantization | Enabled |
| Compute dtype | FP16 |
| LoRA rank (`r`) | 16 |
| LoRA alpha | 32 |
| LoRA dropout | 0.05 |
| Batch size | 1 |
| Gradient accumulation steps | 8 |
| Effective batch size | 8 |
| Number of epochs | 4 |
| Learning rate | 1e-4 |
| LR scheduler | Cosine |
| Weight decay | 0.01 |
| Warmup steps | 30 |
| Evaluation frequency | Every 50 steps |
| Checkpoint save frequency | Every 50 steps |
| Logging frequency | Every 10 steps |
| Maximum sequence length | 256 |
| Gradient checkpointing | Enabled |
| FIM rate | 0.0 |
| FIM SPM rate | 0.0 |
| Random seed | 42 |
| FP16 | Enabled |
| BF16 | Disabled |
### Speeds, Sizes, Times
The completed training run reported:
| Metric | Value |
|---|---:|
| Global steps | 500 |
| Epochs | 4 |
| Training runtime | 3342.5477 seconds |
| Training runtime | ~55 minutes 43 seconds |
| Training samples / second | 1.197 |
| Training steps / second | 0.150 |
| Total FLOPs | 4,835,834,903,592,960 |
| Total tokens processed | 607,168 |
| Final logged training loss | 0.037346 |
| Aggregate Trainer training loss | 0.2003363176 |
The `training_loss` value reported by `Trainer` (`0.2003363176`) represents the aggregate training loss reported for the complete run, whereas the training loss shown at step 500 (`0.037346`) is the most recent logged training loss.
## Evaluation
### Testing Data, Factors & Metrics
#### Testing Data
The evaluation dataset was held separately from the training data and was used to calculate validation loss during training.
Validation was performed every 50 training steps.
#### Factors
The primary evaluation objective was to determine whether the model could learn the expected Python modernization patterns while reducing validation loss throughout training.
The evaluation results below are the validation losses recorded during the training run.
#### Metrics
The primary reported metrics are:
- Training loss
- Validation loss
- Entropy
- Mean token accuracy
- Number of processed tokens
### Results
#### Summary
The model showed a substantial reduction in both training and validation loss during fine-tuning.
Validation loss decreased from **0.252825 at step 50** to **0.037586 at step 500**.
This represents an approximately **85.1% reduction in validation loss** over the recorded training run.
The final reported mean token accuracy was **98.6229%** at step 500.
The validation loss continued to decrease throughout the later checkpoints, reaching its lowest recorded value of **0.037586 at step 500**.
| Step | Training Loss | Validation Loss | Entropy | Mean Token Accuracy | Num Tokens |
|---:|---:|---:|---:|---:|---:|
| 50 | 0.329822 | 0.252825 | 0.280223 | 0.939414 | 60,652 |
| 100 | 0.070807 | 0.064497 | 0.067091 | 0.981024 | 121,228 |
| 150 | 0.043590 | 0.048881 | 0.047465 | 0.984845 | 182,259 |
| 200 | 0.040075 | 0.042402 | 0.043094 | 0.985729 | 242,627 |
| 250 | 0.038932 | 0.040337 | 0.044742 | 0.985716 | 303,584 |
| 300 | 0.037993 | 0.038709 | 0.041848 | 0.985923 | 364,412 |
| 350 | 0.037793 | 0.038682 | 0.041355 | 0.986143 | 424,864 |
| 400 | 0.038162 | 0.038088 | 0.039560 | 0.986307 | 485,911 |
| 450 | 0.040015 | 0.037656 | 0.041152 | 0.986229 | 546,449 |
| 500 | 0.037346 | **0.037586** | 0.040890 | **0.986229** | 607,168 |
The final training output was:
```text
TrainOutput(
global_step=500,
training_loss=0.20033631759881973,
epoch=4.0
)
```
with the following reported training metrics:
```text
train_runtime: 3342.5477
train_samples_per_second: 1.197
train_steps_per_second: 0.15
total_flos: 4835834903592960.0
train_loss: 0.20033631759881973
epoch: 4.0
```
These results indicate that the model successfully optimized the training objective and achieved high token-level accuracy on the evaluation data.
However, token-level accuracy and validation loss should not be interpreted as a guarantee that every generated modernization preserves the original program's behavior. Functional testing remains necessary.
## Model Examination
The model should be examined primarily through qualitative code-generation and modernization tests.
Recommended examination procedures include:
- Comparing legacy and modernized Python implementations.
- Checking generated code with the Python 3.14 interpreter.
- Running unit tests before and after modernization.
- Checking whether program behavior is preserved.
- Testing edge cases and uncommon Python constructs.
- Evaluating whether deprecated or legacy syntax is correctly modernized.
No additional qualitative examination results are reported in this model card unless separately documented.
## Environmental Impact
The training run required approximately **55 minutes and 43 seconds** of compute time.
No verified carbon-emissions measurement was recorded for this training run, so a specific carbon footprint is not reported.
## Technical Specifications
### Model Architecture and Objective
The underlying architecture is based on Qwen2.5-Coder-1.5B-Instruct.
The fine-tuning objective uses supervised instruction tuning with LoRA adapters.
QLoRA was used to reduce the memory requirements of fine-tuning by quantizing the frozen base model to 4-bit NF4 while keeping the trainable LoRA parameters separate.
The LoRA configuration was:
```text
r = 16
alpha = 32
dropout = 0.05
```
Target modules:
```text
q_proj
k_proj
v_proj
o_proj
gate_proj
up_proj
down_proj
```
The adapter contains only the learned parameter-efficient fine-tuning weights and does not contain a standalone copy of the base model.
### Compute Infrastructure
#### Hardware
Training was performed using an NVIDIA Tesla T4 GPU environment.
#### Software
| Component | Version |
|---|---|
| Python | 3.13 |
| PyTorch | 2.11.0+cu128 |
| CUDA | 12.8 |
| Transformers | 5.16.1 |
| TRL | 1.12.0 |
| PEFT | 0.20.0 |
| Accelerate | 1.14.0 |
| BitsAndBytes | 0.50.2 |
## Citation
If you use this adapter, please also cite the underlying Qwen2.5-Coder model according to the citation information provided by its authors.
## Glossary
**LoRA**
Low-Rank Adaptation, a parameter-efficient fine-tuning method that trains small low-rank matrices instead of updating the entire model.
**QLoRA**
Quantized LoRA fine-tuning, where the frozen base model is loaded in low-bit precision while LoRA parameters are trained.
**NF4**
NormalFloat 4-bit, a 4-bit quantization data type designed for normally distributed neural-network weights.
**Nested Quantization / Double Quantization**
A technique that further quantizes the quantization constants to reduce memory usage.
**FP16**
16-bit floating-point representation used for computation during training and inference.
**Mean Token Accuracy**
The proportion of target tokens correctly predicted by the model during evaluation.
**Validation Loss**
The loss calculated on the held-out evaluation dataset.
## More Information
This adapter is specifically intended for Python code modernization toward Python 3.14.
For deployment scenarios with limited GPU memory, the adapter can be loaded with the base model using 4-bit NF4 quantization.
For standalone deployment, the LoRA adapter can also be merged into the base model and subsequently quantized using an appropriate deployment format.
## Model Card Authors
Krishnasri2027
## Model Card Contact
For questions, issues, or suggestions regarding this model, please use the discussion and issue facilities available on the model repository. |