Text Generation
GGUF
English
Chinese
text-to-sql
nl2sql
sql
small-language-model
qwen2.5-coder
dpo
postgresql
mysql
sqlite
ollama
llama-cpp
local-llm
Eval Results (legacy)
conversational
Instructions to use xiain/SwiftSQL-3B-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use xiain/SwiftSQL-3B-GGUF with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf xiain/SwiftSQL-3B-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf xiain/SwiftSQL-3B-GGUF:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf xiain/SwiftSQL-3B-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf xiain/SwiftSQL-3B-GGUF:Q4_K_M
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf xiain/SwiftSQL-3B-GGUF:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama cli -hf xiain/SwiftSQL-3B-GGUF:Q4_K_M
Use Docker
docker model run hf.co/xiain/SwiftSQL-3B-GGUF:Q4_K_M
- Llama new
- LM Studio
- Jan
- vLLM
How to use xiain/SwiftSQL-3B-GGUF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "xiain/SwiftSQL-3B-GGUF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "xiain/SwiftSQL-3B-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/xiain/SwiftSQL-3B-GGUF:Q4_K_M
- Ollama
How to use xiain/SwiftSQL-3B-GGUF with Ollama:
ollama run hf.co/xiain/SwiftSQL-3B-GGUF:Q4_K_M
- Unsloth Desktop
- Pi
How to use xiain/SwiftSQL-3B-GGUF with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf xiain/SwiftSQL-3B-GGUF:Q4_K_M
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:9931/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "xiain/SwiftSQL-3B-GGUF:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use xiain/SwiftSQL-3B-GGUF with Docker Model Runner:
docker model run hf.co/xiain/SwiftSQL-3B-GGUF:Q4_K_M
- Lemonade
How to use xiain/SwiftSQL-3B-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull xiain/SwiftSQL-3B-GGUF:Q4_K_M
Run and chat with the model
lemonade run user.SwiftSQL-3B-GGUF-Q4_K_M
List all available models
lemonade list
- Hermes Agent
How to use xiain/SwiftSQL-3B-GGUF with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf xiain/SwiftSQL-3B-GGUF:Q4_K_M
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:9931/v1 hermes config set model.default xiain/SwiftSQL-3B-GGUF:Q4_K_M
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use xiain/SwiftSQL-3B-GGUF with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf xiain/SwiftSQL-3B-GGUF:Q4_K_M
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:9931/v1 \ --custom-model-id "xiain/SwiftSQL-3B-GGUF:Q4_K_M" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
File size: 8,447 Bytes
98d86ef 17898cb 98d86ef 17898cb 98d86ef 17898cb 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 98d86ef b8018d6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | ---
license: apache-2.0
base_model: Qwen/Qwen2.5-Coder-3B-Instruct
language:
- en
- zh
pipeline_tag: text-generation
tags:
- text-to-sql
- nl2sql
- sql
- gguf
- small-language-model
- qwen2.5-coder
- dpo
- postgresql
- mysql
- sqlite
- ollama
- llama-cpp
- local-llm
datasets:
- gretelai/synthetic_text_to_sql
- trl-lab/SQaLe-text-to-SQL-dataset
- jtjt520j/CSpider_and_DUSQL_sql_create_context
model-index:
- name: SwiftSQL-3B
results:
- task:
type: text-generation
name: Text-to-SQL Bilingual Multi-Dialect & Refusal (300 Holdout)
dataset:
name: SwiftSQL Bilingual Multi-Dialect Holdout (300)
type: swiftsql-holdout-300
metrics:
- type: accuracy
name: Execution Accuracy (System + 1-Shot Repair)
value: 70.15
- type: accuracy
name: Execution Accuracy (Standalone)
value: 69.15
- type: f1
name: Anti-Hallucination Refusal F1
value: 90.41
- type: accuracy
name: Strict JSON Compliance
value: 100.0
- type: accuracy
name: Multi-Dialect Syntax Validity
value: 97.38
- task:
type: text-generation
name: Text-to-SQL Public Head-to-Head Refusal Benchmark
dataset:
name: SwiftSQL Public Refusal & Efficiency Eval
type: swiftsql-public-refusal
metrics:
- type: f1
name: Anti-Hallucination Refusal F1
value: 98.77
---
# ⚡ SwiftSQL-3B (GGUF)
**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 schemas
llama-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**
```text
You 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`)**
```text
Task: generate_sql
Dialect: postgresql
Mode: auto
Schema:
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**.
|