For real-world database queries (BIRD-style schemas with evidence), use the companion model:
jk200201/qwen2.5-coder-7b-bird-dpo.
1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5BASE_MODEL = "Qwen/Qwen2.5-Coder-7B-Instruct"
6ADAPTER = "jk200201/qwen2.5-coder-7b-sql-dpo"
7
8tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)
9
10bnb = BitsAndBytesConfig(
11 load_in_4bit=True, bnb_4bit_quant_type="nf4",
12 bnb_4bit_compute_dtype=torch.bfloat16, bnb_4bit_use_double_quant=True,
13)
14model = AutoModelForCausalLM.from_pretrained(
15 BASE_MODEL, quantization_config=bnb, device_map="auto", trust_remote_code=True
16)
17model = PeftModel.from_pretrained(model, ADAPTER)
18model.eval()
19
20schema = "CREATE TABLE users (id INT, name TEXT, country TEXT);"
21question = "How many users are from Japan?"
22
23prompt = f"""Convert the following natural language question into a valid SQL query.
24
25Database Schema:
26{schema}
27
28Question: {question}
29
30Return only the SQL query with no explanation."""
31
32inputs = tokenizer.apply_chat_template(
33 [{"role": "user", "content": prompt}],
34 return_tensors="pt", add_generation_prompt=True
35).to(model.device)
36
37out = model.generate(inputs, max_new_tokens=256, do_sample=False, pad_token_id=tokenizer.eos_token_id)
38sql = tokenizer.decode(out[0][inputs.shape[-1]:], skip_special_tokens=True).strip()
39print(sql)
jk200201/spider-dpo-1040 — 1,040 preference pairs built from Grok-4 vs DeepSeek-V3 disagreements on Spider dev.
AWS EC2 g5.xlarge (NVIDIA A10G 24GB VRAM). Training time: ~3h total.
1@misc{kothari2026qwenspiderdpo,
2 author = {Kothari, Jenish},
3 title = {Qwen2.5-Coder-7B Spider-DPO: A 7B Model that Beats Frontier Models on Spider via Frontier-Disagreement DPO},
4 year = {2026},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/jk200201/qwen2.5-coder-7b-sql-dpo}},
7}