Text Generation
Transformers
Safetensors
English
qwen2
qwen2.5
qwen
code-generation
python
python-code-generation
dpo
direct-preference-optimization
preference-learning
lora
parameter-efficient-fine-tuning
conversational
text-generation-inference
Instructions to use ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B") model = AutoModelForCausalLM.from_pretrained("ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B", 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B
- SGLang
How to use ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B 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 "ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B" \ --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": "ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B", "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 "ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B" \ --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": "ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B with Docker Model Runner:
docker model run hf.co/ranjanrajib/DPO-trained-Qwen2.5-Python-Coder-7B
Update README.md
Browse files
README.md
CHANGED
|
@@ -87,17 +87,17 @@ was fine-tuned using:
|
|
| 87 |
|
| 88 |
The resulting model demonstrates improved coding performance on the evaluated held-out benchmark:
|
| 89 |
|
| 90 |
-
| Metric
|
| 91 |
|
| 92 |
| ----------------------- | ------------------------: | ---------: | -----------: |
|
| 93 |
|
| 94 |
-
| Pass@1
|
| 95 |
|
| 96 |
-
| Pass@5
|
| 97 |
|
| 98 |
-
| Pass@10
|
| 99 |
|
| 100 |
-
| Tests passed per answer |
|
| 101 |
|
| 102 |
The primary result is the improvement in ****Pass@1****, meaning that a single generated solution was more likely to produce a correct solution on the evaluated programming problems.
|
| 103 |
|
|
@@ -176,7 +176,7 @@ model = PeftModel.from_pretrained(
|
|
| 176 |
The base model and the merged trained model use the same VRAM. The merge changes weight values, not tensor shapes: both models have the same 7.6B parameters and architecture, so the model weights occupy the same amount of bf16 memory.
|
| 177 |
|
| 178 |
| Component | bf16 VRAM |
|
| 179 |
-
|---|---:|
|
| 180 |
| Weights (base or merged D4) | 14.19 GiB |
|
| 181 |
| KV cache, per token | 56 KiB |
|
| 182 |
| Activations / workspace | ~0.5β1 GiB |
|
|
@@ -308,15 +308,15 @@ The model was evaluated against the original Qwen2.5-Coder-7B-Instruct using a c
|
|
| 308 |
|
| 309 |
The same prompts, generation settings, random seeds, number of samples, and grading procedure were used for both models.
|
| 310 |
## Pass@k
|
| 311 |
-
| Metric
|
| 312 |
|
| 313 |
| ------- | ---------: | ---------: |
|
| 314 |
|
| 315 |
-
| Pass@1
|
| 316 |
|
| 317 |
-
| Pass@5
|
| 318 |
|
| 319 |
-
| Pass@10 |
|
| 320 |
|
| 321 |
The improvement in Pass@1 is approximately ****3.35 percentage points****.
|
| 322 |
## Partial Correctness
|
|
@@ -332,17 +332,17 @@ The evaluation used the same 508 problems for both models, allowing direct compa
|
|
| 332 |
|
| 333 |
For the first generated answer:
|
| 334 |
|
| 335 |
-
| Base β DPO
|
| 336 |
|
| 337 |
| --------------------- | -------: |
|
| 338 |
|
| 339 |
-
| Correct β Correct
|
| 340 |
|
| 341 |
-
| Correct β Incorrect
|
| 342 |
|
| 343 |
-
| Incorrect β Correct
|
| 344 |
|
| 345 |
-
| Incorrect β Incorrect |
|
| 346 |
|
| 347 |
The DPO model converted 41 problems from incorrect to correct while 17 previously correct problems became incorrect.
|
| 348 |
|
|
@@ -474,15 +474,15 @@ It was constructed from programming problems drawn from:
|
|
| 474 |
|
| 475 |
* handwritten programming problems
|
| 476 |
### Training Data
|
| 477 |
-
| Dataset
|
| 478 |
|
| 479 |
| ------------ | ---------- |
|
| 480 |
|
| 481 |
| BigCodeBench | Apache 2.0 |
|
| 482 |
|
| 483 |
-
| MBPP
|
| 484 |
|
| 485 |
-
| HumanEval
|
| 486 |
|
| 487 |
Candidate solutions were generated automatically.
|
| 488 |
|
|
@@ -531,11 +531,11 @@ The preference signal was generated from objective unit-test execution.
|
|
| 531 |
The primary DPO configuration was:
|
| 532 |
|
| 533 |
| Parameter | Value |
|
| 534 |
-
|---|---
|
| 535 |
-
|
|
| 536 |
-
|
|
| 537 |
-
|
|
| 538 |
-
|
|
| 539 |
| Epochs | 2 |
|
| 540 |
| Maximum sequence length | 1,024 |
|
| 541 |
| Batch size | 4 |
|
|
@@ -546,7 +546,7 @@ The primary DPO configuration was:
|
|
| 546 |
| Gradient checkpointing | Enabled |
|
| 547 |
## LoRA Configuration
|
| 548 |
| Parameter | Value |
|
| 549 |
-
|---|---|
|
| 550 |
| Rank | 32 |
|
| 551 |
| Alpha | 64 |
|
| 552 |
| Dropout | 0.05 |
|
|
@@ -602,13 +602,13 @@ The DPO training objective produced a strong preference signal on the training e
|
|
| 602 |
|
| 603 |
However, the validation results were substantially weaker.
|
| 604 |
|
| 605 |
-
| Metric
|
| 606 |
|
| 607 |
| ------------------- | -------: | --------------------: |
|
| 608 |
|
| 609 |
-
| Preference accuracy |
|
| 610 |
|
| 611 |
-
| Reward margin
|
| 612 |
|
| 613 |
This indicates that the explicit preference signal learned during training did not generalize strongly to the validation preference examples.
|
| 614 |
|
|
|
|
| 87 |
|
| 88 |
The resulting model demonstrates improved coding performance on the evaluated held-out benchmark:
|
| 89 |
|
| 90 |
+
| Metric | Qwen2.5-Coder-7B-Instruct | DPO Model | Improvement |
|
| 91 |
|
| 92 |
| ----------------------- | ------------------------: | ---------: | -----------: |
|
| 93 |
|
| 94 |
+
| Pass@1 | 41.87% | ****45.22%**** | ****+3.35 pp**** |
|
| 95 |
|
| 96 |
+
| Pass@5 | 48.87% | ****51.10%**** | ****+2.23 pp**** |
|
| 97 |
|
| 98 |
+
| Pass@10 | 50.99% | ****53.16%**** | ****+2.17 pp**** |
|
| 99 |
|
| 100 |
+
| Tests passed per answer | 66.20% | ****69.41%**** | ****+3.21 pp**** |
|
| 101 |
|
| 102 |
The primary result is the improvement in ****Pass@1****, meaning that a single generated solution was more likely to produce a correct solution on the evaluated programming problems.
|
| 103 |
|
|
|
|
| 176 |
The base model and the merged trained model use the same VRAM. The merge changes weight values, not tensor shapes: both models have the same 7.6B parameters and architecture, so the model weights occupy the same amount of bf16 memory.
|
| 177 |
|
| 178 |
| Component | bf16 VRAM |
|
| 179 |
+
| --- | ---: |
|
| 180 |
| Weights (base or merged D4) | 14.19 GiB |
|
| 181 |
| KV cache, per token | 56 KiB |
|
| 182 |
| Activations / workspace | ~0.5β1 GiB |
|
|
|
|
| 308 |
|
| 309 |
The same prompts, generation settings, random seeds, number of samples, and grading procedure were used for both models.
|
| 310 |
## Pass@k
|
| 311 |
+
| Metric | Base Model | DPO Model |
|
| 312 |
|
| 313 |
| ------- | ---------: | ---------: |
|
| 314 |
|
| 315 |
+
| Pass@1 | 41.87% | ****45.22%**** |
|
| 316 |
|
| 317 |
+
| Pass@5 | 48.87% | ****51.10%**** |
|
| 318 |
|
| 319 |
+
| Pass@10 | 50.99% | ****53.16%**** |
|
| 320 |
|
| 321 |
The improvement in Pass@1 is approximately ****3.35 percentage points****.
|
| 322 |
## Partial Correctness
|
|
|
|
| 332 |
|
| 333 |
For the first generated answer:
|
| 334 |
|
| 335 |
+
| Base β DPO | Problems |
|
| 336 |
|
| 337 |
| --------------------- | -------: |
|
| 338 |
|
| 339 |
+
| Correct β Correct | 186 |
|
| 340 |
|
| 341 |
+
| Correct β Incorrect | 17 |
|
| 342 |
|
| 343 |
+
| Incorrect β Correct | 41 |
|
| 344 |
|
| 345 |
+
| Incorrect β Incorrect | 264 |
|
| 346 |
|
| 347 |
The DPO model converted 41 problems from incorrect to correct while 17 previously correct problems became incorrect.
|
| 348 |
|
|
|
|
| 474 |
|
| 475 |
* handwritten programming problems
|
| 476 |
### Training Data
|
| 477 |
+
| Dataset | License |
|
| 478 |
|
| 479 |
| ------------ | ---------- |
|
| 480 |
|
| 481 |
| BigCodeBench | Apache 2.0 |
|
| 482 |
|
| 483 |
+
| MBPP | CC BY 4.0 |
|
| 484 |
|
| 485 |
+
| HumanEval | MIT |
|
| 486 |
|
| 487 |
Candidate solutions were generated automatically.
|
| 488 |
|
|
|
|
| 531 |
The primary DPO configuration was:
|
| 532 |
|
| 533 |
| Parameter | Value |
|
| 534 |
+
| --- | --- |
|
| 535 |
+
| Rank | 32 |
|
| 536 |
+
| Alpha | 64 |
|
| 537 |
+
| Dropout | 0.05 |
|
| 538 |
+
| Target modules | Attention and MLP projections |
|
| 539 |
| Epochs | 2 |
|
| 540 |
| Maximum sequence length | 1,024 |
|
| 541 |
| Batch size | 4 |
|
|
|
|
| 546 |
| Gradient checkpointing | Enabled |
|
| 547 |
## LoRA Configuration
|
| 548 |
| Parameter | Value |
|
| 549 |
+
| --- | --- |
|
| 550 |
| Rank | 32 |
|
| 551 |
| Alpha | 64 |
|
| 552 |
| Dropout | 0.05 |
|
|
|
|
| 602 |
|
| 603 |
However, the validation results were substantially weaker.
|
| 604 |
|
| 605 |
+
| Metric | Training | Validation |
|
| 606 |
|
| 607 |
| ------------------- | -------: | --------------------: |
|
| 608 |
|
| 609 |
+
| Preference accuracy | ~84.4% | ~45.8% |
|
| 610 |
|
| 611 |
+
| Reward margin | Positive | Approximately neutral |
|
| 612 |
|
| 613 |
This indicates that the explicit preference signal learned during training did not generalize strongly to the validation preference examples.
|
| 614 |
|