Text Generation
PEFT
Safetensors
MLX
English
text-to-sql
sql
sqlite
lora
bird
spider
Eval Results (legacy)
Instructions to use Felamity-Technologies/sqlant-1b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Felamity-Technologies/sqlant-1b with PEFT:
Task type is invalid.
- MLX
How to use Felamity-Technologies/sqlant-1b with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # if on a CUDA device, also pip install mlx[cuda] # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("Felamity-Technologies/sqlant-1b") prompt = "Once upon a time in" text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- MLX LM
How to use Felamity-Technologies/sqlant-1b with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Generate some text mlx_lm.generate --model "Felamity-Technologies/sqlant-1b" --prompt "Once upon a time"
- Atomic Chat
Final pipeline: 16 candidates, verifier weight 1.0 (BIRD dev 58.3, Spider dev 77.2)
Browse files- README.md +24 -21
- code/README.md +4 -4
- code/sqlant/pipeline.py +6 -3
README.md
CHANGED
|
@@ -28,8 +28,8 @@ model-index:
|
|
| 28 |
split: dev
|
| 29 |
metrics:
|
| 30 |
- type: execution_accuracy
|
| 31 |
-
value:
|
| 32 |
-
name: EX (full pipeline,
|
| 33 |
- type: execution_accuracy
|
| 34 |
value: 44.9
|
| 35 |
name: EX (single answer, pruning + repair)
|
|
@@ -41,8 +41,8 @@ model-index:
|
|
| 41 |
split: dev
|
| 42 |
metrics:
|
| 43 |
- type: execution_accuracy
|
| 44 |
-
value:
|
| 45 |
-
name: EX (full pipeline,
|
| 46 |
- type: execution_accuracy
|
| 47 |
value: 74.7
|
| 48 |
name: EX (single answer, pruning + repair)
|
|
@@ -76,7 +76,7 @@ The base model is not included; it downloads from Hugging Face on first use. Bot
|
|
| 76 |
|
| 77 |
## Results
|
| 78 |
|
| 79 |
-
Execution accuracy (EX) on the **full** BIRD dev (1,534) and Spider dev (1,034) sets. No dev question or database was used for training. Each configuration below was fixed beforehand and run on dev once, with
|
| 80 |
|
| 81 |
| Configuration | BIRD dev | Spider dev | Generations per question |
|
| 82 |
|---|---|---|---|
|
|
@@ -86,16 +86,19 @@ Execution accuracy (EX) on the **full** BIRD dev (1,534) and Spider dev (1,034)
|
|
| 86 |
| + 8 candidates, self-consistency (majority vote on results) | 51.2 | 75.4 | 9 |
|
| 87 |
| + verifier rerank | 53.3 (95% CI 50.8–55.7) | 77.2 (74.5–79.6) | 9, plus ~2.3 verifier passes |
|
| 88 |
| + value snapping + empty-result rule | 54.1 (51.6–56.6) | 74.8 (72.1–77.4) | same |
|
| 89 |
-
|
|
| 90 |
-
| *
|
|
|
|
|
|
|
| 91 |
|
| 92 |
- **The verifier is a statistically significant gain.** Against the plain vote it fixes 70 questions and breaks 21 (McNemar p < 0.001). The gain holds on both BIRD (44 / 13) and Spider (26 / 8).
|
| 93 |
- **Value snapping + the empty-result rule add 0.8 on BIRD** (14 questions fixed, 1 broken).
|
| 94 |
- **The final verifier was trained on twice the data** (19,491 examples, up from 9,395). On full dev it fixes 66 questions and breaks 28 (p < 0.001): BIRD +42/−17, Spider +24/−11. On held-out databases its gain was smaller (+23/−15, not significant), so it was chosen on dev by a rule set before the run: adopt it only if overall dev EX rose by at least 1.0 point. It rose by 1.5. Because the choice used dev, treat these dev numbers as slightly optimistic.
|
| 95 |
-
- **
|
| 96 |
-
- **
|
| 97 |
-
- **
|
| 98 |
-
- **
|
|
|
|
| 99 |
|
| 100 |
### Comparison with published models (BIRD dev EX)
|
| 101 |
|
|
@@ -105,12 +108,12 @@ Other systems' numbers come from their papers and model cards, with their own pr
|
|
| 105 |
|---|---|---|---|
|
| 106 |
| Prem-1B-SQL | 1.3B | 46 | 85 |
|
| 107 |
| CodeS-1B (SFT) | 1B | 50.5 | 77.9 |
|
| 108 |
-
| **SQLant-1B (this model)** | 1.5B | **55.7** | **76.0**¹ |
|
| 109 |
| SLM-SQL-0.5B | 0.5B | 56.9 | — |
|
|
|
|
| 110 |
| OmniSQL-7B | 7B | 63.9 (66.1 with voting) | 81.2² |
|
| 111 |
| SLM-SQL-1.5B (same base, SFT + GRPO + voting) | 1.5B | 67.1 | — |
|
| 112 |
|
| 113 |
-
¹
|
| 114 |
² Test-suite accuracy, which is stricter than the execution accuracy in the other rows, so it is not directly comparable.
|
| 115 |
|
| 116 |
SQLant-1B uses only supervised fine-tuning plus inference-time selection; it has no reinforcement learning. Models with GRPO-style training on the same base score substantially higher on BIRD.
|
|
@@ -121,11 +124,11 @@ For each question:
|
|
| 121 |
|
| 122 |
1. **Draft.** The generator writes one query (greedy) from the full schema.
|
| 123 |
2. **Prune.** The schema is cut to the tables that matter: tables whose names or columns match the question or hint, tables containing values mentioned in the question, tables the draft used, and the foreign-key tables that connect them. Databases with fewer than 5 tables aren't pruned.
|
| 124 |
-
3. **Generate
|
| 125 |
4. **Repair and run.** Each candidate is repaired (a column on the wrong alias, or a missing one-hop join along a foreign key, only when there is exactly one valid fix), then **value-snapped**: a literal in `col = '…'` that doesn't occur in that column is replaced by the unique stored value that matches it up to case, punctuation or spacing, or a short prefix for numbers (`2002` → `'YR2002'`). `col IS NULL` becomes `col = ''` when the column has no NULLs but has empty strings. The query is then executed read-only. Failed queries are dropped.
|
| 126 |
5. **Group** the candidates by their result rows.
|
| 127 |
6. **Verify.** If there are two or more groups, the verifier scores one SQL per group: `v = logit("yes") − logit("no")`, one forward pass, no generation.
|
| 128 |
-
7. **Pick** the group with the highest `v + 1.
|
| 129 |
|
| 130 |
### Prompt formats
|
| 131 |
|
|
@@ -262,7 +265,7 @@ To get a standalone generator model, fuse the adapter: `python -m mlx_lm fuse --
|
|
| 262 |
| | |
|
| 263 |
|---|---|
|
| 264 |
| Method | A separate LoRA (rank 16, layers 1–27, all 7 projections) on the base model, trained to answer `yes` / `no` |
|
| 265 |
-
| Data | The generator's own candidates (8 per question) on 10,458 questions: 3,484 BIRD-train and 2,974 Spider-train questions the generator never trained on, plus 4,000 **SynSQL-2.5M** questions. Labels come from executing each candidate against the gold query. 19,491 training examples (32% yes); 10% of databases held out for validation and for picking the
|
| 266 |
| Optimisation | AdamW, LR 1e-4 → 1e-5 (linear), 1 epoch (2,437 updates, effective batch 8), clipping 1.0 |
|
| 267 |
| Hardware / time | Apple M5 Pro 24 GB; about 16 h to generate candidates + 9.2 h to train |
|
| 268 |
|
|
@@ -280,8 +283,8 @@ Three issues in mlx-lm 0.32.2 / mlx 0.32.4 silently broke LoRA training on this
|
|
| 280 |
|---|---|
|
| 281 |
| Metric | Execution accuracy: the predicted query's result rows, compared as a **set** with the gold query's rows (like BIRD's official evaluator, which ignores row order and duplicates). 30 s timeout per query, read-only database. |
|
| 282 |
| Prompt | Schema as `CREATE TABLE` statements with 3 example rows per table (values cut at 40 characters), BIRD's hint text, the question |
|
| 283 |
-
| Decoding | Greedy for the draft and for candidate 1; T 0.8, top-p 0.95 for the
|
| 284 |
-
| Selection hygiene | Every choice (pruning, repair, value snapping, the empty-result rule, number of candidates, verifier weight) was made on a tuning set from held-out training databases or on held-out-database verifier data. Dev was used once per milestone, for reporting only, except for
|
| 285 |
|
| 286 |
The Spider numbers use the same set-based comparison, not Spider's official test-suite evaluation, which also checks row order for `ORDER BY` queries. They may read slightly higher than official Spider EX.
|
| 287 |
|
|
@@ -289,10 +292,10 @@ The Spider numbers use the same set-based comparison, not Spider's official test
|
|
| 289 |
|
| 290 |
- **SQLite only, English only.** Trained and evaluated on SQLite dialect and English questions. Other dialects (Postgres, BigQuery, Snowflake) were not tested.
|
| 291 |
- **Benchmark-style data.** Training data comes from BIRD, Spider and synthetic SynSQL databases. Real enterprise schemas (hundreds of tables, cryptic names, no hints) will be harder; Spider 2.0-style warehouse tasks are out of scope.
|
| 292 |
-
- **About
|
| 293 |
- **The full pipeline needs database access.** It executes candidate queries, so it needs a live (read-only) connection. Without one, use the single-answer mode (44.9 / 74.7 with pruning and repair, or 40.8 / 73.4 plain).
|
| 294 |
-
- **Harder, hint-free questions score much lower.** On the 2026 revision of BIRD mini-dev (SQLite, 500 questions, 460 of them "challenging", no hints), the
|
| 295 |
-
- **Cost.** The full pipeline runs
|
| 296 |
- **The verifier's score is not a calibrated probability.** It's used only to rank candidates against each other.
|
| 297 |
|
| 298 |
## Safe use
|
|
|
|
| 28 |
split: dev
|
| 29 |
metrics:
|
| 30 |
- type: execution_accuracy
|
| 31 |
+
value: 58.3
|
| 32 |
+
name: EX (full pipeline, 16 candidates + verifier + value snapping)
|
| 33 |
- type: execution_accuracy
|
| 34 |
value: 44.9
|
| 35 |
name: EX (single answer, pruning + repair)
|
|
|
|
| 41 |
split: dev
|
| 42 |
metrics:
|
| 43 |
- type: execution_accuracy
|
| 44 |
+
value: 77.2
|
| 45 |
+
name: EX (full pipeline, 16 candidates + verifier + value snapping)
|
| 46 |
- type: execution_accuracy
|
| 47 |
value: 74.7
|
| 48 |
name: EX (single answer, pruning + repair)
|
|
|
|
| 76 |
|
| 77 |
## Results
|
| 78 |
|
| 79 |
+
Execution accuracy (EX) on the **full** BIRD dev (1,534) and Spider dev (1,034) sets. No dev question or database was used for training. Each configuration below was fixed beforehand and run on dev once, with two exceptions, noted in the last two rows: the choice between two verifiers and the choice between 8 and 16 candidates were each made on dev, by a rule set before the run.
|
| 80 |
|
| 81 |
| Configuration | BIRD dev | Spider dev | Generations per question |
|
| 82 |
|---|---|---|---|
|
|
|
|
| 86 |
| + 8 candidates, self-consistency (majority vote on results) | 51.2 | 75.4 | 9 |
|
| 87 |
| + verifier rerank | 53.3 (95% CI 50.8–55.7) | 77.2 (74.5–79.6) | 9, plus ~2.3 verifier passes |
|
| 88 |
| + value snapping + empty-result rule | 54.1 (51.6–56.6) | 74.8 (72.1–77.4) | same |
|
| 89 |
+
| + verifier trained on twice the data | 55.7 (53.2–58.1) | 76.0 (73.3–78.5) | same |
|
| 90 |
+
| **+ 16 candidates instead of 8 (full SQLant-1B pipeline)** | **58.3** (55.7–60.8) | **77.2** (74.5–79.7) | 17, plus ~3 verifier passes |
|
| 91 |
+
| *Oracle@8: upper bound, at least one of 8 candidates is correct* | *64.9* | *86.2* | |
|
| 92 |
+
| *Oracle@16: upper bound, at least one of 16 candidates is correct* | *71.1* | *89.6* | |
|
| 93 |
|
| 94 |
- **The verifier is a statistically significant gain.** Against the plain vote it fixes 70 questions and breaks 21 (McNemar p < 0.001). The gain holds on both BIRD (44 / 13) and Spider (26 / 8).
|
| 95 |
- **Value snapping + the empty-result rule add 0.8 on BIRD** (14 questions fixed, 1 broken).
|
| 96 |
- **The final verifier was trained on twice the data** (19,491 examples, up from 9,395). On full dev it fixes 66 questions and breaks 28 (p < 0.001): BIRD +42/−17, Spider +24/−11. On held-out databases its gain was smaller (+23/−15, not significant), so it was chosen on dev by a rule set before the run: adopt it only if overall dev EX rose by at least 1.0 point. It rose by 1.5. Because the choice used dev, treat these dev numbers as slightly optimistic.
|
| 97 |
+
- **16 candidates beat 8 once the verifier picks.** With majority voting alone, going from 8 to 16 candidates had not helped on the tuning set: the extra right answers were minority votes. The verifier can pick a minority answer, so on held-out-database questions 16 candidates gained 1.4 points (+39/−22, p = 0.04) with the vote weight re-chosen there (1.0). On full dev, under a rule set before the run (adopt only if overall EX rises by at least 1.0), 16 candidates fixed 87 questions and broke 36 (p < 0.001): BIRD +60/−21, Spider +27/−15, overall +2.0. The gain is mostly from the extra candidates; changing only the weight to 1.0 with 8 candidates gives +0.2.
|
| 98 |
+
- **The lower Spider score is caused by one database with wrong gold answers.** 25 of the 27 lost Spider questions are in `flight_2`, whose stored values carry stray spaces (`'Anthony '`, `' APG'`). Spider's gold SQL compares against `"Anthony"`, so the gold answer is empty. SQLant's snapped SQL uses the stored value and returns the real rows, which the benchmark counts as wrong. On the other Spider databases the score is unchanged (76.2 → 76.2) by snapping, and the final pipeline scores 78.8 there. We kept the behaviour that gives correct answers on real data.
|
| 99 |
+
- **BIRD by difficulty** (full pipeline): simple 65.9 · moderate 47.6 · challenging 43.4.
|
| 100 |
+
- **Oracle@N is not an achievable score.** It counts a question as solved if *any* of the N candidates is right, as a perfect selector would. With 16 candidates the final pipeline recovers 58.3 of BIRD's 71.1, so better selection could still add up to about 13 points on BIRD and 12 on Spider.
|
| 101 |
+
- **PyTorch and MLX give the same system.** The results above were produced with MLX. The PyTorch/PEFT version in `code/` was checked against it on 200 BIRD dev questions (8-candidate configuration): the verifier gives near-identical scores to the same inputs (correlation 0.9992, same top-ranked candidate in 40/40 questions), and 180/200 greedy drafts are identical (the rest differ through bf16 rounding). End-to-end accuracy differs only by sampling noise (34.0 vs 38.5 vs 35.5 for the original run, all differences not significant), because the two frameworks draw different random samples.
|
| 102 |
|
| 103 |
### Comparison with published models (BIRD dev EX)
|
| 104 |
|
|
|
|
| 108 |
|---|---|---|---|
|
| 109 |
| Prem-1B-SQL | 1.3B | 46 | 85 |
|
| 110 |
| CodeS-1B (SFT) | 1B | 50.5 | 77.9 |
|
|
|
|
| 111 |
| SLM-SQL-0.5B | 0.5B | 56.9 | — |
|
| 112 |
+
| **SQLant-1B (this model)** | 1.5B | **58.3** | **77.2**¹ |
|
| 113 |
| OmniSQL-7B | 7B | 63.9 (66.1 with voting) | 81.2² |
|
| 114 |
| SLM-SQL-1.5B (same base, SFT + GRPO + voting) | 1.5B | 67.1 | — |
|
| 115 |
|
| 116 |
+
¹ 78.8 without `flight_2`, whose gold answers are empty because of whitespace in the stored values (see above).
|
| 117 |
² Test-suite accuracy, which is stricter than the execution accuracy in the other rows, so it is not directly comparable.
|
| 118 |
|
| 119 |
SQLant-1B uses only supervised fine-tuning plus inference-time selection; it has no reinforcement learning. Models with GRPO-style training on the same base score substantially higher on BIRD.
|
|
|
|
| 124 |
|
| 125 |
1. **Draft.** The generator writes one query (greedy) from the full schema.
|
| 126 |
2. **Prune.** The schema is cut to the tables that matter: tables whose names or columns match the question or hint, tables containing values mentioned in the question, tables the draft used, and the foreign-key tables that connect them. Databases with fewer than 5 tables aren't pruned.
|
| 127 |
+
3. **Generate 16 candidates.** On the pruned prompt: 1 greedy answer plus 15 samples (temperature 0.8, top-p 0.95).
|
| 128 |
4. **Repair and run.** Each candidate is repaired (a column on the wrong alias, or a missing one-hop join along a foreign key, only when there is exactly one valid fix), then **value-snapped**: a literal in `col = '…'` that doesn't occur in that column is replaced by the unique stored value that matches it up to case, punctuation or spacing, or a short prefix for numbers (`2002` → `'YR2002'`). `col IS NULL` becomes `col = ''` when the column has no NULLs but has empty strings. The query is then executed read-only. Failed queries are dropped.
|
| 129 |
5. **Group** the candidates by their result rows.
|
| 130 |
6. **Verify.** If there are two or more groups, the verifier scores one SQL per group: `v = logit("yes") − logit("no")`, one forward pass, no generation.
|
| 131 |
+
7. **Pick** the group with the highest `v + 1.0 · log(votes)`. A clear majority usually wins, and the verifier decides close calls. **If the chosen query returns no rows** and another group returns rows, the best such group is taken instead. If every candidate fails, the greedy answer is returned.
|
| 132 |
|
| 133 |
### Prompt formats
|
| 134 |
|
|
|
|
| 265 |
| | |
|
| 266 |
|---|---|
|
| 267 |
| Method | A separate LoRA (rank 16, layers 1–27, all 7 projections) on the base model, trained to answer `yes` / `no` |
|
| 268 |
+
| Data | The generator's own candidates (8 per question) on 10,458 questions: 3,484 BIRD-train and 2,974 Spider-train questions the generator never trained on, plus 4,000 **SynSQL-2.5M** questions. Labels come from executing each candidate against the gold query. 19,491 training examples (32% yes); 10% of databases held out for validation and for picking the vote weight. |
|
| 269 |
| Optimisation | AdamW, LR 1e-4 → 1e-5 (linear), 1 epoch (2,437 updates, effective batch 8), clipping 1.0 |
|
| 270 |
| Hardware / time | Apple M5 Pro 24 GB; about 16 h to generate candidates + 9.2 h to train |
|
| 271 |
|
|
|
|
| 283 |
|---|---|
|
| 284 |
| Metric | Execution accuracy: the predicted query's result rows, compared as a **set** with the gold query's rows (like BIRD's official evaluator, which ignores row order and duplicates). 30 s timeout per query, read-only database. |
|
| 285 |
| Prompt | Schema as `CREATE TABLE` statements with 3 example rows per table (values cut at 40 characters), BIRD's hint text, the question |
|
| 286 |
+
| Decoding | Greedy for the draft and for candidate 1; T 0.8, top-p 0.95 for the 15 sampled candidates; max 512 new tokens |
|
| 287 |
+
| Selection hygiene | Every choice (pruning, repair, value snapping, the empty-result rule, number of candidates, verifier weight) was made on a tuning set from held-out training databases or on held-out-database verifier data. Dev was used once per milestone, for reporting only, except for two final choices made by rules set before the run: verifier2 vs verifier3, and 8 vs 16 candidates (see Results). |
|
| 288 |
|
| 289 |
The Spider numbers use the same set-based comparison, not Spider's official test-suite evaluation, which also checks row order for `ORDER BY` queries. They may read slightly higher than official Spider EX.
|
| 290 |
|
|
|
|
| 292 |
|
| 293 |
- **SQLite only, English only.** Trained and evaluated on SQLite dialect and English questions. Other dialects (Postgres, BigQuery, Snowflake) were not tested.
|
| 294 |
- **Benchmark-style data.** Training data comes from BIRD, Spider and synthetic SynSQL databases. Real enterprise schemas (hundreds of tables, cryptic names, no hints) will be harder; Spider 2.0-style warehouse tasks are out of scope.
|
| 295 |
+
- **About 42% of BIRD questions are still answered wrong.** Typical errors: a column taken from the wrong table, a wrong join path, a misread hint, and multi-step logic on "challenging" questions (43.4%). An audit of the tuning set found that about 1 in 10 BIRD gold queries is itself wrong or ambiguous, so the reachable ceiling is below 100%.
|
| 296 |
- **The full pipeline needs database access.** It executes candidate queries, so it needs a live (read-only) connection. Without one, use the single-answer mode (44.9 / 74.7 with pruning and repair, or 40.8 / 73.4 plain).
|
| 297 |
+
- **Harder, hint-free questions score much lower.** On the 2026 revision of BIRD mini-dev (SQLite, 500 questions, 460 of them "challenging", no hints), the 8-candidate pipeline scores 4.6 EX, and at least one of the 8 candidates is correct for only 7.4%. About 22% of greedy answers there reference columns that don't exist. SQLant relies heavily on BIRD's hint text.
|
| 298 |
+
- **Cost.** The full pipeline runs 17 generations per question (1 draft, 1 greedy, 15 samples) plus ~3 verifier passes: about 20–25 s per question on an M5 Pro. With 8 candidates (`N_SAMPLES = 7`, `ALPHA = 1.5` in `code/sqlant/pipeline.py`) it is about 1.8× faster and scores 55.7 / 76.0.
|
| 299 |
- **The verifier's score is not a calibrated probability.** It's used only to rank candidates against each other.
|
| 300 |
|
| 301 |
## Safe use
|
code/README.md
CHANGED
|
@@ -7,14 +7,14 @@ SQLant-1B is a 1.5B text-to-SQL system: **one** base model, [`Qwen/Qwen2.5-Coder
|
|
| 7 |
|
| 8 |
Total weights in memory: 1.54B (base) + 2 × 18M (adapters).
|
| 9 |
|
| 10 |
-
**BIRD dev (full, 1,534 questions):
|
| 11 |
|
| 12 |
## Resources
|
| 13 |
|
| 14 |
| | |
|
| 15 |
|---|---|
|
| 16 |
| GPU | 1 × A100 80 GB. Any GPU with 8 GB or more works; peak memory is about 5 GB. |
|
| 17 |
-
| Time | About
|
| 18 |
| Disk | 3.1 GB base model + 140 MB adapters |
|
| 19 |
| Network | Only to download the base model from Hugging Face on first run. Inference makes **no** network calls and sends no data anywhere. |
|
| 20 |
| `column_meaning.json` | **Not used.** |
|
|
@@ -52,11 +52,11 @@ python compare.py --data dev.json --db_root dev_databases predict_dev.json.progr
|
|
| 52 |
|
| 53 |
1. **Draft:** the generator writes a greedy SQL from the full schema (`CREATE TABLE` statements + 3 example rows per table), the hint and the question.
|
| 54 |
2. **Schema pruning:** keeps tables matched by name, by database values mentioned in the question or hint, by the draft SQL, plus foreign-key bridges. Falls back to the full schema when unsure.
|
| 55 |
-
3. **Candidates:** 1 greedy +
|
| 56 |
4. **Repair and value snapping** (no model): fixes `T1.col` pointing to a table that lacks `col`, and replaces literals that don't occur in their column with the stored spelling (for example `'Non-essential'` → `'Non-Essential'`).
|
| 57 |
5. **Execute** each candidate (read-only, 15 s timeout) and group candidates by result.
|
| 58 |
6. **Verify:** if there are two or more groups, the verifier scores one SQL per group, `v = logit(yes) − logit(no)`.
|
| 59 |
-
7. **Pick** the group with the highest `v + 1.
|
| 60 |
|
| 61 |
## Files
|
| 62 |
|
|
|
|
| 7 |
|
| 8 |
Total weights in memory: 1.54B (base) + 2 × 18M (adapters).
|
| 9 |
|
| 10 |
+
**BIRD dev (full, 1,534 questions): 58.3 EX.**
|
| 11 |
|
| 12 |
## Resources
|
| 13 |
|
| 14 |
| | |
|
| 15 |
|---|---|
|
| 16 |
| GPU | 1 × A100 80 GB. Any GPU with 8 GB or more works; peak memory is about 5 GB. |
|
| 17 |
+
| Time | About 20–25 s per question on an Apple M5 Pro (PyTorch, MPS). Expected to be considerably faster on an A100. 1,789 test questions ≈ 10–12 h on the M5 Pro. |
|
| 18 |
| Disk | 3.1 GB base model + 140 MB adapters |
|
| 19 |
| Network | Only to download the base model from Hugging Face on first run. Inference makes **no** network calls and sends no data anywhere. |
|
| 20 |
| `column_meaning.json` | **Not used.** |
|
|
|
|
| 52 |
|
| 53 |
1. **Draft:** the generator writes a greedy SQL from the full schema (`CREATE TABLE` statements + 3 example rows per table), the hint and the question.
|
| 54 |
2. **Schema pruning:** keeps tables matched by name, by database values mentioned in the question or hint, by the draft SQL, plus foreign-key bridges. Falls back to the full schema when unsure.
|
| 55 |
+
3. **Candidates:** 1 greedy + 15 sampled (temperature 0.8, top-p 0.95) SQL queries from the pruned prompt (16 in total).
|
| 56 |
4. **Repair and value snapping** (no model): fixes `T1.col` pointing to a table that lacks `col`, and replaces literals that don't occur in their column with the stored spelling (for example `'Non-essential'` → `'Non-Essential'`).
|
| 57 |
5. **Execute** each candidate (read-only, 15 s timeout) and group candidates by result.
|
| 58 |
6. **Verify:** if there are two or more groups, the verifier scores one SQL per group, `v = logit(yes) − logit(no)`.
|
| 59 |
+
7. **Pick** the group with the highest `v + 1.0·log(votes)`. If that group returns no rows and another returns rows, the best such group is taken instead.
|
| 60 |
|
| 61 |
## Files
|
| 62 |
|
code/sqlant/pipeline.py
CHANGED
|
@@ -23,8 +23,9 @@ from .schema_format import build_prompt, schema_text
|
|
| 23 |
|
| 24 |
SYSTEM = "You are an expert SQLite developer who writes correct, efficient SQL."
|
| 25 |
VSYS = "You are an expert SQLite reviewer. Decide whether the candidate SQL correctly answers the question."
|
| 26 |
-
N_SAMPLES, TEMP, TOP_P, MAX_TOKENS =
|
| 27 |
-
|
|
|
|
| 28 |
QUERY_TIMEOUT_S = 15
|
| 29 |
|
| 30 |
|
|
@@ -138,7 +139,9 @@ def answer(backend, db, question, evidence):
|
|
| 138 |
draft = extract_sql(backend.generate(chat_messages(full_prompt(db, question, evidence)), 1, 0.0)[0])
|
| 139 |
prompt = pruned_prompt(db, question, evidence, draft)
|
| 140 |
msgs = chat_messages(prompt)
|
| 141 |
-
texts = backend.generate(msgs, 1, 0.0)
|
|
|
|
|
|
|
| 142 |
cands = [extract_sql(t) for t in texts]
|
| 143 |
results = [execute(db, c) for c in cands]
|
| 144 |
final, info = select(prompt, cands, results, backend.score)
|
|
|
|
| 23 |
|
| 24 |
SYSTEM = "You are an expert SQLite developer who writes correct, efficient SQL."
|
| 25 |
VSYS = "You are an expert SQLite reviewer. Decide whether the candidate SQL correctly answers the question."
|
| 26 |
+
N_SAMPLES, TEMP, TOP_P, MAX_TOKENS = 15, 0.8, 0.95, 512 # 1 greedy + 15 sampled = 16 candidates
|
| 27 |
+
SAMPLE_BATCH = 8 # samples per generate() call, bounds peak memory on long schemas
|
| 28 |
+
ALPHA = 1.0 # chosen on held-out-database questions for 16 candidates (results/cand16)
|
| 29 |
QUERY_TIMEOUT_S = 15
|
| 30 |
|
| 31 |
|
|
|
|
| 139 |
draft = extract_sql(backend.generate(chat_messages(full_prompt(db, question, evidence)), 1, 0.0)[0])
|
| 140 |
prompt = pruned_prompt(db, question, evidence, draft)
|
| 141 |
msgs = chat_messages(prompt)
|
| 142 |
+
texts = backend.generate(msgs, 1, 0.0)
|
| 143 |
+
for k in range(0, N_SAMPLES, SAMPLE_BATCH):
|
| 144 |
+
texts += backend.generate(msgs, min(SAMPLE_BATCH, N_SAMPLES - k), TEMP)
|
| 145 |
cands = [extract_sql(t) for t in texts]
|
| 146 |
results = [execute(db, c) for c in cands]
|
| 147 |
final, info = select(prompt, cands, results, backend.score)
|