Text Generation
Transformers
Safetensors
GGUF
PEFT
English
qwen2
text-to-sql
sql
sqlite
qlora
spider
bird
code
conversational
Eval Results (legacy)
text-generation-inference
Instructions to use ay2r/sqlforge-3b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ay2r/sqlforge-3b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ay2r/sqlforge-3b") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ay2r/sqlforge-3b") model = AutoModelForCausalLM.from_pretrained("ay2r/sqlforge-3b", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - PEFT
How to use ay2r/sqlforge-3b with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use ay2r/sqlforge-3b 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 ay2r/sqlforge-3b:Q4_K_M # Run inference directly in the terminal: llama cli -hf ay2r/sqlforge-3b:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf ay2r/sqlforge-3b:Q4_K_M # Run inference directly in the terminal: llama cli -hf ay2r/sqlforge-3b: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 ay2r/sqlforge-3b:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama cli -hf ay2r/sqlforge-3b:Q4_K_M
Use Docker
docker model run hf.co/ay2r/sqlforge-3b:Q4_K_M
- Llama new
- LM Studio
- Jan
- vLLM
How to use ay2r/sqlforge-3b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ay2r/sqlforge-3b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ay2r/sqlforge-3b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ay2r/sqlforge-3b:Q4_K_M
- SGLang
How to use ay2r/sqlforge-3b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "ay2r/sqlforge-3b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ay2r/sqlforge-3b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "ay2r/sqlforge-3b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ay2r/sqlforge-3b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use ay2r/sqlforge-3b with Ollama:
ollama run hf.co/ay2r/sqlforge-3b:Q4_K_M
- Unsloth Desktop
- Pi
How to use ay2r/sqlforge-3b with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf ay2r/sqlforge-3b: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": "ay2r/sqlforge-3b:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use ay2r/sqlforge-3b with Docker Model Runner:
docker model run hf.co/ay2r/sqlforge-3b:Q4_K_M
- Lemonade
How to use ay2r/sqlforge-3b with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull ay2r/sqlforge-3b:Q4_K_M
Run and chat with the model
lemonade run user.sqlforge-3b-Q4_K_M
List all available models
lemonade list
- Hermes Agent
How to use ay2r/sqlforge-3b with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf ay2r/sqlforge-3b: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 ay2r/sqlforge-3b:Q4_K_M
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use ay2r/sqlforge-3b with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf ay2r/sqlforge-3b: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 "ay2r/sqlforge-3b: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"
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: Qwen/Qwen2.5-Coder-3B-Instruct
|
| 4 |
+
library_name: transformers
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
language: [en]
|
| 7 |
+
tags: [text-to-sql, sql, sqlite, qlora, peft, spider, bird, code]
|
| 8 |
+
datasets: [spider, bird-bench]
|
| 9 |
+
model-index:
|
| 10 |
+
- name: SQLForge-3B
|
| 11 |
+
results:
|
| 12 |
+
- task: { type: text-to-sql, name: Text-to-SQL }
|
| 13 |
+
dataset: { type: spider, name: Spider 1.0 dev, split: dev }
|
| 14 |
+
metrics:
|
| 15 |
+
- { type: execution_accuracy, value: 78.5, name: Execution accuracy (greedy) }
|
| 16 |
+
- { type: execution_accuracy, value: 80.5, name: Execution accuracy (+ column fix + self-correction) }
|
| 17 |
+
- task: { type: text-to-sql, name: Text-to-SQL }
|
| 18 |
+
dataset: { type: bird-bench, name: BIRD dev (500-question subset), split: dev }
|
| 19 |
+
metrics:
|
| 20 |
+
- { type: execution_accuracy, value: 53.1, name: Execution accuracy (greedy) }
|
| 21 |
+
- { type: execution_accuracy, value: 54.1, name: Execution accuracy (+ self-correction) }
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
# SQLForge-3B
|
| 25 |
+
|
| 26 |
+
A 3B text-to-SQL model for SQLite: [Qwen2.5-Coder-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-3B-Instruct)
|
| 27 |
+
fine-tuned with QLoRA on Spider and BIRD training data, built on a single 8 GB laptop GPU.
|
| 28 |
+
|
| 29 |
+
Part of the SQLForge project, which also includes an evaluation harness, serving with vLLM and
|
| 30 |
+
quantization, guardrails, self-correction and an observability stack. See the project README for
|
| 31 |
+
the full write-up.
|
| 32 |
+
|
| 33 |
+
## Results
|
| 34 |
+
|
| 35 |
+
Execution accuracy (EX): the predicted query's result set matches the gold query's.
|
| 36 |
+
Greedy decoding, schema given as `CREATE TABLE` DDL plus 3 sample rows per table.
|
| 37 |
+
|
| 38 |
+
| Model | Spider dev EX | BIRD dev EX* |
|
| 39 |
+
|---|---|---|
|
| 40 |
+
| Qwen2.5-Coder-3B-Instruct (base) | 71.8 | 41.7 |
|
| 41 |
+
| SQLForge-3B run 1 (Spider only) | 78.0 | 43.5 |
|
| 42 |
+
| **SQLForge-3B (this model)** | **78.5** | **53.1** |
|
| 43 |
+
| + deterministic column fix + execution-guided self-correction | **80.5** | **54.1** |
|
| 44 |
+
|
| 45 |
+
\*Fixed random 500-question subset of BIRD dev (seed 42); evidence hints included in the prompt.
|
| 46 |
+
|
| 47 |
+
**Quantized variants**:
|
| 48 |
+
|
| 49 |
+
| Variant | Size | Spider EX | BIRD EX |
|
| 50 |
+
|---|---|---|---|
|
| 51 |
+
| bf16 | 5.8 GB | 78.5 | 53.1 |
|
| 52 |
+
| FP8 (vLLM, online) | weights 3.2 GB in VRAM | 78.6 | 52.7 |
|
| 53 |
+
| GGUF Q8_0 | 3.3 GB | 78.4 | 52.5 |
|
| 54 |
+
| GGUF Q4_K_M | 1.8 GB | 76.6 | 52.7 |
|
| 55 |
+
| AWQ W4A16 | 2.0 GB | 75.2 | 51.9 |
|
| 56 |
+
|
| 57 |
+
## Prompt format
|
| 58 |
+
|
| 59 |
+
Use the chat template with this system prompt and user message (the model was trained on exactly this):
|
| 60 |
+
|
| 61 |
+
```text
|
| 62 |
+
[system] You are an expert SQLite engineer. Given a database schema and a question, write a single
|
| 63 |
+
correct SQLite SELECT query that answers it. Return only the SQL, with no explanation.
|
| 64 |
+
|
| 65 |
+
[user]
|
| 66 |
+
### Database schema
|
| 67 |
+
CREATE TABLE singer (
|
| 68 |
+
Singer_ID INTEGER,
|
| 69 |
+
Name TEXT,
|
| 70 |
+
...
|
| 71 |
+
);
|
| 72 |
+
-- sample rows (Singer_ID | Name | ...):
|
| 73 |
+
-- 1 | Joe Sharp | ...
|
| 74 |
+
|
| 75 |
+
### Question
|
| 76 |
+
How many singers are there?
|
| 77 |
+
|
| 78 |
+
### Hint <- optional, BIRD-style domain knowledge
|
| 79 |
+
...
|
| 80 |
+
|
| 81 |
+
### SQL
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
```python
|
| 85 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 86 |
+
|
| 87 |
+
tok = AutoTokenizer.from_pretrained("ay2r/sqlforge-3b")
|
| 88 |
+
model = AutoModelForCausalLM.from_pretrained("ay2r/sqlforge-3b", dtype="bfloat16", device_map="auto")
|
| 89 |
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}, {"role": "user", "content": user_prompt}]
|
| 90 |
+
ids = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
| 91 |
+
print(tok.decode(model.generate(ids, max_new_tokens=256, do_sample=False)[0, ids.shape[1]:], skip_special_tokens=True))
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
With vLLM: `vllm serve ay2r/sqlforge-3b --quantization fp8 --enable-prefix-caching`. Prefix
|
| 95 |
+
caching matters here: questions on the same database share the schema prefix, which gave 4.7×
|
| 96 |
+
throughput on BIRD.
|
| 97 |
+
|
| 98 |
+
## Training
|
| 99 |
+
|
| 100 |
+
- **Data:**
|
| 101 |
+
- 16,218 examples: Spider train (8,140) and BIRD train (8,078), from 201 databases.
|
| 102 |
+
- BIRD examples whose gold SQL fails to execute were dropped (478).
|
| 103 |
+
- `formula_1` was excluded because it overlaps BIRD dev.
|
| 104 |
+
- No dev databases or questions appear in training; a contamination check confirms this.
|
| 105 |
+
- **Method:**
|
| 106 |
+
- QLoRA: NF4 4-bit base, LoRA r=16, α=32, dropout 0.05, on all attention and MLP projections (0.96% of parameters).
|
| 107 |
+
- Loss on the SQL completion only.
|
| 108 |
+
- **Hyperparameters:** 1 epoch (1,014 steps), learning rate 2e-4 with cosine decay, effective batch 16, max length 2,048, paged AdamW 8-bit, gradient checkpointing.
|
| 109 |
+
- **Compute:** one RTX 5060 Laptop GPU (8 GB): 7.2 h, peak 3.5 GB.
|
| 110 |
+
- **Checkpoint:** the final checkpoint. On full Spider and BIRD it beat the checkpoint chosen by validation execution accuracy.
|
| 111 |
+
|
| 112 |
+
## Limitations
|
| 113 |
+
|
| 114 |
+
- **SQLite dialect only.** It was trained and evaluated on SQLite; other dialects will need adaptation.
|
| 115 |
+
- **It hallucinates column names.** This is the main remaining failure mode, with 66 of 1,034 Spider dev and 53 of 500 BIRD answers affected. On Spider most are near-misses (`pet_type` for `PetType`) that a deterministic post-processing step fixes. On BIRD they're mostly invented.
|
| 116 |
+
- **Harder questions and value semantics.** It's weaker on BIRD "challenging" questions (36% EX) and on questions that need value-level domain knowledge without a hint.
|
| 117 |
+
- **Schema size.** Prompts over about 8k tokens (very wide schemas) need schema linking, which is in the project's serving pipeline.
|
| 118 |
+
- **Not safe to run unchecked.** Like any LLM, it can be prompt-injected into emitting destructive SQL; this was observed with `DROP TABLE`. **Never run its output on a database without guardrails.** The project ships a read-only guardrail layer for this.
|
| 119 |
+
|
| 120 |
+
## License and attribution
|
| 121 |
+
|
| 122 |
+
The weights derive from Qwen2.5-Coder-3B-Instruct; check its license before redistribution. Training
|
| 123 |
+
data: [Spider](https://yale-lily.github.io/spider) (CC BY-SA 4.0) and [BIRD](https://bird-bench.github.io/) (CC BY-SA 4.0).
|