AaTekle commited on
Commit
3a0420b
·
1 Parent(s): 5a6f0ee

Upload model weights with Git LFS

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen2.5-Coder-0.5B-Instruct
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - "base_model:adapter:Qwen/Qwen2.5-Coder-0.5B-Instruct"
7
+ - lora
8
+ - sft
9
+ - text-to-sql
10
+ ---
11
+
12
+ # **SQLQwen - Qwen2.5 Text-to-SQL Fine-Tuning with LoRA**
13
+
14
+ LoRA fine-tuning of **Qwen2.5-Coder-0.5B-Instruct** for **Text-to-SQL generation** using the **Gretel synthetic_text_to_sql** dataset.
15
+
16
+ Text-to-SQL systems translate natural-language questions into executable SQL using a provided database schema or SQL context. SQLQwen is designed to specialize a lightweight code-focused language model for this task while keeping the fine-tuning process parameter-efficient and practical on consumer hardware.
17
+
18
+ Given:
19
+
20
+ 1. a database schema or SQL context
21
+ 2. a natural-language request
22
+
23
+ the model generates the relevant SQL query
24
+
25
+ ### Example
26
+
27
+ **Database context:**
28
+
29
+ ```sql
30
+ CREATE TABLE customers (
31
+ id INTEGER PRIMARY KEY,
32
+ name TEXT,
33
+ country TEXT,
34
+ revenue DECIMAL(12, 2)
35
+ );
36
+ ```
37
+
38
+ **Natural-language request:**
39
+
40
+ ```text
41
+ Find the five customers with the highest revenue.
42
+ ```
43
+
44
+ **Expected output:**
45
+
46
+ ```sql
47
+ SELECT id, name, country, revenue
48
+ FROM customers
49
+ ORDER BY revenue DESC
50
+ LIMIT 5;
51
+ ```
52
+
53
+ ## Why LoRA
54
+
55
+ LoRA (**Low-Rank Adaptation**) provides a parameter-efficient alternative to full fine-tuning.
56
+
57
+ Instead of updating all parameters in the pretrained model, LoRA freezes the original model weights and introduces small trainable low-rank matrices into selected Transformer layers.
58
+
59
+ for this project, LoRA adapters are applied to the attention projection layers:
60
+
61
+ ```text
62
+ q_proj
63
+ k_proj
64
+ v_proj
65
+ o_proj
66
+ ```
67
+
68
+ this reduces the number of trainable parameters, GPU memory requirements, and adapter storage size while preserving the capabilities of the original pretrained model.
69
+
70
+ Only **2,162,688 of 496,195,456 parameters**, or approximately **0.4359%**, were trainable during fine-tuning.
71
+
72
+ ## Model
73
+
74
+ * **Base model:** [`Qwen/Qwen2.5-Coder-0.5B-Instruct`](https://huggingface.co/Qwen/Qwen2.5-Coder-0.5B-Instruct)
75
+ * **Fine-tuning:** PEFT LoRA
76
+ * **Training:** TRL `SFTTrainer`
77
+ * **LoRA rank:** `16`
78
+ * **LoRA alpha:** `32`
79
+ * **LoRA dropout:** `0.05`
80
+ * **Target modules:** `q_proj`, `k_proj`, `v_proj`, `o_proj`
81
+ * **Training objective:** Completion-only supervised fine-tuning
82
+
83
+ Qwen2.5-Coder was selected because SQL generation is fundamentally a structured code-generation task rather than conventional natural-language classification.
84
+
85
+ ## Dataset
86
+
87
+ ### Gretel Synthetic Text-to-SQL
88
+
89
+ [`gretelai/synthetic_text_to_sql`](https://huggingface.co/datasets/gretelai/synthetic_text_to_sql)
90
+
91
+ Gretel Synthetic Text-to-SQL dataset provides natural-language SQL requests, database context, target SQL queries, and supporting metadata.
92
+
93
+ 3 fields are used directly during training:
94
+
95
+ | Dataset field | Purpose |
96
+ | ------------- | ------------------------------ |
97
+ | `sql_context` | Database schema or SQL context |
98
+ | `sql_prompt` | Natural-language request |
99
+ | `sql` | Ground-truth SQL completion |
100
+
101
+ Training pipeline converts each example into an instruction-style prompt and trains the model specifically on the assistant SQL completion.
102
+
103
+ ## Training Configuration
104
+
105
+ | Setting | Value |
106
+ | ----------------------- | ---------------------------------: |
107
+ | Base model | `Qwen/Qwen2.5-Coder-0.5B-Instruct` |
108
+ | LoRA rank | `16` |
109
+ | LoRA alpha | `32` |
110
+ | LoRA dropout | `0.05` |
111
+ | Epochs | **2** |
112
+ | Training examples | **20,000** |
113
+ | Validation examples | **1,000** |
114
+ | Train batch size | **4** |
115
+ | Gradient accumulation | **4** |
116
+ | Effective batch size | **16 sequences** |
117
+ | Learning rate | **2e-4** |
118
+ | Warmup ratio | **0.03** |
119
+ | Weight decay | **0.01** |
120
+ | LR scheduler | **Cosine** |
121
+ | Maximum sequence length | **2048** |
122
+ | Gradient checkpointing | **Enabled** |
123
+ | Training objective | **Completion-only SFT** |
124
+
125
+ Training automatically uses **BF16** where supported, falling back to FP16 on CUDA or FP32 when CUDA is unavailable.
126
+
127
+ ## Training Run
128
+
129
+ | Metric | Result |
130
+ | ------------------------------- | ----------: |
131
+ | Training examples | **20,000** |
132
+ | Validation examples | **1,000** |
133
+ | Epochs | **2** |
134
+ | Optimizer steps | **2,500** |
135
+ | Final training loss | **0.2381** |
136
+ | Best evaluation loss | **0.2198** |
137
+ | Final evaluation loss | **0.2200** |
138
+ | Final evaluation token accuracy | **93.54%** |
139
+ | Best checkpoint | **2,400** |
140
+ | Training runtime | **~1h 35m** |
141
+
142
+ Training was completed locally on an **NVIDIA GeForce RTX 3050**.
143
+
144
+ Validation loss decreased from **0.2839** at the first logged evaluation to a best value of **0.2198** at checkpoint 2,400. The final checkpoint produced an evaluation loss of **0.2200**, indicating that training had largely converged by the end of the second epoch.
145
+
146
+ ## Held-Out Generation Evaluation
147
+
148
+ A held-out generation benchmark of **50 examples** was used to evaluate SQL generation code quality.
149
+
150
+ | Metric | Result |
151
+ | ------------------------ | ----------: |
152
+ | Evaluation examples | **50** |
153
+ | Exact-match accuracy | **28.0%** |
154
+ | SQL syntax validity | **100.0%** |
155
+ | Exact matches | **14 / 50** |
156
+ | Syntax-valid generations | **50 / 50** |
157
+
158
+ All **50 generated SQL queries were successfully parsed by SQLGlot**, resulting in a **100% syntax-validity rate**.
159
+
160
+ **28% exact-match score** uses strict string-level comparison. Semantically or execution-equivalent SQL queries may differ from the reference query while still producing the correct result, so exact match should not be interpreted as the model's full semantic accuracy.
161
+
162
+
163
+ ## Model Limitations:
164
+
165
+ * model may hallucinate tables or columns when the supplied database context is incomplete.
166
+ * **0.5B parameter** base model prioritizes lightweight training and inference over maximum reasoning capacity.
167
+ * Training uses synthetic Text-to-SQL examples, which may not represent every real-world database schema or production SQL workload.
168
+ * Exact-match evaluation does not account for all semantically equivalent SQL formulations.
169
+ * SQL execution accuracy against live databases was not measured in the reported benchmark.
170
+
171
+ ## Results:
172
+
173
+ completed fine-tuning run shows:
174
+
175
+ * **parameter-efficient adaptation**, with approximately **0.4359%** of model parameters trainable
176
+ * **stable convergence**, with validation loss reaching approximately **0.22**
177
+ * **100% syntax-valid SQL generation** across the 50-example held-out benchmark
178
+ * successful local fine-tuning of a code-focused language model using an **NVIDIA GeForce RTX 3050**
179
+
180
+ ## References:
181
+ - Hu, E. J., Shen, Y., Wallis, P., Allen-Zhu, Z., Li, Y., Wang, S., Wang, L., and Chen, W. *LoRA: Low-Rank Adaptation of Large Language Models*. arXiv:2106.09685, 2021.](https://arxiv.org/abs/2106.09685)
182
+
183
+ - Hugging Face. *PEFT LoRA Documentation*. Parameter-Efficient Fine-Tuning documentation. (https://huggingface.co/docs/transformers/en/peft) (https://huggingface.co/docs/peft/en/package_reference/lora)
184
+
185
+ - Qwen Team. Qwen2.5-Coder-0.5B-Instruct Model Card
186
+
187
+ - Hui, B. et al. Qwen2.5-Coder Technical Report. arXiv:2409.12186, 2024
188
+
189
+ - Gretel.ai. synthetic_text_to_sql Dataset Card. Hugging Face Datasets
adapter_config.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "Qwen/Qwen2.5-Coder-0.5B-Instruct",
7
+ "bias": "none",
8
+ "corda_config": null,
9
+ "ensure_weight_tying": false,
10
+ "eva_config": null,
11
+ "exclude_modules": null,
12
+ "fan_in_fan_out": false,
13
+ "inference_mode": true,
14
+ "init_lora_weights": true,
15
+ "layer_replication": null,
16
+ "layers_pattern": null,
17
+ "layers_to_transform": null,
18
+ "loftq_config": {},
19
+ "lora_alpha": 32,
20
+ "lora_bias": false,
21
+ "lora_dropout": 0.05,
22
+ "lora_ga_config": null,
23
+ "megatron_config": null,
24
+ "megatron_core": "megatron.core",
25
+ "modules_to_save": null,
26
+ "monteclora_config": null,
27
+ "peft_type": "LORA",
28
+ "peft_version": "0.20.0",
29
+ "qalora_group_size": 16,
30
+ "r": 16,
31
+ "rank_pattern": {},
32
+ "revision": null,
33
+ "target_modules": [
34
+ "o_proj",
35
+ "k_proj",
36
+ "q_proj",
37
+ "v_proj"
38
+ ],
39
+ "target_parameters": null,
40
+ "task_type": "CAUSAL_LM",
41
+ "trainable_token_indices": null,
42
+ "use_bdlora": null,
43
+ "use_dora": false,
44
+ "use_qalora": false,
45
+ "use_rslora": false,
46
+ "velora_config": null
47
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:82501f27a261361484b8c67bcb6d87b8c861f4076c83def5570b46c9dff746b7
3
+ size 8676008
chat_template.jinja ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
7
+ {%- endif %}
8
+ {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" %}
25
+ {{- '<|im_start|>' + message.role }}
26
+ {%- if message.content %}
27
+ {{- '\n' + message.content }}
28
+ {%- endif %}
29
+ {%- for tool_call in message.tool_calls %}
30
+ {%- if tool_call.function is defined %}
31
+ {%- set tool_call = tool_call.function %}
32
+ {%- endif %}
33
+ {{- '\n<tool_call>\n{"name": "' }}
34
+ {{- tool_call.name }}
35
+ {{- '", "arguments": ' }}
36
+ {{- tool_call.arguments | tojson }}
37
+ {{- '}\n</tool_call>' }}
38
+ {%- endfor %}
39
+ {{- '<|im_end|>\n' }}
40
+ {%- elif message.role == "tool" %}
41
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
42
+ {{- '<|im_start|>user' }}
43
+ {%- endif %}
44
+ {{- '\n<tool_response>\n' }}
45
+ {{- message.content }}
46
+ {{- '\n</tool_response>' }}
47
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
48
+ {{- '<|im_end|>\n' }}
49
+ {%- endif %}
50
+ {%- endif %}
51
+ {%- endfor %}
52
+ {%- if add_generation_prompt %}
53
+ {{- '<|im_start|>assistant\n' }}
54
+ {%- endif %}
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d48beb5dc8838419f34acc78392a7acab120ac7d4425e4eb021c0b5604ee3e0f
3
+ size 12179335
tokenizer_config.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": false,
24
+ "local_files_only": false,
25
+ "model_max_length": 32768,
26
+ "pad_token": "<|endoftext|>",
27
+ "split_special_tokens": false,
28
+ "tokenizer_class": "Qwen2Tokenizer",
29
+ "unk_token": null
30
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:78391a5f3c7906f77f20a11da12769dbf82969852f48b5b7e857521e8cad37ae
3
+ size 5713