sriksven commited on
Commit
bf7c7f8
·
verified ·
1 Parent(s): 5cc3ccf

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +135 -0
README.md ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: Qwen/Qwen2.5-7B-Instruct
4
+ tags:
5
+ - sql
6
+ - text-to-sql
7
+ - qlora
8
+ - unsloth
9
+ - qwen2.5
10
+ - database
11
+ - natural-language-to-sql
12
+ datasets:
13
+ - gretelai/synthetic_text_to_sql
14
+ language:
15
+ - en
16
+ pipeline_tag: text-generation
17
+ library_name: transformers
18
+ model-index:
19
+ - name: SQLForge-7B
20
+ results: []
21
+ ---
22
+
23
+ # SQLForge-7B
24
+
25
+ A fine-tuned **Qwen2.5-7B-Instruct** model specialized for **natural language to SQL generation**. Given a database schema and a question in plain English, it writes the correct SQL query and explains what it does.
26
+
27
+ ## Key Details
28
+
29
+ | | |
30
+ |---|---|
31
+ | **Base model** | Qwen/Qwen2.5-7B-Instruct |
32
+ | **Method** | QLoRA (4-bit NF4, rank 16, alpha 16) |
33
+ | **Library** | Unsloth + TRL SFTTrainer |
34
+ | **Dataset** | gretelai/synthetic_text_to_sql (10K examples from 100K) |
35
+ | **Hardware** | NVIDIA RTX A5000 (24GB VRAM) on RunPod |
36
+ | **Training time** | ~2.75 hours (500 steps) |
37
+ | **Final loss** | 0.414 |
38
+ | **Parameters trained** | 40.4M of 7.66B (0.53%) |
39
+ | **Format** | ChatML |
40
+ | **Output** | Merged 16-bit safetensors |
41
+
42
+ ## Dataset
43
+
44
+ Trained on 10,000 examples from the [gretelai/synthetic_text_to_sql](https://huggingface.co/datasets/gretelai/synthetic_text_to_sql) dataset, which covers 100 domains with a wide range of SQL complexity levels including subqueries, joins, aggregations, window functions, and set operations. Each example includes the database schema (CREATE TABLE statements), a natural language question, the correct SQL query, and an explanation.
45
+
46
+ ## Usage
47
+
48
+ ### Transformers
49
+
50
+ ```python
51
+ from transformers import AutoModelForCausalLM, AutoTokenizer
52
+
53
+ model = AutoModelForCausalLM.from_pretrained("sriksven/SQLForge-7B")
54
+ tokenizer = AutoTokenizer.from_pretrained("sriksven/SQLForge-7B")
55
+
56
+ messages = [
57
+ {
58
+ "role": "system",
59
+ "content": "You are an expert SQL assistant. Given a database schema and a natural language question, write the correct SQL query and explain what it does.",
60
+ },
61
+ {
62
+ "role": "user",
63
+ "content": (
64
+ "Schema:\n"
65
+ "CREATE TABLE employees (id INT, name VARCHAR(100), department VARCHAR(50), salary DECIMAL(10,2));\n"
66
+ "CREATE TABLE departments (name VARCHAR(50), budget DECIMAL(12,2));\n\n"
67
+ "Question: What is the average salary by department, only showing departments with average salary above 75000?"
68
+ ),
69
+ },
70
+ ]
71
+
72
+ inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
73
+ outputs = model.generate(inputs, max_new_tokens=512)
74
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
75
+ ```
76
+
77
+ ### Unsloth (faster inference)
78
+
79
+ ```python
80
+ from unsloth import FastLanguageModel
81
+
82
+ model, tokenizer = FastLanguageModel.from_pretrained(
83
+ model_name="sriksven/SQLForge-7B",
84
+ max_seq_length=2048,
85
+ load_in_4bit=True,
86
+ )
87
+ FastLanguageModel.for_inference(model)
88
+ ```
89
+
90
+ ## SQL Complexity Coverage
91
+
92
+ The training data includes queries across multiple complexity levels:
93
+ - Simple SELECT with WHERE clauses
94
+ - Aggregations with GROUP BY and HAVING
95
+ - Single and multiple JOINs
96
+ - Subqueries and correlated subqueries
97
+ - Window functions (ROW_NUMBER, RANK, LAG, LEAD)
98
+ - Set operations (UNION, INTERSECT, EXCEPT)
99
+ - Data definition (CREATE, ALTER, INSERT)
100
+
101
+ ## Intended Use
102
+
103
+ - Natural language interfaces to databases
104
+ - SQL copilot tools for analysts and developers
105
+ - Educational tools for learning SQL
106
+ - Prototyping data query systems
107
+
108
+ ## Limitations
109
+
110
+ - Trained on synthetic data, not real production database queries
111
+ - May not handle highly domain-specific or proprietary SQL dialects
112
+ - Best with standard SQL syntax (PostgreSQL/MySQL style)
113
+ - Does not validate against a live database — SQL correctness is not guaranteed
114
+ - Long or deeply nested schemas may exceed the 2048 token context
115
+
116
+ ## Training Infrastructure
117
+
118
+ | | |
119
+ |---|---|
120
+ | **GPU** | NVIDIA RTX A5000 24GB |
121
+ | **Cloud** | RunPod ($0.27/hr) |
122
+ | **Framework** | Unsloth 2026.5.2 + TRL + Transformers 5.5.0 |
123
+ | **Precision** | BF16 training, 4-bit NF4 base quantization |
124
+ | **Optimizer** | AdamW 8-bit |
125
+ | **Learning rate** | 2e-4, linear decay |
126
+ | **Batch size** | 16 effective (4 per device × 4 accumulation) |
127
+ | **Packing** | Enabled |
128
+
129
+ ## Source Code
130
+
131
+ Training scripts: [github.com/sriksven/LLM-FineTune-Suite](https://github.com/sriksven/LLM-FineTune-Suite)
132
+
133
+ ## License
134
+
135
+ Apache 2.0