Shizu0n commited on
Commit
7af565c
·
verified ·
1 Parent(s): b47b6d1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -46
README.md CHANGED
@@ -1,7 +1,11 @@
1
  ---
 
 
 
2
  language:
3
  - en
4
- license: apache-2.0
 
5
  tags:
6
  - sql
7
  - text-to-sql
@@ -9,21 +13,15 @@ tags:
9
  - phi-3
10
  - fine-tuned
11
  - text-generation
12
- base_model: microsoft/Phi-3-mini-4k-instruct
 
13
  ---
14
 
15
  # Phi-3 Mini SQL Generator — Merged Model
16
 
17
- This is the **merged (standalone) version** for `Shizu0n/phi3-mini-sql-generator` on top of `microsoft/Phi-3-mini-4k-instruct`.
18
-
19
- The LoRA adapter weights have been merged directly into the base model, making this a standard `AutoModelForCausalLM` — no PEFT dependency required for inference.
20
-
21
- ## Why two versions?
22
-
23
- | Repo | Purpose |
24
- |---|---|
25
- | `Shizu0n/phi3-mini-sql-generator` | Original QLoRA adapter — documents the training pipeline |
26
- | `Shizu0n/phi3-mini-sql-generator-merged` | Merged standalone model — used for deployment and inference |
27
 
28
  ## Evaluation — Base vs Fine-tuned
29
 
@@ -34,29 +32,25 @@ Evaluated on 200 held-out examples from [b-mc2/sql-create-context](https://huggi
34
  | Phi-3-mini-4k-instruct (base) | 2.0% |
35
  | **This model (fine-tuned)** | **73.5%** |
36
 
 
 
 
 
 
 
 
 
 
37
  ## Training Details
38
 
39
  - **Dataset:** b-mc2/sql-create-context — 1,000 train / 200 validation examples
40
- - **Method:** QLoRA (4-bit NF4, LoRA rank 16, alpha 32)
41
  - **Hardware:** NVIDIA T4 (Google Colab free tier)
42
  - **Training time:** ~21 min
43
  - **Final train loss:** 0.6526
 
44
 
45
- ## Validation
46
-
47
- The merge was accepted only after all three smoke tests returned a concrete SQL query:
48
-
49
- 1. PEFT adapter loaded on the base model.
50
- 2. Local merged directory after `merge_and_unload()` and `save_pretrained()`.
51
- 3. Downloaded model from this Hugging Face repo with `force_download=True`.
52
-
53
- Reference smoke output:
54
-
55
- ```sql
56
- SELECT AVG(salary), department FROM employees GROUP BY department
57
- ```
58
-
59
- ## Inference example
60
 
61
  ```python
62
  import torch
@@ -64,26 +58,20 @@ from transformers import AutoModelForCausalLM, AutoTokenizer
64
 
65
  model_id = "Shizu0n/phi3-mini-sql-generator-merged"
66
 
67
- tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=False)
68
  model = AutoModelForCausalLM.from_pretrained(
69
  model_id,
70
- dtype=torch.float16,
71
  device_map="auto",
72
  trust_remote_code=False,
73
  attn_implementation="eager",
74
  )
75
- model.config.use_cache = False
76
 
77
  prompt = (
78
- "Given the following SQL table, write a SQL query.
79
-
80
- "
81
- "Table: employees (id, name, department, salary)
82
-
83
- "
84
- "Question: What is the average salary per department?
85
-
86
- SQL:"
87
  )
88
 
89
  inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
@@ -96,13 +84,24 @@ with torch.inference_mode():
96
  repetition_penalty=1.1,
97
  pad_token_id=tokenizer.eos_token_id,
98
  )
 
 
 
99
 
100
- text = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
101
- print(text.strip())
 
102
  ```
103
 
104
- ## Notes
 
 
 
 
 
 
 
105
 
106
- - Use `trust_remote_code=False`; the built-in Transformers Phi-3 implementation avoids stale remote-code failures.
107
- - Do not patch `rope_scaling` manually.
108
- - Do not mutate `_tied_weights_keys` before saving.
 
1
  ---
2
+ base_model: microsoft/Phi-3-mini-4k-instruct
3
+ library_name: transformers
4
+ license: mit
5
  language:
6
  - en
7
+ datasets:
8
+ - b-mc2/sql-create-context
9
  tags:
10
  - sql
11
  - text-to-sql
 
13
  - phi-3
14
  - fine-tuned
15
  - text-generation
16
+ - phi3
17
+ pipeline_tag: text-generation
18
  ---
19
 
20
  # Phi-3 Mini SQL Generator — Merged Model
21
 
22
+ Merged standalone version of [Shizu0n/phi3-mini-sql-generator](https://huggingface.co/Shizu0n/phi3-mini-sql-generator)
23
+ — LoRA adapter weights fused into [Phi-3-mini-4k-instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct).
24
+ No PEFT dependency required for inference.
 
 
 
 
 
 
 
25
 
26
  ## Evaluation — Base vs Fine-tuned
27
 
 
32
  | Phi-3-mini-4k-instruct (base) | 2.0% |
33
  | **This model (fine-tuned)** | **73.5%** |
34
 
35
+ > Exact match: normalized SQL comparison (lowercase, strip whitespace/semicolons).
36
+
37
+ ## Why two versions?
38
+
39
+ | Repo | Purpose |
40
+ |---|---|
41
+ | [`Shizu0n/phi3-mini-sql-generator`](https://huggingface.co/Shizu0n/phi3-mini-sql-generator) | QLoRA adapter — documents the training pipeline |
42
+ | `Shizu0n/phi3-mini-sql-generator-merged` | Merged standalone — used for deployment and inference |
43
+
44
  ## Training Details
45
 
46
  - **Dataset:** b-mc2/sql-create-context — 1,000 train / 200 validation examples
47
+ - **Method:** QLoRA (4-bit NF4, LoRA rank 16, alpha 32, target modules: qkv_proj/o_proj/gate_up_proj/down_proj)
48
  - **Hardware:** NVIDIA T4 (Google Colab free tier)
49
  - **Training time:** ~21 min
50
  - **Final train loss:** 0.6526
51
+ - **Best checkpoint:** step 250 (by eval loss)
52
 
53
+ ## Inference Example
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  ```python
56
  import torch
 
58
 
59
  model_id = "Shizu0n/phi3-mini-sql-generator-merged"
60
 
61
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
62
  model = AutoModelForCausalLM.from_pretrained(
63
  model_id,
64
+ torch_dtype=torch.float16,
65
  device_map="auto",
66
  trust_remote_code=False,
67
  attn_implementation="eager",
68
  )
69
+ model.eval()
70
 
71
  prompt = (
72
+ "Given the following SQL table, write a SQL query.\n\n"
73
+ "Table: employees (id, name, department, salary)\n\n"
74
+ "Question: What is the average salary per department?\n\nSQL:"
 
 
 
 
 
 
75
  )
76
 
77
  inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
 
84
  repetition_penalty=1.1,
85
  pad_token_id=tokenizer.eos_token_id,
86
  )
87
+ prompt_len = inputs["input_ids"].shape[-1]
88
+ print(tokenizer.decode(outputs[0][prompt_len:], skip_special_tokens=True))
89
+ ```
90
 
91
+ Expected output:
92
+ ```sql
93
+ SELECT AVG(salary), department FROM employees GROUP BY department
94
  ```
95
 
96
+ ## Validation
97
+
98
+ Merge accepted after three smoke tests:
99
+ 1. PEFT adapter loaded on base model
100
+ 2. Local merged directory after `merge_and_unload()` + `save_pretrained()`
101
+ 3. Downloaded from this repo with `force_download=True`
102
+
103
+ ## Limitations
104
 
105
+ - Fine-tuned on 1,000 examples — best suited for simple to medium complexity SELECT queries
106
+ - Not tested on dialect-specific SQL (PostgreSQL/MySQL-specific functions)
107
+ - May struggle with multi-table JOINs and nested subqueries