Text Generation
PEFT
Safetensors
lora
sft
text-to-sql
trl
conversational
albertkingdom commited on
Commit
c0c29e8
·
verified ·
1 Parent(s): dc4e2b0

docs: fix in-distribution results table, correct comparison claim, add training details

Browse files
Files changed (1) hide show
  1. README.md +45 -12
README.md CHANGED
@@ -28,12 +28,13 @@ LoRA adapter fine-tuned from [deepseek-ai/deepseek-coder-7b-instruct-v1.5](https
28
  **Limitations**:
29
  - Not evaluated on production/adversarial inputs, non-English questions, or dialects outside SQLite-compatible syntax.
30
  - Execution accuracy on Spider (60.8%) means roughly 2 in 5 generated queries on unseen schemas are still wrong — **always validate generated SQL before running it against a real database**, especially for destructive statements (this adapter was only trained/evaluated on read (`SELECT`) queries).
 
31
  - Code capability (HumanEval+) is retained better than the pure-SQL version but still ~4pp below the un-finetuned base model — for general-purpose coding tasks unrelated to SQL, the base model remains the stronger choice. See Results below.
32
 
33
  ## What's on `main` vs `pure-sql`
34
 
35
  - **`main` (this version)** — trained on a 50/50 mix of SQL and general code-instruction data. Better SQL generalization to unseen schemas *and* better retention of general code ability than the pure-SQL version.
36
- - **`pure-sql`** branch — the original version trained on 100% SQL data. Higher in-distribution SQL accuracy on the training-like distribution, but noticeably worse code capability retention and worse generalization to unseen database schemas.
37
 
38
  ```python
39
  # to load the pure-SQL version instead:
@@ -49,7 +50,9 @@ The pure-SQL version showed catastrophic forgetting of general code generation a
49
  | HumanEval pass@1 | 52.0% | 40.0% | -12.0pp |
50
  | HumanEval+ (999 edge cases) | 46.0% | 34.0% | -12.0pp |
51
 
52
- Training data was rebalanced to 50% [b-mc2/sql-create-context](https://huggingface.co/datasets/b-mc2/sql-create-context) + 50% [ise-uiuc/Magicoder-OSS-Instruct-75K](https://huggingface.co/datasets/ise-uiuc/Magicoder-OSS-Instruct-75K) (interleaved batch-wise via `datasets.interleave_datasets`), 1 epoch.
 
 
53
 
54
  ## Results
55
 
@@ -67,15 +70,21 @@ Training data was rebalanced to 50% [b-mc2/sql-create-context](https://huggingfa
67
  | Official Execution Accuracy | 39.9% | 50.4% | **60.8%** |
68
  | Official Exact Match (structural) | 32.1% | 37.4% | **47.3%** |
69
 
70
- This version beats the pure-SQL version on *every* axis measured code capability retention, SQL generalization to unseen schemas, and in-distribution SQL accuracy (see below). Mixing in code data appears to act as a regularizer against overfitting to the narrow single-domain SQL distribution.
71
 
72
  ### In-distribution SQL accuracy (b-mc2/sql-create-context, same distribution as training)
73
 
74
- | Model | Exact Match |
 
 
75
  |------|-------------|
76
- | Base | 4% (2/50) |
77
- | Pure-SQL SFT | 78% (39/50) |
78
- | This version (mixed) | 70% (14/20, different eval run — see repo `text-to-sql/docs/experiment_log.md` for full methodology) |
 
 
 
 
79
 
80
  ## LoRA configuration
81
 
@@ -90,13 +99,16 @@ quantization: 4-bit NF4 (QLoRA), bf16 compute
90
  ## Quick start
91
 
92
  ```python
 
93
  from transformers import AutoModelForCausalLM, AutoTokenizer
94
  from peft import PeftModel
95
 
96
  base_model_id = "deepseek-ai/deepseek-coder-7b-instruct-v1.5"
97
  adapter_id = "albertkingdom/deepseek-coder-7b-text2sql-magicoder-lora"
98
 
99
- model = AutoModelForCausalLM.from_pretrained(base_model_id, device_map="auto")
 
 
100
  tokenizer = AutoTokenizer.from_pretrained(base_model_id)
101
  model = PeftModel.from_pretrained(model, adapter_id) # main = mixed training version
102
 
@@ -113,20 +125,23 @@ Find all users with gmail addresses"""
113
  }]
114
 
115
  inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(model.device)
116
- outputs = model.generate(inputs, max_new_tokens=200)
117
- print(tokenizer.decode(outputs[0], skip_special_tokens=True))
118
  ```
119
 
 
 
120
  ## Training procedure
121
 
122
- Trained with SFT (TRL `SFTTrainer`) on an interleaved SQL + code instruction dataset, 1 epoch, effective batch size 16, bf16, 4-bit QLoRA, on a rented RTX 5090.
123
 
124
  ### Framework versions
125
 
126
- - PEFT 0.18.0
127
  - TRL: 0.26.2
128
  - Transformers: 4.57.3
129
  - Datasets: 4.4.2
 
130
 
131
  ## License
132
 
@@ -160,3 +175,21 @@ Commercial use is otherwise permitted, consistent with the base model's license.
160
  howpublished = {\url{https://github.com/huggingface/trl}}
161
  }
162
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  **Limitations**:
29
  - Not evaluated on production/adversarial inputs, non-English questions, or dialects outside SQLite-compatible syntax.
30
  - Execution accuracy on Spider (60.8%) means roughly 2 in 5 generated queries on unseen schemas are still wrong — **always validate generated SQL before running it against a real database**, especially for destructive statements (this adapter was only trained/evaluated on read (`SELECT`) queries).
31
+ - **JOIN over-generation**: the SQL training data is almost entirely single-table, so on multi-table schemas the model tends to join every available table indiscriminately. This is the main source of exact-match errors on Spider.
32
  - Code capability (HumanEval+) is retained better than the pure-SQL version but still ~4pp below the un-finetuned base model — for general-purpose coding tasks unrelated to SQL, the base model remains the stronger choice. See Results below.
33
 
34
  ## What's on `main` vs `pure-sql`
35
 
36
  - **`main` (this version)** — trained on a 50/50 mix of SQL and general code-instruction data. Better SQL generalization to unseen schemas *and* better retention of general code ability than the pure-SQL version.
37
+ - **`pure-sql`** branch — the original version trained on 100% SQL data. Comparable in-distribution SQL accuracy, but noticeably worse code capability retention and worse generalization to unseen database schemas.
38
 
39
  ```python
40
  # to load the pure-SQL version instead:
 
50
  | HumanEval pass@1 | 52.0% | 40.0% | -12.0pp |
51
  | HumanEval+ (999 edge cases) | 46.0% | 34.0% | -12.0pp |
52
 
53
+ Training data was rebalanced to 50% [b-mc2/sql-create-context](https://huggingface.co/datasets/b-mc2/sql-create-context) + 50% [ise-uiuc/Magicoder-OSS-Instruct-75K](https://huggingface.co/datasets/ise-uiuc/Magicoder-OSS-Instruct-75K) (interleaved batch-wise via `datasets.interleave_datasets`, `stopping_strategy="first_exhausted"`), 1 epoch.
54
+
55
+ The two datasets are nearly the same size (~70.7k vs ~75.2k), so a 50/50 ratio consumes essentially all of both — 141,771 training examples, 8,861 optimizer steps.
56
 
57
  ## Results
58
 
 
70
  | Official Execution Accuracy | 39.9% | 50.4% | **60.8%** |
71
  | Official Exact Match (structural) | 32.1% | 37.4% | **47.3%** |
72
 
73
+ Compared with the pure-SQL version, this version generalizes substantially better to unseen schemas (+10.4pp execution accuracy) and retains more code capability, at no cost to in-distribution SQL accuracy (see below). Mixing in code data appears to act as a regularizer against overfitting to the narrow single-domain SQL distribution.
74
 
75
  ### In-distribution SQL accuracy (b-mc2/sql-create-context, same distribution as training)
76
 
77
+ Measured on the same 20-sample held-out set for all three models, in the same evaluation run:
78
+
79
+ | Model | Exact Match (n=20) |
80
  |------|-------------|
81
+ | Base | 0.0% |
82
+ | Pure-SQL SFT | 70.0% |
83
+ | This version (mixed) | 70.0% |
84
+
85
+ The two fine-tuned versions are **tied** here — mixing in code data cost nothing on the training distribution. Note that n=20 gives a wide confidence interval; the Spider result above (n=1034, real databases, official scripts) is the more reliable measurement.
86
+
87
+ Earlier numbers on this dataset used different splits and are superseded by the table above. Note that `sql-create-context` ships schemas with no data rows, so execution-based metrics on it mostly measure syntax/schema alignment rather than semantic correctness.
88
 
89
  ## LoRA configuration
90
 
 
99
  ## Quick start
100
 
101
  ```python
102
+ import torch
103
  from transformers import AutoModelForCausalLM, AutoTokenizer
104
  from peft import PeftModel
105
 
106
  base_model_id = "deepseek-ai/deepseek-coder-7b-instruct-v1.5"
107
  adapter_id = "albertkingdom/deepseek-coder-7b-text2sql-magicoder-lora"
108
 
109
+ model = AutoModelForCausalLM.from_pretrained(
110
+ base_model_id, torch_dtype=torch.bfloat16, device_map="auto"
111
+ )
112
  tokenizer = AutoTokenizer.from_pretrained(base_model_id)
113
  model = PeftModel.from_pretrained(model, adapter_id) # main = mixed training version
114
 
 
125
  }]
126
 
127
  inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(model.device)
128
+ outputs = model.generate(inputs, max_new_tokens=200, do_sample=False)
129
+ print(tokenizer.decode(outputs[0][inputs.shape[-1]:], skip_special_tokens=True))
130
  ```
131
 
132
+ The adapter was trained with exactly this instruction + `### Schema` / `### Question` layout wrapped in the DeepSeek chat template. Free-form prompts still work, but accuracy drops.
133
+
134
  ## Training procedure
135
 
136
+ Trained with SFT (TRL `SFTTrainer`) on an interleaved SQL + code instruction dataset, 1 epoch over 141,771 examples (8,861 steps), learning rate 1e-4 with linear decay and 3% warmup, effective batch size 16 (per-device 4 × gradient accumulation 4), max sequence length 1024, `paged_adamw_8bit`, bf16, 4-bit QLoRA, on a rented RTX 5090 (~12h). Final train loss 0.3986, eval loss 0.3437.
137
 
138
  ### Framework versions
139
 
140
+ - PEFT: 0.18.0
141
  - TRL: 0.26.2
142
  - Transformers: 4.57.3
143
  - Datasets: 4.4.2
144
+ - PyTorch: 2.9.1+cu128
145
 
146
  ## License
147
 
 
175
  howpublished = {\url{https://github.com/huggingface/trl}}
176
  }
177
  ```
178
+
179
+ ```bibtex
180
+ @article{yu2018spider,
181
+ title = {Spider: A Large-Scale Human-Labeled Dataset for Complex and Cross-Domain Semantic Parsing and Text-to-SQL Task},
182
+ author = {Yu, Tao and Zhang, Rui and Yang, Kai and Yasunaga, Michihiro and Wang, Dongxu and Li, Zifan and Ma, James and Li, Irene and Yao, Qingning and Roman, Shanelle and Zhang, Zilin and Radev, Dragomir},
183
+ journal = {arXiv preprint arXiv:1809.08887},
184
+ year = 2018
185
+ }
186
+ ```
187
+
188
+ ```bibtex
189
+ @article{wei2023magicoder,
190
+ title = {Magicoder: Empowering Code Generation with OSS-Instruct},
191
+ author = {Wei, Yuxiang and Wang, Zhe and Liu, Jiawei and Ding, Yifeng and Zhang, Lingming},
192
+ journal = {arXiv preprint arXiv:2312.02120},
193
+ year = 2023
194
+ }
195
+ ```