Instructions to use mastersubhajit/DPO with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use mastersubhajit/DPO with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-1.5B-Instruct") model = PeftModel.from_pretrained(base_model, "mastersubhajit/DPO") - Notebooks
- Google Colab
- Kaggle
README
Browse files
README.md
CHANGED
|
@@ -1,3 +1,91 @@
|
|
| 1 |
-
---
|
| 2 |
-
license:
|
| 3 |
-
--
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: Qwen/Qwen2.5-1.5B-Instruct
|
| 4 |
+
tags:
|
| 5 |
+
- dpo
|
| 6 |
+
- alignment
|
| 7 |
+
- truthfulness
|
| 8 |
+
- lora
|
| 9 |
+
- peft
|
| 10 |
+
- qwen2
|
| 11 |
+
datasets:
|
| 12 |
+
- jondurbin/truthy-dpo-v0.1
|
| 13 |
+
pipeline_tag: text-generation
|
| 14 |
+
library_name: peft
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Qwen2.5-1.5B-Instruct — DPO Fine-tuned for Truthfulness
|
| 18 |
+
|
| 19 |
+
This is a LoRA adapter for [Qwen/Qwen2.5-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct), fine-tuned using Direct Preference Optimization (DPO) to reduce hallucinations and improve factual accuracy.
|
| 20 |
+
|
| 21 |
+
I trained this as part of my NLU course assignment (A5) at AIT, where the goal was to align a language model to prefer truthful responses over hallucinated ones.
|
| 22 |
+
|
| 23 |
+
## What does this model do differently?
|
| 24 |
+
|
| 25 |
+
The base Qwen2.5-1.5B-Instruct model occasionally generates plausible-sounding but incorrect answers. By training with DPO on the [truthy-dpo](https://huggingface.co/datasets/jondurbin/truthy-dpo-v0.1) dataset, this adapter nudges the model toward choosing factually grounded responses instead of making things up.
|
| 26 |
+
|
| 27 |
+
It's not a massive overhaul — it's a lightweight LoRA adapter that adjusts the attention layers to be slightly more cautious and accurate.
|
| 28 |
+
|
| 29 |
+
## Training Details
|
| 30 |
+
|
| 31 |
+
| Parameter | Value |
|
| 32 |
+
|-----------|-------|
|
| 33 |
+
| Base model | Qwen/Qwen2.5-1.5B-Instruct |
|
| 34 |
+
| Training method | DPO (Direct Preference Optimization) |
|
| 35 |
+
| Dataset | jondurbin/truthy-dpo-v0.1 (1016 samples) |
|
| 36 |
+
| Adapter type | LoRA (rank=8, alpha=16) |
|
| 37 |
+
| Target modules | q_proj, k_proj, v_proj, o_proj |
|
| 38 |
+
| Trainable params | ~2.18M (0.14% of total) |
|
| 39 |
+
| Learning rate | 1e-4 |
|
| 40 |
+
| Beta (DPO) | 0.3 |
|
| 41 |
+
| Training steps | 50 |
|
| 42 |
+
| Batch size | 1 (with gradient accumulation = 4) |
|
| 43 |
+
| Precision | float32 |
|
| 44 |
+
| Hardware | Apple M2 (MPS) |
|
| 45 |
+
|
| 46 |
+
I ran two experiments — one with a conservative setup (beta=0.1, lr=5e-5) and another with stronger preference signal (beta=0.3, lr=1e-4). The second experiment showed better loss reduction, so that's what I saved here.
|
| 47 |
+
|
| 48 |
+
## How to Use
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 52 |
+
from peft import PeftModel
|
| 53 |
+
|
| 54 |
+
# load base model
|
| 55 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 56 |
+
"Qwen/Qwen2.5-1.5B-Instruct",
|
| 57 |
+
torch_dtype="auto",
|
| 58 |
+
trust_remote_code=True,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
# load the DPO adapter on top
|
| 62 |
+
model = PeftModel.from_pretrained(base_model, "mastersubhajit/DPO")
|
| 63 |
+
model = model.merge_and_unload()
|
| 64 |
+
|
| 65 |
+
tokenizer = AutoTokenizer.from_pretrained("mastersubhajit/DPO")
|
| 66 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 67 |
+
|
| 68 |
+
response = pipe("What is the capital of France?", max_new_tokens=256, do_sample=False)
|
| 69 |
+
print(response[0]["generated_text"])
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
## Evaluation
|
| 73 |
+
|
| 74 |
+
I evaluated this model using AlpacaEval with an LLM-as-a-Judge setup. I took 15 random samples from the `helpful_base` subset and had both the base model and this DPO model generate responses. Then I used Llama 3.3 70B (via Groq) as a judge to compare them.
|
| 75 |
+
|
| 76 |
+
**DPO Win Rate: ~60%**
|
| 77 |
+
|
| 78 |
+
The DPO model won more comparisons than the base model, especially on factual and knowledge-based questions. On creative or open-ended prompts the difference was smaller, which makes sense since the training data specifically targets hallucination reduction rather than general helpfulness.
|
| 79 |
+
|
| 80 |
+
## Limitations
|
| 81 |
+
|
| 82 |
+
- This is a LoRA adapter, not a full fine-tune. The changes are subtle.
|
| 83 |
+
- Trained for only 50 steps due to hardware constraints (M2 Mac). More training would likely help.
|
| 84 |
+
- The truthy-dpo dataset focuses on a specific kind of truthfulness — the model won't suddenly become perfect at everything.
|
| 85 |
+
- float32 training (MPS doesn't fully support fp16 for all ops), so training was slower than it would be on a GPU with fp16/bf16.
|
| 86 |
+
|
| 87 |
+
## Acknowledgements
|
| 88 |
+
|
| 89 |
+
- Base model by [Qwen Team](https://huggingface.co/Qwen)
|
| 90 |
+
- Training dataset by [Jon Durbin](https://huggingface.co/jondurbin)
|
| 91 |
+
- Built using [TRL](https://huggingface.co/docs/trl) and [PEFT](https://huggingface.co/docs/peft) libraries
|