ay2r commited on
Commit
4858e3c
·
verified ·
1 Parent(s): 1a41d07

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +123 -0
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).