SQLForge is a QLoRA adapter for
mistralai/Mistral-7B-v0.3
that forges natural-language questions into executable SQL. Trained on a mixture of
Spider and
b-mc2/sql-create-context (~90k examples), it brings exact-match
accuracy on an internal text-to-SQL test split from
9.2% → 87.0% over the base model,
while keeping the adapter footprint under
340 MB.
Evaluated on a held-out internal text-to-SQL test set (500 examples, schema-aware prompt):
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3from peft import PeftModel
4
5BASE = "mistralai/Mistral-7B-v0.3"
6ADAPT = "shreyash-pandey-katni/SQLForge-Mistral-7B-QLoRA"
7
8tok = AutoTokenizer.from_pretrained(BASE)
9model = AutoModelForCausalLM.from_pretrained(
10 BASE,
11 torch_dtype=torch.bfloat16,
12 device_map="auto",
13)
14model = PeftModel.from_pretrained(model, ADAPT)
15model.eval()
16
17schema = "CREATE TABLE employees (id INT, name TEXT, dept TEXT, salary REAL);"
18question = "List the names of employees in the Engineering department earning over 100000."
19
20prompt = f"""[INST] You are an expert SQL assistant. Given the schema and question, write a single SQL query.
21
22Schema:
23{schema}
24
25Question: {question} [/INST]"""
26
27inputs = tok(prompt, return_tensors="pt").to(model.device)
28out = model.generate(**inputs, max_new_tokens=128, do_sample=False)
29print(tok.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
1from transformers import BitsAndBytesConfig
2
3bnb = BitsAndBytesConfig(
4 load_in_4bit=True,
5 bnb_4bit_quant_type="nf4",
6 bnb_4bit_compute_dtype=torch.bfloat16,
7)
8model = AutoModelForCausalLM.from_pretrained(BASE, quantization_config=bnb, device_map="auto")
9model = PeftModel.from_pretrained(model, ADAPT)
The metrics above use
exact_set_match (gold and predicted normalized SQL match exactly
as token sets) and
valid_sql_pct (predicted SQL parses with
sqlparse/sqlite3).
See
evaluate_sql.py in the
training repository
for the full eval harness.
1@misc{sqlforge_mistral7b_qlora_2026,
2 title = {SQLForge-Mistral-7B-QLoRA: A QLoRA Text-to-SQL Adapter for Mistral-7B-v0.3},
3 author = {Shreyash Pandey Katni},
4 year = {2026},
5 url = {https://huggingface.co/shreyash-pandey-katni/SQLForge-Mistral-7B-QLoRA}
6}