gretelai/synthetic_text_to_sql
Viewer • Updated • 106k • 3.83k • 710
How to use amer003100/qwen2.5-coder-3b-text-to-sql-lora with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-Coder-3B-Instruct")
model = PeftModel.from_pretrained(base_model, "amer003100/qwen2.5-coder-3b-text-to-sql-lora")LoRA adapter fine-tuned on gretelai/synthetic_text_to_sql. It takes a table schema
and a question and returns only the SQL query. This is a demo/portfolio project.
Execution accuracy on 200 questions from the dataset's test split (gold queries that run on SQLite and return rows). A prediction counts as correct if its result set matches the gold result set.
| Model | Execution accuracy | Valid SQL |
|---|---|---|
| Base Qwen2.5-Coder-3B-Instruct | 57.0% | 89.5% |
| + this adapter | 69.5% | 97.5% |
System: You are a SQL assistant. Given a table schema and a question, reply with ONLY the SQL query, nothing else.
User: Schema:\n<CREATE TABLE statements>\n\nQuestion: <question>
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
base_id = "Qwen/Qwen2.5-Coder-3B-Instruct"
tok = AutoTokenizer.from_pretrained(base_id)
base = AutoModelForCausalLM.from_pretrained(base_id, dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(base, "amer003100/qwen2.5-coder-3b-text-to-sql-lora")