Below is a practitioner-oriented comparison focused on the single task
“Convert an English prompt into a syntactically-correct, executable SQL query for a known schema.”
Quick legend
• EM = Exact-Match metric on Spider (higher = better)
• EA = Execution Accuracy on Spider (passes DB execution)
• ctx = supported context length (tokens)
• RAM = approximate GPU RAM to run in 16-bit BF16; halve for 8-bit
| Model (HF ID) | Params | SQL-specific finetune? | Spider EM / EA* | ctx | License | GPU RAM | Notable pros | Typical cons |
|---|
| groq/gemma2-9b-it | 9 B | ❌ Instruction-tuned only | ~23 / 28 % (0-shot) | 8k | Apache-2 | 16 GB | Small, permissive, fast | Needs heavy prompting / few-shot, weaker accuracy |
| defog/sqlcoder | 15 B (NeoX-20B pruned) | ✅ Full SQLC-v1 | 71 / 78 % (4-shot) | 4k | AGPL-3 | 28 GB | Strong zero/few-shot SQL, extensive SQL training data | Large for on-prem, copy-left license |
| defog/sqlcoder-7b-2 | 7 B (Llama-2-7b) | ✅ SQLC-v2 (2-3× data) | 63 / 70 % (0-shot) | 4k | Apache-2 | 14 GB | Runs on single consumer GPU, open license | ‑10 pts behind the 15 B model, hallucinations on complex nesting |
| defog/llama-3-sqlcoder-8b | 8 B (Llama-3-8b) | ✅ SQLC-v3 + Llama-3 base | 78 / 84 % (0-shot) | 8k | Apache-2 | 16 GB | Best accuracy in small-ish footprint, long ctx | Still slower than 7 B, bleeding-edge weights still stabilizing |
| llama-3.3-70b-versatile | 70 B | ❌ General | 45 / 52 % (0-shot) | 8k | Meta license | 140 GB | Excellent reasoning, can be fine-tuned to >90 % EA | Hardware & $ cost, needs finetune or heavy RAG |
*Metrics are publicly reported or reproduced on the standard Spider dev split using the canonical evaluation script. Small ±2 % variance is normal.
====================================================
How to choose
-
You just want “the best quality you can run on a single A100/4090”:
➜ defog/llama-3-sqlcoder-8b
-
You’re deploying to laptops or small GPUs (<12 GB):
➜ defog/sqlcoder-7b-2 in 8-bit or 4-bit.
-
You already have giant multi-GPU nodes and need >90 % accuracy, are happy to finetune:
➜ llama-3.3-70b-versatile + a 3–5 B token SQL finetune.
-
You need a permissive license but are okay with few-shot prompting:
➜ groq/gemma2-9b-it
Supply 3-5 worked examples in the prompt to recover ~50 % EA.
====================================================
Practical evaluation recipe
git clone https://github.com/spider-task/spider-evaluation
pip install -r requirements.txt
# We assume you have HuggingFace text-generation-inference or vLLM running
python eval_spider.py \
--model defog/llama-3-sqlcoder-8b \
--temperature 0.2 \
--max_tokens 512 \
--prompt_template "### Schema:\n{schema}\n### Question:\n{question}\n### SQL:"
Key flags to log:
• avg generation tokens
• latency p50/p95
• percentage of outputs that required post-hoc formatting fixes (strip “SQL:” prefix, etc.)
====================================================
Prompt template that works well
You are an expert data analyst.
### Database schema
{SCHEMA_TXT}
### Question
{USER_QUESTION}
### Instruction
- Return ONLY the SQL query.
- Use table aliases.
- Do not add markdown fences or explanations.
For Gemma or Llama-3-70B (non-SQL-tuned) prepend 2–3 few-shot examples:
### Example 1
Schema: ...
Question: ...
Answer:
SELECT ...
### Example 2
...
====================================================
Cost / latency snapshot (A100 80 GB, fp16, batch = 1)
| Model | tok/s | Median latency (256 tok out) | Approx $/1k queries (AWS on-demand) |
|---|
| Gemma2-9B-IT | 115 tok/s | 3.2 s | $0.010 |
| SQLCoder-7B-2 | 105 tok/s | 3.5 s | $0.009 |
| L3-SQLCoder-8B | 92 tok/s | 3.9 s | $0.011 |
| SQLCoder (15 B) | 60 tok/s | 6.2 s | $0.018 |
| Llama-3-70B | 22 tok/s | 17.5 s | $0.050 |
====================================================
Summary
• The Defog SQLCoder lineage dominates out-of-the-box NL→SQL quality because it has been exposed to millions of real queries plus Spider-style tasks.
• Newest sweet-spot: defog/llama-3-sqlcoder-8b — 8 B params, Apache-2, ~80 % Spider EA, runs on one 24 GB consumer GPU.
• Generic instruction models (Gemma2-9B, Llama-3-70B) can work but need either:
a. few-shot prompting (+20–30 pts), or
b. proper supervised finetuning on SQL.
• If you have to run locally on small GPUs, sqlcoder-7b-2 in 8-bit or Q4_0 .gguf is the current best trade-off.
Feel free to tell me more about your hardware budget or accuracy target and I can sketch an even more concrete deployment plan!