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"
docs: update Model Card with plain-language advantages, cross-platform guide & benchmarks
Browse files6 unmodified lines7891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889905 unmodified lines9697989910010110210 unmodified lines1131141151161171181191201211221231241251261271281291301311321331341351361376 unmodified linespipeline_tag: text-generationtags:- text-to-sql- sql- gguf- qwen2.5-coder- dpo- rpo- postgresql- mysql- sqlite- ollama- llama-cpp- apple-silicondatasets:- gretelai/synthetic_text_to_sql- trl-lab/SQaLe-text-to-SQL-dataset- jtjt520j/CSpider_and_DUSQL_sql_create_context---# SwiftSQL-3B (GGUF)**SwiftSQL-3B** is a fast, accurate, bilingual (**English & Chinese**), multi-dialect (**PostgreSQL / MySQL / SQLite**) lightweight Text-to-SQL model fine-tuned from [`Qwen/Qwen2.5-Coder-3B-Instruct`](https://huggingface.co/Qwen/Qwen2.5-Coder-3B-Instruct) via **SQLite-sandbox-verified SFT + RPO-stabilized Iterative Execution-Guided DPO**.Designed specifically to run comfortably on **16GB Apple Silicon (Mac mini / MacBook)** and consumer GPUs, while serving production-grade APIs with built-in **anti-hallucination refusal** and **1-shot SQL self-repair**.- **Code, Training Pipeline & FastAPI Guardrail Gateway**: [github.com/2422725977/swift-sql](https://github.com/2422725977/swift-sql)---## Key Advantages / 核心优势1. **+10.7% Execution Accuracy over Base 3B**: Trained on sandbox-verified executable SQL + iterative execution-guided RPO-DPO (`rpo_alpha=0.5`), pushing 3B execution accuracy from **59.42% → 70.15%** (with 1-shot self-repair).2. **Anti-Hallucination Refusal (`0% → 90.41%` F1)**: Unlike standard open Text-to-SQL models that blindly fabricate missing columns, SwiftSQL explicitly returns `"answerable": false` and lists missing schema columns.3. **Fast Auto-Think (Low Latency)**: Skips verbose Chain-of-Thought (`"plan": ""`) on simple and single-JOIN queries; emits an ultra-compact `<= 60`-char telegraphic plan only for complex multi-JOIN / CTE / subquery / window queries.4. **Native Multi-Dialect & Bilingual (EN/ZH)**: Accepts standard `CREATE TABLE` DDL directly (no custom M-Schema conversion required) and explicitly targets `postgresql`, `mysql`, or `sqlite`.5. **Single-Model Generate + 1-Shot SQL Self-Repair + Strict JSON**: Always outputs a single parseable JSON object (`100%` JSON compliance in eval) and natively supports `Task: repair_sql` when paired with a lightweight `sqlglot` or DB error guardrail.---## Verified Benchmark Results (3B `opt2`, 300-sample Held-Out Multi-Dialect + Refusal Eval)| Metric | Base `3B` | V1 SFT (Sandbox-Cleaned) | V2 R1 (RPO-DPO) | **V2 R2 (Exported)** | **Best + 1-Shot Repair** || :--- | :---: | :---: | :---: | :---: | :---: || **Execution Accuracy (EX)** | 59.42% | 67.63% | 71.28% | **69.15%** | **70.15%** (+10.73%) || **Refusal F1 (Anti-Hallucination)** | 0.00% | 80.00% | 67.35% | **90.41%** | **90.41%** (+90.41%) || **Strict JSON Compliance** | 100.0% | 100.0% | 100.0% | **100.0%** | **100.0%** || **Multi-Dialect Syntax Valid** | 99.63% | 100.0% | 88.01% | **97.38%** | **97.38%** || **Avg Output Length (chars)** | 177.9 | 222.3 | 210.5 | **216.6** | **217.3** |> *Evaluation runs generated queries transpiled back to an isolated in-memory SQLite sandbox against held-out schemas & seed data, plus bilingual and missing-column refusal tests.*---## Available GGUF Files| File | Size | Recommendation || :--- | :---: | :--- || `SwiftSQL-3B-Q4_K_M.gguf` | 1.80 GB | Ultra-fast, minimal memory footprint & higher concurrency || `SwiftSQL-3B-Q8_0.gguf` | 3.06 GB | Near-lossless quality, ideal for 16GB Apple Silicon / Mac mini |---## Quick Start### 1. Run Immediately with Ollama (1 Command)```bashollama run hf.co/xiain/SwiftSQL-3B-GGUF:Q8_0```### 2. Serve High-Concurrency OpenAI-Compatible API via `llama.cpp````bashllama-server -hf xiain/SwiftSQL-3B-GGUF:Q8_0 --port 11434 --ctx-size 4096 --parallel 4 --flash-attn```### 3. Production API Gateway with Read-Only Guardrail & Auto-RepairClone [github.com/2422725977/swift-sql](https://github.com/2422725977/swift-sql) and start `serve/api_gateway.py` in front of Ollama / `llama-server` to get Bearer API key auth, rate limiting, `sqlglot` read-only safety blocking, and automatic 1-shot SQL self-repair.---## Prompt Format**System Prompt**```text5 unmodified lines4. 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 (Generation)**```textTask: generate_sqlDialect: postgresql10 unmodified lines{"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"]}```**User Prompt (1-Shot SQL Self-Repair)**```textTask: repair_sqlDialect: postgresqlSchema:CREATE TABLE orders (id INT, user_id INT, amount NUMERIC, status TEXT);Question:统计每个用户的订单数Failed SQL:SELECT user_id, COUNT(*) FORM orders GROUP BY user_idError:syntax error at or near "FORM"```---## Limitations & Responsible Use- Always enforce database-level read-only permissions and static SQL validation (e.g., `sqlglot`) before executing model-generated SQL in production.- Built on `Qwen/Qwen2.5-Coder-3B-Instruct` (Apache 2.0) and open public datasets; released under **Apache 2.0**.6 unmodified lines7891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101115 unmodified lines11711811912012112212310 unmodified lines1341351361371381391401411426 unmodified linespipeline_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 (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 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**```text5 unmodified lines4. 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: postgresql10 unmodified lines{"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+59-54