SQLForge-3B
a compact model for generating SQLite queries
2 min read
The model translates natural language questions into ready-to-use SELECT queries for SQLite databases. It was created by author ay2r based on Qwen2.5-Coder-3B-Instruct (3.09 billion parameters) using QLoRA (an efficient fine-tuning method with quantization) on the Spider and BIRD datasets. Unlike the base version, the fine-tune understands table structures and sample rows noticeably more accurately, outputting clean code without unnecessary explanations. It is suitable for developers, analysts, and creators of local AI assistants for working with databases on low-end hardware.
Key features
- High execution accuracy (EX): an increase from 41.7% to 53.1% on the difficult BIRD benchmark compared to the base model.
- Minimal memory requirements: weighs 5.8 GB in bf16, and in quantized GGUF Q4_K_M and AWQ formats takes up only 1.8–2 GB VRAM.
- Support for prefix caching in vLLM, which speeds up generation by 4.7 times during a series of questions for a single database schema.
- Trained on just a single laptop GPU with 8 GB of video memory using 16,218 verified examples from 201 databases.
What you can do
- Integrate it into a local Telegram bot or internal analytics service for quickly generating reports from SQLite databases via text prompt.
- Run it via the vLLM or llama.cpp engine on an office PC or laptop for secure offline work with corporate data (be sure to check queries for read-only mode).
Example
from transformers import AutoModelForCausalLM, AutoTokenizer
tok = AutoTokenizer.from_pretrained("ay2r/sqlforge-3b")
model = AutoModelForCausalLM.from_pretrained("ay2r/sqlforge-3b", dtype="bfloat16", device_map="auto")
messages = [{"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": user_prompt}]
ids = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
print(tok.decode(model.generate(ids, max_new_tokens=256, do_sample=False)[0, ids.shape[1]:], skip_special_tokens=True))
Read more
DetailsBenchmarks (Execution Accuracy): Spider dev — 78.5% (base 71.8%), BIRD dev — 53.1% (base 41.7%); with post-processing and self-correction — up to 80.5% and 54.1%.
Quantization: FP8 (3.2 GB VRAM, 78.6% Spider), GGUF Q8_0 (3.3 GB), GGUF Q4_K_M (1.8 GB), AWQ W4A16 (2.0 GB).
Limitations: SQLite dialect only; column name hallucinations are possible; for schemas longer than ~8k tokens, preliminary schema linking is required.
Security: the model is vulnerable to prompt injections (can generate
DROP TABLE), run strictly with read-only restrictions.









Comments