Text Generation
PEFT
Safetensors
English
text-to-sql
sql
code-generation
bird
bird-sql
spider
dpo
qwen
qwen2.5
conversational
Instructions to use jk200201/qwen2.5-coder-7b-bird-dpo with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use jk200201/qwen2.5-coder-7b-bird-dpo with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-Coder-7B-Instruct") model = PeftModel.from_pretrained(base_model, "jk200201/qwen2.5-coder-7b-bird-dpo") - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,209 +1,148 @@
|
|
| 1 |
---
|
|
|
|
| 2 |
base_model: Qwen/Qwen2.5-Coder-7B-Instruct
|
| 3 |
library_name: peft
|
| 4 |
-
pipeline_tag: text-generation
|
| 5 |
tags:
|
| 6 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
- dpo
|
| 8 |
-
-
|
| 9 |
-
-
|
| 10 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
## Model Details
|
| 20 |
-
|
| 21 |
-
### Model Description
|
| 22 |
-
|
| 23 |
-
<!-- Provide a longer summary of what this model is. -->
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
- **Developed by:** [More Information Needed]
|
| 28 |
-
- **Funded by [optional]:** [More Information Needed]
|
| 29 |
-
- **Shared by [optional]:** [More Information Needed]
|
| 30 |
-
- **Model type:** [More Information Needed]
|
| 31 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 32 |
-
- **License:** [More Information Needed]
|
| 33 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 34 |
-
|
| 35 |
-
### Model Sources [optional]
|
| 36 |
-
|
| 37 |
-
<!-- Provide the basic links for the model. -->
|
| 38 |
-
|
| 39 |
-
- **Repository:** [More Information Needed]
|
| 40 |
-
- **Paper [optional]:** [More Information Needed]
|
| 41 |
-
- **Demo [optional]:** [More Information Needed]
|
| 42 |
-
|
| 43 |
-
## Uses
|
| 44 |
-
|
| 45 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 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 |
## Training Details
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 88 |
-
|
| 89 |
-
[More Information Needed]
|
| 90 |
-
|
| 91 |
-
### Training Procedure
|
| 92 |
-
|
| 93 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 94 |
-
|
| 95 |
-
#### Preprocessing [optional]
|
| 96 |
-
|
| 97 |
-
[More Information Needed]
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
#### Training Hyperparameters
|
| 101 |
-
|
| 102 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 103 |
-
|
| 104 |
-
#### Speeds, Sizes, Times [optional]
|
| 105 |
-
|
| 106 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
| 107 |
-
|
| 108 |
-
[More Information Needed]
|
| 109 |
-
|
| 110 |
-
## Evaluation
|
| 111 |
-
|
| 112 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 113 |
-
|
| 114 |
-
### Testing Data, Factors & Metrics
|
| 115 |
-
|
| 116 |
-
#### Testing Data
|
| 117 |
-
|
| 118 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 119 |
-
|
| 120 |
-
[More Information Needed]
|
| 121 |
-
|
| 122 |
-
#### Factors
|
| 123 |
-
|
| 124 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
| 125 |
-
|
| 126 |
-
[More Information Needed]
|
| 127 |
-
|
| 128 |
-
#### Metrics
|
| 129 |
-
|
| 130 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 131 |
-
|
| 132 |
-
[More Information Needed]
|
| 133 |
-
|
| 134 |
-
### Results
|
| 135 |
-
|
| 136 |
-
[More Information Needed]
|
| 137 |
-
|
| 138 |
-
#### Summary
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
## Model Examination [optional]
|
| 143 |
-
|
| 144 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 145 |
-
|
| 146 |
-
[More Information Needed]
|
| 147 |
-
|
| 148 |
-
## Environmental Impact
|
| 149 |
-
|
| 150 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 151 |
-
|
| 152 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 153 |
-
|
| 154 |
-
- **Hardware Type:** [More Information Needed]
|
| 155 |
-
- **Hours used:** [More Information Needed]
|
| 156 |
-
- **Cloud Provider:** [More Information Needed]
|
| 157 |
-
- **Compute Region:** [More Information Needed]
|
| 158 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 159 |
-
|
| 160 |
-
## Technical Specifications [optional]
|
| 161 |
-
|
| 162 |
-
### Model Architecture and Objective
|
| 163 |
-
|
| 164 |
-
[More Information Needed]
|
| 165 |
-
|
| 166 |
-
### Compute Infrastructure
|
| 167 |
-
|
| 168 |
-
[More Information Needed]
|
| 169 |
-
|
| 170 |
-
#### Hardware
|
| 171 |
-
|
| 172 |
-
[More Information Needed]
|
| 173 |
-
|
| 174 |
-
#### Software
|
| 175 |
-
|
| 176 |
-
[More Information Needed]
|
| 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 |
-
### Framework versions
|
| 208 |
|
| 209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
base_model: Qwen/Qwen2.5-Coder-7B-Instruct
|
| 4 |
library_name: peft
|
|
|
|
| 5 |
tags:
|
| 6 |
+
- text-to-sql
|
| 7 |
+
- sql
|
| 8 |
+
- code-generation
|
| 9 |
+
- bird
|
| 10 |
+
- bird-sql
|
| 11 |
+
- spider
|
| 12 |
- dpo
|
| 13 |
+
- qwen
|
| 14 |
+
- qwen2.5
|
| 15 |
+
- text-generation
|
| 16 |
+
language:
|
| 17 |
+
- en
|
| 18 |
+
pipeline_tag: text-generation
|
| 19 |
+
datasets:
|
| 20 |
+
- birdsql/bird_mini_dev
|
| 21 |
---
|
| 22 |
|
| 23 |
+
# Qwen2.5-Coder-7B BIRD-DPO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
A LoRA adapter for **Qwen2.5-Coder-7B-Instruct** fine-tuned for real-world Text-to-SQL with **DPO using frontier model disagreements**. Achieves **50.3% on the BIRD dev set** — a +23.3pp improvement over the base model on real-world database queries with messy schemas and domain-specific evidence.
|
| 26 |
|
| 27 |
+
## Results
|
| 28 |
|
| 29 |
+
| Benchmark | Metric | Score |
|
| 30 |
+
|---|---|---|
|
| 31 |
+
| **BIRD dev** (1,534 Q) | Result accuracy | **50.3%** |
|
| 32 |
+
| **BIRD mini-dev** (500 Q) | Result accuracy | **44.4%** |
|
| 33 |
+
| BIRD mini-dev — Simple | Result accuracy | 62.8% |
|
| 34 |
+
| BIRD mini-dev — Moderate | Result accuracy | 38.8% |
|
| 35 |
+
| BIRD mini-dev — Challenging | Result accuracy | 31.4% |
|
| 36 |
+
| **Spider V1 dev** (1,034 Q, cross-eval) | Result accuracy | **75.9%** |
|
| 37 |
|
| 38 |
+
**Cross-domain transfer**: trained purely on BIRD, this adapter scores **75.9% on Spider** — only 2.3pp below a Spider-specific adapter (78.2%). Strong evidence that DPO from frontier disagreements generalizes across SQL benchmarks.
|
| 39 |
|
| 40 |
+
| Model | BIRD dev |
|
| 41 |
+
|---|---|
|
| 42 |
+
| Qwen2.5-Coder-7B base | 27.0% |
|
| 43 |
+
| Qwen2.5-Coder-7B + SFT only | ~35% |
|
| 44 |
+
| **Qwen2.5-Coder-7B + SFT + BIRD-DPO (this model)** | **50.3%** |
|
| 45 |
|
| 46 |
+
## Quick Start
|
| 47 |
|
| 48 |
+
```python
|
| 49 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 50 |
+
from peft import PeftModel
|
| 51 |
+
import torch
|
| 52 |
|
| 53 |
+
BASE_MODEL = "Qwen/Qwen2.5-Coder-7B-Instruct"
|
| 54 |
+
ADAPTER = "jk200201/qwen2.5-coder-7b-bird-dpo"
|
| 55 |
|
| 56 |
+
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)
|
| 57 |
|
| 58 |
+
bnb = BitsAndBytesConfig(
|
| 59 |
+
load_in_4bit=True, bnb_4bit_quant_type="nf4",
|
| 60 |
+
bnb_4bit_compute_dtype=torch.bfloat16, bnb_4bit_use_double_quant=True,
|
| 61 |
+
)
|
| 62 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 63 |
+
BASE_MODEL, quantization_config=bnb, device_map="auto", trust_remote_code=True
|
| 64 |
+
)
|
| 65 |
+
model = PeftModel.from_pretrained(model, ADAPTER)
|
| 66 |
+
model.eval()
|
| 67 |
|
| 68 |
+
schema = "CREATE TABLE users (id INT, name TEXT, country TEXT);"
|
| 69 |
+
question = "How many users are from Japan?"
|
| 70 |
+
evidence = "" # optional domain hint for BIRD-style queries
|
| 71 |
|
| 72 |
+
prompt = f"""Convert the following natural language question into a valid SQL query.
|
| 73 |
|
| 74 |
+
Database Schema:
|
| 75 |
+
{schema}
|
| 76 |
|
| 77 |
+
{f'External Knowledge:{chr(10)}{evidence}{chr(10)}{chr(10)}' if evidence.strip() else ''}Question: {question}
|
| 78 |
|
| 79 |
+
Return only the SQL query with no explanation."""
|
| 80 |
|
| 81 |
+
inputs = tokenizer.apply_chat_template(
|
| 82 |
+
[{"role": "user", "content": prompt}],
|
| 83 |
+
return_tensors="pt", add_generation_prompt=True
|
| 84 |
+
).to(model.device)
|
| 85 |
|
| 86 |
+
out = model.generate(inputs, max_new_tokens=256, do_sample=False, pad_token_id=tokenizer.eos_token_id)
|
| 87 |
+
sql = tokenizer.decode(out[0][inputs.shape[-1]:], skip_special_tokens=True).strip()
|
| 88 |
+
print(sql)
|
| 89 |
+
```
|
| 90 |
|
| 91 |
## Training Details
|
| 92 |
|
| 93 |
+
**The novel idea**: rather than human-annotated preferences, this model uses **automatically generated preference pairs from frontier model disagreements** — total cost: ~$25 of OpenRouter API calls.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
### Pipeline
|
| 96 |
|
| 97 |
+
1. Run **Grok-4.1-fast** and **DeepSeek-V3.2** on BIRD train (9,428 questions). Both score ~53%.
|
| 98 |
+
2. Compare results question-by-question. Where one model is right and the other wrong → preference pair (1,219 pairs from BIRD).
|
| 99 |
+
3. SFT Qwen2.5-Coder-7B on BIRD train gold SQL (QLoRA r=32, α=64, NF4 4-bit, 3 epochs).
|
| 100 |
+
4. DPO on the 1,219 clear-preference pairs on top of SFT (β=0.05, 1 epoch, cutoff=8192).
|
| 101 |
|
| 102 |
+
### Hyperparameters
|
| 103 |
|
| 104 |
+
| Stage | Setting |
|
| 105 |
+
|---|---|
|
| 106 |
+
| Quantization | 4-bit NF4 (QLoRA) |
|
| 107 |
+
| LoRA rank | 32 |
|
| 108 |
+
| LoRA alpha | 64 |
|
| 109 |
+
| LoRA dropout | 0.05 |
|
| 110 |
+
| Target modules | q/k/v/o_proj, gate/up/down_proj |
|
| 111 |
+
| SFT epochs | 3, LR 2e-4 cosine |
|
| 112 |
+
| DPO epochs | 1, LR 5e-5 cosine, β=0.05 |
|
| 113 |
+
| Cutoff length | 8,192 tokens (H200 80GB) |
|
| 114 |
|
| 115 |
+
### Hardware
|
| 116 |
|
| 117 |
+
Northeastern Discovery HPC — single NVIDIA H200 80GB. Training time: ~1h 15min.
|
| 118 |
|
| 119 |
+
## Key Finding — What Doesn't Work
|
| 120 |
|
| 121 |
+
Initially trained with 4,677 pairs (1,219 clear-preference + 3,458 judge-resolved style pairs). This **regressed to 40.7%** (-9.6pp).
|
| 122 |
|
| 123 |
+
**Lesson**: judge-resolved pairs where both models are correct but write different SQL carry zero correctness signal for BIRD's result-accuracy metric. They dilute training and hurt performance. Only use pairs where one model is right and one is wrong.
|
| 124 |
|
| 125 |
+
## Limitations
|
| 126 |
|
| 127 |
+
- BIRD test set was not used (hidden); evaluation is on the public dev set
|
| 128 |
+
- Real-world databases with very long schemas (>8K tokens) get truncated
|
| 129 |
+
- Optimized for SQLite syntax (BIRD format); MySQL/PostgreSQL outputs may need adaptation
|
| 130 |
+
- Trained only on English questions
|
| 131 |
|
| 132 |
+
## Related Models
|
| 133 |
|
| 134 |
+
- **Spider version** of this approach: [`jk200201/qwen2.5-coder-7b-sql-dpo`](https://huggingface.co/jk200201/qwen2.5-coder-7b-sql-dpo) — 78.2% on Spider V1, also beats Grok-4 and DeepSeek V3
|
| 135 |
|
| 136 |
+
## Citation
|
| 137 |
|
| 138 |
+
If you use this model, please cite:
|
|
|
|
| 139 |
|
| 140 |
+
```bibtex
|
| 141 |
+
@misc{kothari2026qwenbirddpo,
|
| 142 |
+
author = {Kothari, Jenish},
|
| 143 |
+
title = {Qwen2.5-Coder-7B BIRD-DPO: Frontier-Disagreement DPO for Real-World Text-to-SQL},
|
| 144 |
+
year = {2026},
|
| 145 |
+
publisher = {Hugging Face},
|
| 146 |
+
howpublished = {\url{https://huggingface.co/jk200201/qwen2.5-coder-7b-bird-dpo}},
|
| 147 |
+
}
|
| 148 |
+
```
|