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
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -20,6 +20,56 @@ attempts, where some samples passed a problem's tests and others failed.
|
|
| 20 |
**Base model:** `Qwen/Qwen2.5-Coder-7B-Instruct` at snapshot
|
| 21 |
`c03e6d358207e414f1eca0bb1891e29f1db0e242`. The merge was performed against exactly these weights.
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
## What was measured, and what it does and does not show
|
| 24 |
|
| 25 |
On `python_eval_v3` — 508 BigCodeBench problems held out of training, 10 samples per problem at
|
|
|
|
| 20 |
**Base model:** `Qwen/Qwen2.5-Coder-7B-Instruct` at snapshot
|
| 21 |
`c03e6d358207e414f1eca0bb1891e29f1db0e242`. The merge was performed against exactly these weights.
|
| 22 |
|
| 23 |
+
## Downloading and using
|
| 24 |
+
|
| 25 |
+
### The merged model (what most people want)
|
| 26 |
+
|
| 27 |
+
```python
|
| 28 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 29 |
+
|
| 30 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 31 |
+
"ranjanrajib/DPO-trained-Qwen2.5-Coder-7B", dtype="bfloat16", device_map="auto")
|
| 32 |
+
tok = AutoTokenizer.from_pretrained("ranjanrajib/DPO-trained-Qwen2.5-Coder-7B")
|
| 33 |
+
|
| 34 |
+
msgs = [{"role": "user", "content": "Write a Python function that merges overlapping intervals."}]
|
| 35 |
+
text = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True)
|
| 36 |
+
out = model.generate(**tok(text, return_tensors="pt").to(model.device), max_new_tokens=512)
|
| 37 |
+
print(tok.decode(out[0], skip_special_tokens=True))
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
Or fetch the files without loading them (~14 GB, four shards):
|
| 41 |
+
|
| 42 |
+
```bash
|
| 43 |
+
hf download ranjanrajib/DPO-trained-Qwen2.5-Coder-7B --exclude "adapter/*" --local-dir ./d4
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
### The LoRA adapter only (308 MB)
|
| 47 |
+
|
| 48 |
+
The adapter lives in `adapter/`. Applying it to the base model gives the same result as the
|
| 49 |
+
merged weights, at a fraction of the download.
|
| 50 |
+
|
| 51 |
+
```bash
|
| 52 |
+
hf download ranjanrajib/DPO-trained-Qwen2.5-Coder-7B --include "adapter/*" --local-dir ./d4-lora
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
```python
|
| 56 |
+
import torch
|
| 57 |
+
from peft import PeftModel
|
| 58 |
+
from transformers import AutoModelForCausalLM
|
| 59 |
+
|
| 60 |
+
BASE = "Qwen/Qwen2.5-Coder-7B-Instruct"
|
| 61 |
+
REVISION = "c03e6d358207e414f1eca0bb1891e29f1db0e242" # the snapshot this was trained against
|
| 62 |
+
|
| 63 |
+
base = AutoModelForCausalLM.from_pretrained(
|
| 64 |
+
BASE, revision=REVISION, dtype=torch.bfloat16, device_map="auto")
|
| 65 |
+
model = PeftModel.from_pretrained(
|
| 66 |
+
base, "ranjanrajib/DPO-trained-Qwen2.5-Coder-7B", subfolder="adapter")
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
**Pin the revision.** The adapter's own config does not record one, so omitting `revision`
|
| 70 |
+
silently applies it to whatever `main` points at. Today that is the same snapshot; it will not
|
| 71 |
+
stay true forever, and an adapter applied to different base weights is not this model.
|
| 72 |
+
|
| 73 |
## What was measured, and what it does and does not show
|
| 74 |
|
| 75 |
On `python_eval_v3` — 508 BigCodeBench problems held out of training, 10 samples per problem at
|