Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
base_model:
|
6 |
+
- TinyLlama/TinyLlama-1.1B-Chat-v1.0
|
7 |
+
tags:
|
8 |
+
- lora
|
9 |
+
- fused
|
10 |
+
- text-to-sql
|
11 |
+
- natural-language-to-sql
|
12 |
+
- mlx
|
13 |
+
- apple-silicon
|
14 |
+
- fine-tuning
|
15 |
+
- instruction-following
|
16 |
+
model_creator: Jerome Mohanan
|
17 |
+
datasets:
|
18 |
+
- spider # used conceptually as inspiration; see Training Data
|
19 |
+
---
|
20 |
+
|
21 |
+
# TinyLlama-1.1B-Chat-LoRA-Fused-v1.0 — Natural-Language-to-SQL
|
22 |
+
|
23 |
+
**TinyLlama-1.1B-Chat-LoRA-Fused-v1.0** is a 1.1 billion parameter model derived from *TinyLlama/TinyLlama-1.1B-Chat-v1.0*.
|
24 |
+
Using parameter-efficient **LoRA** fine-tuning and the new Apple-Silicon-native **MLX** framework, the model has been specialised to convert plain-English questions into syntactically correct SQL queries for relational databases.
|
25 |
+
After training, the LoRA adapters were **merged (“fused”)** into the base weights, so you only need this single checkpoint for inference.
|
26 |
+
|
27 |
+
---
|
28 |
+
|
29 |
+
## 🗝️ Key Facts
|
30 |
+
| Property | Value |
|
31 |
+
|---|---|
|
32 |
+
| Base model | TinyLlama 1.1B Chat v1.0 |
|
33 |
+
| Task | Natural-Language → SQL generation |
|
34 |
+
| Fine-tuning method | Low-Rank Adaptation (LoRA) @ rank = 16 |
|
35 |
+
| Training framework | MLX 0.8 + PEFT |
|
36 |
+
| Hardware | MacBook Pro M4 Pro (20-core GPU) |
|
37 |
+
| Checkpoint size | 2.1 GB (fp16, fused) |
|
38 |
+
| License | Apache 2.0 |
|
39 |
+
|
40 |
+
---
|
41 |
+
|
42 |
+
## ✨ Intended Use
|
43 |
+
|
44 |
+
* **Interactive data exploration** inside BI notebooks or chatbots.
|
45 |
+
* **Customer-support analytics** — empower non-SQL users to ask free-form questions.
|
46 |
+
* **Education & demos** showing how LoRA + MLX enables rapid on-device fine-tuning.
|
47 |
+
|
48 |
+
The model was trained on synthetic NL-SQL pairs for demo purposes. **Do not** deploy it in production for mission-critical SQL generation without additional evaluation on your own schema and security review.
|
49 |
+
|
50 |
+
---
|
51 |
+
|
52 |
+
## 💻 Quick Start
|
53 |
+
```python
|
54 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
55 |
+
|
56 |
+
model_id = "jero2rome/tinyllama-1.1b-chat-lora-fused-v1.0"
|
57 |
+
tok = AutoTokenizer.from_pretrained(model_id)
|
58 |
+
model = AutoModelForCausalLM.from_pretrained(model_id)
|
59 |
+
|
60 |
+
prompt = """\
|
61 |
+
### Database schema
|
62 |
+
table orders(id, customer_id, total, created_at)
|
63 |
+
table customers(id, name, country)
|
64 |
+
|
65 |
+
### Question
|
66 |
+
List total sales per country ordered by total descending."""
|
67 |
+
|
68 |
+
inputs = tok(prompt, return_tensors="pt")
|
69 |
+
sql_out = model.generate(**inputs, max_new_tokens=128)
|
70 |
+
print(tok.decode(sql_out[0], skip_special_tokens=True))
|
71 |
+
```
|
72 |
+
|
73 |
+
---
|
74 |
+
|
75 |
+
## 🏋️♂️ Training Details
|
76 |
+
|
77 |
+
* **Data** – 10 K synthetic NL/SQL pairs auto-generated from the open-domain schema list, then manually spot-checked for correctness.
|
78 |
+
* **Pre-processing** – schema + question paired using the *Text-to-SQL prompt* pattern; SQL statements lower-cased; no anonymisation.
|
79 |
+
* **Hyper-parameters**
|
80 |
+
* batch size = 32 (gradient-accum = 4)
|
81 |
+
* learning-rate = 2 e-4 (cosine schedule)
|
82 |
+
* epochs = 3
|
83 |
+
* LoRA rank = 16, α = 32
|
84 |
+
* fp16 mixed-precision
|
85 |
+
|
86 |
+
Total GPU-hours ≈ 5mins on Apple-Silicon.
|
87 |
+
|
88 |
+
---
|
89 |
+
|
90 |
+
## 🌱 Environmental Impact
|
91 |
+
|
92 |
+
LoRA fine-tuning on consumer Apple-Silicon is energy-efficient.
|
93 |
+
|
94 |
+
---
|
95 |
+
|
96 |
+
## 🛠️ Limitations & Biases
|
97 |
+
|
98 |
+
* Trained on a synthetic, limited dataset → may under-perform on real production schemas.
|
99 |
+
* Does **not** perform schema-linking; you must include the relevant schema in the prompt.
|
100 |
+
* SQL is not guaranteed to be safe; always validate queries before execution.
|
101 |
+
|
102 |
+
---
|
103 |
+
|
104 |
+
## ✍️ Citation
|
105 |
+
```
|
106 |
+
@misc{mohanan2024tinyllama_sql_lora,
|
107 |
+
title = {TinyLlama-1.1B-Chat-LoRA-Fused-v1.0},
|
108 |
+
author = {Jerome Mohanan},
|
109 |
+
note = {Hugging Face repository: https://huggingface.co/jero2rome/tinyllama-1.1b-chat-lora-fused-v1.0},
|
110 |
+
year = {2024}
|
111 |
+
}
|
112 |
+
```
|
113 |
+
|
114 |
+
---
|
115 |
+
|
116 |
+
## 📫 Contact
|
117 |
+
Questions or feedback? Ping **@jero2rome** on Hugging Face or email <[email protected]>.
|