Text Generation
PEFT
Safetensors
English
Chinese
text-to-sql
nl2sql
sql
lora
small-language-model
qwen2.5-coder
dpo
postgresql
mysql
sqlite
ollama
llama-cpp
local-llm
conversational
Eval Results (legacy)
Run this model with HF Jobs
Run xiain/SwiftSQL-3B-LoRA on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/xiain/SwiftSQL-3B-LoRA. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/xiain/SwiftSQL-3B-LoRA on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/xiain/SwiftSQL-3B-LoRA. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/xiain/SwiftSQL-3B-LoRA. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use xiain/SwiftSQL-3B-LoRA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use xiain/SwiftSQL-3B-LoRA with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/Qwen2.5-Coder-3B-Instruct-bnb-4bit") model = PeftModel.from_pretrained(base_model, "xiain/SwiftSQL-3B-LoRA") - Notebooks
- Google Colab
- Kaggle
docs: update Model Card with plain-language advantages, cross-platform guide & benchmarks
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210---base_model: unsloth/Qwen2.5-Coder-3B-Instructlibrary_name: peftpipeline_tag: text-generationtags:- base_model:adapter:unsloth/Qwen2.5-Coder-3B-Instruct- dpo- lora- transformers- trl- unsloth---# Model Card for Model ID<!-- Provide a quick summary of what the model is/does. -->## Model Details### Model Description<!-- Provide a longer summary of what this model is. -->- **Developed by:** [More Information Needed]- **Funded by [optional]:** [More Information Needed]- **Shared by [optional]:** [More Information Needed]- **Model type:** [More Information Needed]- **Language(s) (NLP):** [More Information Needed]- **License:** [More Information Needed]- **Finetuned from model [optional]:** [More Information Needed]### Model Sources [optional]<!-- Provide the basic links for the model. -->- **Repository:** [More Information Needed]- **Paper [optional]:** [More Information Needed]- **Demo [optional]:** [More Information Needed]## Uses<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->### Direct Use<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->[More Information Needed]### Downstream Use [optional]<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->[More Information Needed]### Out-of-Scope Use<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->[More Information Needed]## Bias, Risks, and Limitations<!-- This section is meant to convey both technical and sociotechnical limitations. -->[More Information Needed]### Recommendations<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.## How to Get Started with the ModelUse the code below to get started with the model.[More Information Needed]## Training Details### Training Data<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->[More Information Needed]### Training Procedure<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->#### Preprocessing [optional][More Information Needed]#### Training Hyperparameters- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->#### Speeds, Sizes, Times [optional]<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->[More Information Needed]## Evaluation<!-- This section describes the evaluation protocols and provides the results. -->### Testing Data, Factors & Metrics#### Testing Data<!-- This should link to a Dataset Card if possible. -->[More Information Needed]#### Factors<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->[More Information Needed]#### Metrics<!-- These are the evaluation metrics being used, ideally with a description of why. -->[More Information Needed]### Results[More Information Needed]#### Summary## Model Examination [optional]<!-- Relevant interpretability work for the model goes here -->[More Information Needed]## Environmental Impact<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).- **Hardware Type:** [More Information Needed]- **Hours used:** [More Information Needed]- **Cloud Provider:** [More Information Needed]- **Compute Region:** [More Information Needed]- **Carbon Emitted:** [More Information Needed]## Technical Specifications [optional]### Model Architecture and Objective[More Information Needed]### Compute Infrastructure[More Information Needed]#### Hardware[More Information Needed]#### Software[More Information Needed]## Citation [optional]<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->**BibTeX:**[More Information Needed]**APA:**[More Information Needed]## Glossary [optional]<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->[More Information Needed]## More Information [optional][More Information Needed]## Model Card Authors [optional][More Information Needed]## Model Card Contact[More Information Needed]### Framework versions- PEFT 0.21.2123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142---license: apache-2.0base_model: Qwen/Qwen2.5-Coder-3B-Instructlanguage:- en- zhpipeline_tag: text-generationtags:- text-to-sql- nl2sql- sql- gguf- small-language-model- qwen2.5-coder- dpo- postgresql- mysql- sqlite- ollama- llama-cpp- local-llmdatasets:- gretelai/synthetic_text_to_sql- trl-lab/SQaLe-text-to-SQL-dataset- jtjt520j/CSpider_and_DUSQL_sql_create_context---# ⚡ SwiftSQL-3B (LoRA Adapter)**A fast, accurate, bilingual (English & Chinese), multi-dialect (PostgreSQL / MySQL / SQLite) lightweight Text-to-SQL model — built to drop straight into real business databases and automation workflows.****轻量、极速、不瞎编字段的中英双语 Text-to-SQL 模型(仅 1.8GB 起步)——Windows / Mac / Linux 普通电脑、笔记本、消费级显卡甚至纯 CPU 都能流畅离线运行,开发者拿过去就能直接接进中小型业务库或 Dify / n8n 自动化工作流。**- **GitHub (Full Code, Benchmarks & Ready-to-Use FastAPI Guardrail Gateway)**: [github.com/2422725977/swift-sql](https://github.com/2422725977/swift-sql)- **GGUF Quantized Models**: [`xiain/SwiftSQL-3B-GGUF`](https://huggingface.co/xiain/SwiftSQL-3B-GGUF)- **LoRA Adapter**: [`xiain/SwiftSQL-3B-LoRA`](https://huggingface.co/xiain/SwiftSQL-3B-LoRA)---## ✨ Why SwiftSQL? / 5 大实用优势1. **🛡️ Refuses Missing Columns Instead of Hallucinating (`98.77%` Refusal F1)**: When a user asks for a column that doesn't exist in your schema (e.g., asking for `phone` when only `name` & `city` exist), SwiftSQL honestly returns `"answerable": false` and lists missing fields — vs `67.69%` for Base-3B, `9.52%` for XiYanSQL-3B, and `0.00%` for Arctic-R1-7B.2. **⚡ Runs on Any Everyday Hardware (4.6× Faster & 5.7× Fewer Tokens than 7B CoT)**: Only **1.80 GB (`Q4_K_M`)** to **3.06 GB (`Q8_0`)**. Runs smoothly on 8GB–16GB laptops (Windows / Mac / Linux), 4GB+ consumer GPUs, or even CPU-only machines — with **13.8× higher batch throughput** than Arctic-R1-7B.3. **🎯 +10.73% Execution Accuracy Jump over Base 3B**: Reaches **70.15% Execution Accuracy** (with 1-shot self-repair) vs **59.42%** for Base-3B on held-out multi-dialect execution evaluation.4. **🌍 Standard DDL In, Production Dialects Out (EN & ZH)**: Paste standard `CREATE TABLE` DDL directly (no custom schema converter needed) and target **PostgreSQL**, **MySQL**, or **SQLite** in English or Chinese.5. **📦 100% Strict JSON + Built-in Self-Repair**: Always outputs clean, directly parseable JSON with zero conversational filler, and natively supports 1-shot SQL error repair (`Task: repair_sql`).---## 📊 Benchmarks / 实测对比### 1. Held-Out Multi-Dialect & Refusal Progression (300 Samples)| Metric | Base-3B | **SwiftSQL-3B** | **SwiftSQL-3B + 1-Shot Repair** | Improvement || :--- | :---: | :---: | :---: | :---: || **Execution Accuracy (EX)** | 59.42% | 69.15% | **70.15%** | **+10.73%** || **Refusal F1 (Anti-Hallucination)** | 0.00% | **90.41%** | **90.41%** | **+90.41%** || **Strict JSON Compliance** | 100.0% | **100.0%** | **100.0%** | Zero filler || **Multi-Dialect Syntax Valid** | 99.63% | **97.38%** | **97.38%** | Production-ready |### 2. Head-to-Head Public Benchmark (`BIRD Mini-Dev 2026` + Fair Missing-Column Refusal)| Benchmark Metric | **SwiftSQL-3B** | Base-3B | XiYanSQL-3B | Arctic-R1-7B *(7B)* || :--- | :---: | :---: | :---: | :---: || **Refusal F1 (Missing-Column Stress)** | **98.77%** 🏆 | 67.69% | 9.52% | 0.00% || **BIRD Truncated-Schema SQLite EX\*** | **4.32%** *(1st in 3B)* | 3.09% | 3.70% | 8.02% || **Avg Output Tokens** *(lower is faster)* | **98.9** | 81.5 | 74.0 | 566.3 *(5.7×)* || **Single-Request Latency (ms, L4)** | **2,981.7** | 2,364.5 | 2,068.4 | 13,694.1 *(4.6× slower)* || **Batch Throughput (QPS, L4)** | **1.10** | 1.48 | 1.53 | 0.08 *(13.8× lower)* |> **\*Evaluation Note:** All models were evaluated under identical short-context caps (`MAX_SCHEMA_CHARS=5500`, `max_length=2560`). Because large BIRD enterprise schemas often exceed 15,000–35,000 chars with comments, truncation cut off target tables on many questions—compressing absolute EX for every model (including 7B Arctic-R1). Full reproducible script: [`notebooks/05_public_benchmark.ipynb`](https://github.com/2422725977/swift-sql/blob/main/notebooks/05_public_benchmark.ipynb).---## 📦 Available Files & Verified SHA-256| File | Size | Best For | SHA-256 (LFS) || :--- | :---: | :--- | :--- || `SwiftSQL-3B-Q8_0.gguf` | 3.06 GB | Near-lossless precision (16GB+ RAM or 6GB+ VRAM) | `dc109bac55e2c176edf47f504b2f1a95429e12b1050c2f4db3fbd8c4617dabec` || `SwiftSQL-3B-Q4_K_M.gguf` | 1.80 GB | Everyday laptops (8GB RAM / 4GB VRAM / CPU / high concurrency) | `cdb70d928434ff2dabb22382657d969cd9e2ee06243b85bb8e0edcf15b686641` || `adapter_model.safetensors` | 228 MB | LoRA (`r=64`) adapter in [`xiain/SwiftSQL-3B-LoRA`](https://huggingface.co/xiain/SwiftSQL-3B-LoRA) | `dc635d966ec92fbf347e9cc7de65cfbeaa0245a8ac04bc0350053eb36b7c65a7` |---## 🚀 30-Second Quick Start (Windows / Mac / Linux)### 1. Run with Ollama (1 Command)```bash# Near-lossless Q8_0 (3.06 GB)ollama run hf.co/xiain/SwiftSQL-3B-GGUF:Q8_0# Lightweight Q4_K_M (1.80 GB, runs easily on 8GB RAM laptops)ollama run hf.co/xiain/SwiftSQL-3B-GGUF:Q4_K_M```### 2. High-Concurrency OpenAI-Compatible API (`llama.cpp`)```bash# --parallel 4 handles 4 concurrent requests; --ctx-size 4096 fits typical business schemasllama-server -hf xiain/SwiftSQL-3B-GGUF:Q8_0 \--port 11434 --ctx-size 4096 --parallel 4 --flash-attn```### 3. Production FastAPI Gateway (Auth + Read-Only Guardrail + Auto-Repair)See [github.com/2422725977/swift-sql](https://github.com/2422725977/swift-sql) for the ready-to-use `serve/api_gateway.py` with API key auth, rate limiting, `sqlglot` read-only safety blocking, and automatic 1-shot SQL self-repair.---## 🧩 Prompt Format**System Prompt**```textYou are SwiftSQL, a fast and accurate multi-dialect Text-to-SQL engine.Rules:1. Respond ONLY with a single valid JSON object. No markdown fences or extra text.2. Follow the requested SQL dialect strictly (postgresql, mysql, or sqlite) and output read-only SELECT queries only.3. Auto-Think: leave "plan" empty ("") for simple and single-JOIN queries; only for complex multi-JOIN, subquery, CTE, HAVING, or window queries, write an ultra-brief plan (<= 60 chars) in "plan" before "sql".4. Never invent tables or columns. If the schema lacks required information to answer the question, set "answerable": false, "sql": "", and list missing fields in "missing".```**User Prompt (`generate_sql`)**```textTask: generate_sqlDialect: postgresqlMode: autoSchema:CREATE TABLE orders (id INT, user_id INT, amount NUMERIC, status TEXT);Question:统计每个用户的已完成订单总金额,按总金额降序取前 10 名```**Expected Output**```json{"answerable": true, "plan": "", "dialect": "postgresql", "sql": "SELECT user_id, SUM(amount) AS total_amount FROM orders WHERE status = 'completed' GROUP BY user_id ORDER BY total_amount DESC LIMIT 10", "tables": ["orders"]}```---## ⚠️ Scope & License- Ideal for small-to-medium schemas (≤ ~10 tables / ~4,000 DDL chars). For databases with dozens of tables, pre-filter relevant tables before querying.- Always enforce database-level read-only permissions in production alongside static SQL validation.- Released under **Apache 2.0**.
README.md+111-179