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
|
Download README.md from Felamity-Technologies/sqlant-1b: direct link, hf CLI and curl.
- Browser
- Download file 20.8 kB
-
https://huggingface.co/Felamity-Technologies/sqlant-1b/resolve/main/README.md
- Command line
-
hf download hf://Felamity-Technologies/sqlant-1b/README.md
-
curl -L -o README.md https://huggingface.co/Felamity-Technologies/sqlant-1b/resolve/main/README.md
20.8 kB
| license: apache-2.0 | |
| base_model: Qwen/Qwen2.5-Coder-1.5B-Instruct | |
| library_name: peft | |
| pipeline_tag: text-generation | |
| language: | |
| - en | |
| tags: | |
| - text-to-sql | |
| - sql | |
| - sqlite | |
| - lora | |
| - peft | |
| - mlx | |
| - bird | |
| - spider | |
| datasets: | |
| - xlangai/spider | |
| - seeklhy/SynSQL-2.5M | |
| model-index: | |
| - name: SQLant-1B | |
| results: | |
| - task: | |
| type: text-to-sql | |
| dataset: | |
| name: BIRD dev (1,534 questions) | |
| type: bird | |
| split: dev | |
| metrics: | |
| - type: execution_accuracy | |
| value: 58.3 | |
| name: EX (full pipeline, 16 candidates + verifier + value snapping) | |
| - type: execution_accuracy | |
| value: 44.9 | |
| name: EX (single answer, pruning + repair) | |
| - task: | |
| type: text-to-sql | |
| dataset: | |
| name: Spider dev (1,034 questions) | |
| type: spider | |
| split: dev | |
| metrics: | |
| - type: execution_accuracy | |
| value: 77.2 | |
| name: EX (full pipeline, 16 candidates + verifier + value snapping) | |
| - type: execution_accuracy | |
| value: 74.7 | |
| name: EX (single answer, pruning + repair) | |
| # SQLant-1B | |
| SQLant-1B is a small text-to-SQL system for **SQLite**. Given a database schema, an optional hint, and a question in English, it writes one SQL query that answers the question. It runs locally: with PyTorch (`transformers` + `peft`, on CUDA, Apple MPS or CPU) or with MLX on Apple Silicon. It was developed on an Apple M5 Pro with 24 GB. | |
| It is made of two LoRA adapters on the same base model, [`Qwen/Qwen2.5-Coder-1.5B-Instruct`](https://huggingface.co/Qwen/Qwen2.5-Coder-1.5B-Instruct), plus a small amount of non-learned code: | |
| | Component | What it does | Size | | |
| |---|---|---| | |
| | **Generator** (`generator/`) | Writes SQL from the schema and question | LoRA, rank 16, 68 MB | | |
| | **Verifier** (`verifier/`) | Reads one candidate SQL and its first result rows, and answers "yes" or "no" to "is this correct?" | LoRA, rank 16, 68 MB | | |
| | Schema pruning, SQL repair, value snapping | Non-learned code (`code/`): shrinks the prompt to relevant tables, fixes wrong table aliases and missing joins, corrects literal spellings | β | | |
| ``` | |
| sqlant-1b/ | |
| βββ README.md | |
| βββ generator/ adapter_config.json, adapter_model.safetensors (PEFT LoRA, layers 1β27) | |
| βββ verifier/ adapter_config.json, adapter_model.safetensors (PEFT LoRA, layers 1β27) | |
| βββ mlx/generator/ adapter_config.json, adapters.safetensors (same weights, MLX format) | |
| βββ mlx/verifier/ adapter_config.json, adapters.safetensors | |
| βββ code/ full pipeline: run.py (BIRD-format runner), sqlant/ (pruning, repair, prompts, selection) | |
| ``` | |
| The base model is not included; it downloads from Hugging Face on first use. Both adapters are loaded on **one** copy of the base and switched at runtime, so the whole system is 1.54B + 2 Γ 18M parameters. | |
| "1B" is the size class. The base model has 1.54B parameters (1.31B without embeddings). | |
| ## Results | |
| 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. | |
| | Configuration | BIRD dev | Spider dev | Generations per question | | |
| |---|---|---|---| | |
| | Base model, no fine-tuning | 29.5 | 65.4 | 1 | | |
| | Generator, single answer | 40.8 | 73.4 | 1 | | |
| | Generator + schema pruning + SQL repair | 44.9 | 74.7 | 2 | | |
| | + 8 candidates, self-consistency (majority vote on results) | 51.2 | 75.4 | 9 | | |
| | + verifier rerank | 53.3 (95% CI 50.8β55.7) | 77.2 (74.5β79.6) | 9, plus ~2.3 verifier passes | | |
| | + value snapping + empty-result rule | 54.1 (51.6β56.6) | 74.8 (72.1β77.4) | same | | |
| | + verifier trained on twice the data | 55.7 (53.2β58.1) | 76.0 (73.3β78.5) | same | | |
| | **+ 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 | | |
| | *Oracle@8: upper bound, at least one of 8 candidates is correct* | *64.9* | *86.2* | | | |
| | *Oracle@16: upper bound, at least one of 16 candidates is correct* | *71.1* | *89.6* | | | |
| - **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). | |
| - **Value snapping + the empty-result rule add 0.8 on BIRD** (14 questions fixed, 1 broken). | |
| - **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. | |
| - **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. | |
| - **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. | |
| - **BIRD by difficulty** (full pipeline): simple 65.9 Β· moderate 47.6 Β· challenging 43.4. | |
| - **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. | |
| - **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. | |
| ### Comparison with published models (BIRD dev EX) | |
| Other systems' numbers come from their papers and model cards, with their own prompts and setups, so differences of 1β2 points mean little. | |
| | Model | Size | BIRD dev | Spider dev | | |
| |---|---|---|---| | |
| | Prem-1B-SQL | 1.3B | 46 | 85 | | |
| | CodeS-1B (SFT) | 1B | 50.5 | 77.9 | | |
| | SLM-SQL-0.5B | 0.5B | 56.9 | β | | |
| | **SQLant-1B (this model)** | 1.5B | **58.3** | **77.2**ΒΉ | | |
| | OmniSQL-7B | 7B | 63.9 (66.1 with voting) | 81.2Β² | | |
| | SLM-SQL-1.5B (same base, SFT + GRPO + voting) | 1.5B | 67.1 | β | | |
| ΒΉ 78.8 without `flight_2`, whose gold answers are empty because of whitespace in the stored values (see above). | |
| Β² Test-suite accuracy, which is stricter than the execution accuracy in the other rows, so it is not directly comparable. | |
| 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. | |
| ## How it works | |
| For each question: | |
| 1. **Draft.** The generator writes one query (greedy) from the full schema. | |
| 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. | |
| 3. **Generate 16 candidates.** On the pruned prompt: 1 greedy answer plus 15 samples (temperature 0.8, top-p 0.95). | |
| 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. | |
| 5. **Group** the candidates by their result rows. | |
| 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. | |
| 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. | |
| ### Prompt formats | |
| **Generator.** One user turn in Qwen's chat template: | |
| ~~~text | |
| You are an expert SQLite developer who writes correct, efficient SQL. | |
| Database schema (SQLite): | |
| CREATE TABLE ... ; -- one block per (kept) table | |
| /* 3 example rows from <table>: | |
| col1 | col2 | ... | |
| ... */ | |
| External knowledge: <hint> (omit the line if there is no hint) | |
| Question: <question> | |
| Write one SQLite query that answers the question. Return only the SQL inside a ```sql code block, with no explanation. | |
| ~~~ | |
| **Verifier.** One user turn; it answers the single token `yes` or `no`: | |
| ~~~text | |
| You are an expert SQLite reviewer. Decide whether the candidate SQL correctly answers the question. | |
| Database schema (SQLite): | |
| <same pruned schema> | |
| External knowledge: <hint> | |
| Question: <question> | |
| Candidate SQL: | |
| ```sql | |
| <repaired SQL> | |
| ``` | |
| Execution result (first rows): | |
| <up to 5 rows, " | "-separated, cells cut at 60 characters> | |
| (<N> rows) or "... (<N> rows in total)" or "(no rows)" | |
| Is the candidate SQL correct? Answer yes or no. | |
| ~~~ | |
| ## Usage | |
| ### Full pipeline (PyTorch or MLX) | |
| ```bash | |
| huggingface-cli download Felamity-Technologies/sqlant-1b --local-dir sqlant-1b | |
| cd sqlant-1b/code | |
| pip install -r requirements.txt # PyTorch backend; add mlx-lm for --backend mlx | |
| python run.py --data dev.json --db_root dev_databases --out predict_dev.json | |
| ``` | |
| The input is a BIRD-style JSON list with `question`, `evidence` (optional hint) and `db_id`; databases are read from `<db_root>/<db_id>/<db_id>.sqlite`. The output maps each question's index to `"<SQL>\t----- bird -----\t<db_id>"`. Progress is saved after every question, and re-running the same command resumes. Peak memory is about 5 GB. | |
| ### PyTorch: loading the adapters | |
| ```python | |
| import torch | |
| from peft import PeftModel | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| BASE, REPO = "Qwen/Qwen2.5-Coder-1.5B-Instruct", "Felamity-Technologies/sqlant-1b" | |
| tok = AutoTokenizer.from_pretrained(BASE) | |
| model = AutoModelForCausalLM.from_pretrained(BASE, torch_dtype=torch.bfloat16) | |
| model = PeftModel.from_pretrained(model, REPO, subfolder="generator", adapter_name="generator") | |
| model.load_adapter(REPO, subfolder="verifier", adapter_name="verifier") | |
| model.set_adapter("generator") # or "verifier" | |
| ``` | |
| When generating, pass `repetition_penalty=1.0` and `top_k=0`. The base model's `generation_config.json` otherwise applies `repetition_penalty=1.1` and `top_k=20`, which were not used in training or evaluation. | |
| ### MLX | |
| ```bash | |
| pip install mlx-lm | |
| ``` | |
| **Single answer** (generator only): | |
| ```python | |
| from mlx_lm import load, generate | |
| SYSTEM = "You are an expert SQLite developer who writes correct, efficient SQL." | |
| model, tok = load("Qwen/Qwen2.5-Coder-1.5B-Instruct", adapter_path="sqlant-1b/mlx/generator") | |
| user = (f"{SYSTEM}\n\nDatabase schema (SQLite):\n{schema}\n\n" | |
| + (f"External knowledge: {hint}\n\n" if hint else "") | |
| + f"Question: {question}\n\n" | |
| "Write one SQLite query that answers the question. " | |
| "Return only the SQL inside a ```sql code block, with no explanation.") | |
| ids = tok.apply_chat_template([{"role": "user", "content": user}], add_generation_prompt=True) | |
| print(generate(model, tok, prompt=ids, max_tokens=512)) | |
| ``` | |
| **Scoring one candidate with the verifier:** | |
| ```python | |
| import mlx.core as mx | |
| from mlx_lm import load | |
| vmodel, vtok = load("Qwen/Qwen2.5-Coder-1.5B-Instruct", adapter_path="sqlant-1b/mlx/verifier") | |
| yes, no = vtok.encode("yes")[0], vtok.encode("no")[0] | |
| ids = vtok.apply_chat_template([{"role": "user", "content": verifier_prompt}], add_generation_prompt=True) | |
| logits = vmodel(mx.array([ids]))[0, -1] | |
| score = (logits[yes] - logits[no]).item() # higher = more likely correct | |
| ``` | |
| The full pipeline is in `code/`: | |
| - schema pruning, repair and value snapping: `code/sqlant/schema_tools.py`; | |
| - prompt format: `code/sqlant/schema_format.py`; | |
| - candidates, execution, grouping and verifier selection: `code/sqlant/pipeline.py`; | |
| - backends: `code/sqlant/backend_torch.py` and `code/sqlant/backend_mlx.py`. | |
| To get a standalone generator model, fuse the adapter: `python -m mlx_lm fuse --model Qwen/Qwen2.5-Coder-1.5B-Instruct --adapter-path sqlant-1b/mlx/generator --save-path sqlant-1b-generator`, or `merge_and_unload()` in PEFT. Don't fuse both adapters into one model; they are separate tasks. | |
| ## Training | |
| ### Generator | |
| | | | | |
| |---|---| | |
| | Method | LoRA SFT, rank 16, scale 1.0, dropout 0.05, all 7 linear projections on transformer layers 1β27. Loss on the SQL answer only. | | |
| | Data | 9,410 examples: the first 5 of 8 balanced shards of a 15,056-example set from **BIRD train** (7,287) and **Spider train** (7,769). Every gold query was execution-checked. 21 training databases were held out as a tuning set. No dev data. | | |
| | Optimisation | AdamW, peak LR 1e-5, 50-update warmup, cosine schedule; stopped after 1,180 updates (effective batch 8). Gradient clipping 1.0. | | |
| | Checkpoint choice | Best of 8 shards on the tuning set (300 questions from held-out training databases) | | |
| | Hardware / time | Apple M5 Pro 24 GB, MLX bf16 with fp32 attention; about 3 hours | | |
| ### Verifier | |
| | | | | |
| |---|---| | |
| | Method | A separate LoRA (rank 16, layers 1β27, all 7 projections) on the base model, trained to answer `yes` / `no` | | |
| | 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. | | |
| | Optimisation | AdamW, LR 1e-4 β 1e-5 (linear), 1 epoch (2,437 updates, effective batch 8), clipping 1.0 | | |
| | Hardware / time | Apple M5 Pro 24 GB; about 16 h to generate candidates + 9.2 h to train | | |
| ### Training notes for MLX users | |
| Three issues in mlx-lm 0.32.2 / mlx 0.32.4 silently broke LoRA training on this base model. Each looked like "the method doesn't help": | |
| 1. **Loss mask off by one.** The default loss also trains on one padding token after each answer, which is ruinous for one-token targets. | |
| 2. **Layer-0 gradients explode** (1e12+) in bf16 on Qwen2.5's q/k/v LoRA. With gradient clipping this silently zeroes all updates. Fix: skip layer 0. | |
| 3. **bf16 attention backward gives noisy gradients**, which makes training drift after about 700 updates at any learning rate. Fix: compute attention in fp32 (same speed, fits in 24 GB). | |
| ## Evaluation protocol | |
| | | | | |
| |---|---| | |
| | 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. | | |
| | Prompt | Schema as `CREATE TABLE` statements with 3 example rows per table (values cut at 40 characters), BIRD's hint text, the question | | |
| | 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 | | |
| | 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). | | |
| 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. | |
| ## Limitations | |
| - **SQLite only, English only.** Trained and evaluated on SQLite dialect and English questions. Other dialects (Postgres, BigQuery, Snowflake) were not tested. | |
| - **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. | |
| - **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%. | |
| - **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). | |
| - **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. | |
| - **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. | |
| - **The verifier's score is not a calibrated probability.** It's used only to rank candidates against each other. | |
| ## Safe use | |
| SQLant-1B writes SQL that the pipeline **executes**. Always run generated queries with a **read-only** connection or on a copy of the database. The pipeline itself never writes, but a model can produce `UPDATE`/`DELETE`/`DROP` if asked. Review queries before running them on data you care about, and don't use it as the only safeguard for access control. | |
| ## Licence and data | |
| - **Adapters:** Apache 2.0, the same as the base model [Qwen2.5-Coder-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-1.5B-Instruct). | |
| - **Training data:** | |
| - [BIRD](https://bird-bench.github.io) train: CC BY-SA 4.0. | |
| - [Spider](https://yale-lily.github.io/spider) train: CC BY-SA 4.0. | |
| - [SynSQL-2.5M](https://huggingface.co/datasets/seeklhy/SynSQL-2.5M) (OmniSQL), verifier only: Apache 2.0 per the OmniSQL release. | |
| Check these licences against your intended use. | |
| ## References | |
| - Qwen2.5-Coder: [Qwen/Qwen2.5-Coder-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-1.5B-Instruct) | |
| - BIRD: Li et al., *Can LLM Already Serve as A Database Interface? A BIg Bench for Large-Scale Database Grounded Text-to-SQLs*, [arXiv 2305.03111](https://arxiv.org/abs/2305.03111) | |
| - Spider: Yu et al., *Spider: A Large-Scale Human-Labeled Dataset for Complex and Cross-Domain Semantic Parsing and Text-to-SQL Task*, EMNLP 2018 | |
| - OmniSQL / SynSQL-2.5M: Li et al., [arXiv 2503.02240](https://arxiv.org/abs/2503.02240) | |
| - SLM-SQL: [arXiv 2507.22478](https://arxiv.org/abs/2507.22478) | |