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

Replace with SQL+Magicoder mixed-training adapter (better SQL generalization + retained code capability, see experiment_log.md)

Browse files
README.md CHANGED
@@ -1,102 +1,51 @@
1
  ---
2
  base_model: deepseek-ai/deepseek-coder-7b-instruct-v1.5
3
- library_name: peft
4
- model_name: sql-adapter
5
  tags:
6
- - base_model:adapter:deepseek-ai/deepseek-coder-7b-instruct-v1.5
7
- - lora
8
- - sft
9
- - text-to-sql
10
  - trl
11
- license: apache-2.0
12
- pipeline_tag: text-generation
13
- datasets:
14
- - b-mc2/sql-create-context
15
- - ise-uiuc/Magicoder-OSS-Instruct-75K
16
  ---
17
 
18
- # Model Card for sql-adapter
19
-
20
- LoRA adapter fine-tuned from [deepseek-ai/deepseek-coder-7b-instruct-v1.5](https://huggingface.co/deepseek-ai/deepseek-coder-7b-instruct-v1.5) for text-to-SQL generation, trained with [TRL](https://github.com/huggingface/trl) SFTTrainer.
21
-
22
- ## What's new in this version
23
-
24
- The first version of this adapter was trained on 100% SQL data (`b-mc2/sql-create-context`) and showed catastrophic forgetting of general code generation ability (HumanEval pass@1 dropped from 60% to 50%, HumanEval+ from 50% to 40%).
25
-
26
- This version mixes in code-instruction data during training to mitigate that regression:
27
-
28
- | Dataset | Mix ratio | Purpose |
29
- |---|---|---|
30
- | [b-mc2/sql-create-context](https://huggingface.co/datasets/b-mc2/sql-create-context) | 30% | Text-to-SQL |
31
- | [ise-uiuc/Magicoder-OSS-Instruct-75K](https://huggingface.co/datasets/ise-uiuc/Magicoder-OSS-Instruct-75K) | 70% | Preserve general code generation ability |
32
-
33
- Mixing was done batch-wise via `datasets.interleave_datasets`. Learning rate was also lowered (2e-4 → 1e-4) and epochs increased (1 → 2) to compensate for the reduced SQL share.
34
-
35
- > Note: post-training benchmark numbers for this mixed-data run have not been re-measured yet. The SQL Exact Match / HumanEval numbers below are from the prior 100%-SQL run, kept here for reference; treat this release as a mitigation for known degradation rather than a verified improvement.
36
-
37
- ## LoRA configuration
38
-
39
- ```
40
- r: 16
41
- lora_alpha: 32
42
- lora_dropout: 0.05
43
- target_modules: [q_proj, k_proj, v_proj, o_proj]
44
- quantization: 4-bit NF4 (QLoRA), bf16 compute
45
- ```
46
-
47
- ## Prior version results (100% SQL training)
48
 
49
- | Metric | Base | SFT | Δ |
50
- |---|---|---|---|
51
- | SQL Exact Match (50 samples, sql-create-context) | 4% (2/50) | 78% (39/50) | +74% |
52
- | HumanEval pass@1 | 60% | 50% | -10% |
53
- | HumanEval+ (plus) | 50% | 40% | -10% |
54
 
55
  ## Quick start
56
 
57
  ```python
58
- from transformers import AutoModelForCausalLM, AutoTokenizer
59
- from peft import PeftModel
60
-
61
- base_model_id = "deepseek-ai/deepseek-coder-7b-instruct-v1.5"
62
- adapter_id = "albertkingdom/deepseek-coder-7b-instruct-sql-create-context-lora"
63
-
64
- model = AutoModelForCausalLM.from_pretrained(base_model_id, device_map="auto")
65
- tokenizer = AutoTokenizer.from_pretrained(base_model_id)
66
- model = PeftModel.from_pretrained(model, adapter_id)
67
-
68
- messages = [{
69
- "role": "user",
70
- "content": """Given the database schema below, write a SQL query that answers the user's question.
71
- Only output the SQL query. Do not add any explanation.
72
-
73
- ### Schema
74
- CREATE TABLE users (id INT, name VARCHAR(100), email VARCHAR(100))
75
 
76
- ### Question
77
- Find all users with gmail addresses"""
78
- }]
79
-
80
- inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True).to(model.device)
81
- outputs = model.generate(inputs, max_new_tokens=200)
82
- print(tokenizer.decode(outputs[0], skip_special_tokens=True))
83
  ```
84
 
85
  ## Training procedure
86
 
87
- Trained with SFT (TRL `SFTTrainer`) on an interleaved SQL + code instruction dataset, 2 epochs, effective batch size 16, bf16, 4-bit QLoRA.
 
 
 
88
 
89
  ### Framework versions
90
 
91
- - PEFT 0.18.0
92
  - TRL: 0.26.2
93
  - Transformers: 4.57.3
94
- - Pytorch: 2.9.1+cu128
95
  - Datasets: 4.4.2
96
- - Tokenizers: 0.22.1
97
 
98
  ## Citations
99
 
 
 
 
 
100
  ```bibtex
101
  @misc{vonwerra2022trl,
102
  title = {{TRL: Transformer Reinforcement Learning}},
@@ -106,4 +55,4 @@ Trained with SFT (TRL `SFTTrainer`) on an interleaved SQL + code instruction dat
106
  publisher = {GitHub},
107
  howpublished = {\url{https://github.com/huggingface/trl}}
108
  }
109
- ```
 
1
  ---
2
  base_model: deepseek-ai/deepseek-coder-7b-instruct-v1.5
3
+ library_name: transformers
4
+ model_name: deepseek-sql-magicoder-adapter
5
  tags:
6
+ - generated_from_trainer
 
 
 
7
  - trl
8
+ - sft
9
+ licence: license
 
 
 
10
  ---
11
 
12
+ # Model Card for deepseek-sql-magicoder-adapter
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ This model is a fine-tuned version of [deepseek-ai/deepseek-coder-7b-instruct-v1.5](https://huggingface.co/deepseek-ai/deepseek-coder-7b-instruct-v1.5).
15
+ It has been trained using [TRL](https://github.com/huggingface/trl).
 
 
 
16
 
17
  ## Quick start
18
 
19
  ```python
20
+ from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
23
+ generator = pipeline("text-generation", model="albertkingdom/deepseek-sql-magicoder-adapter", device="cuda")
24
+ output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
25
+ print(output["generated_text"])
 
 
 
26
  ```
27
 
28
  ## Training procedure
29
 
30
+
31
+
32
+
33
+ This model was trained with SFT.
34
 
35
  ### Framework versions
36
 
 
37
  - TRL: 0.26.2
38
  - Transformers: 4.57.3
39
+ - Pytorch: 2.13.0
40
  - Datasets: 4.4.2
41
+ - Tokenizers: 0.22.2
42
 
43
  ## Citations
44
 
45
+
46
+
47
+ Cite TRL as:
48
+
49
  ```bibtex
50
  @misc{vonwerra2022trl,
51
  title = {{TRL: Transformer Reinforcement Learning}},
 
55
  publisher = {GitHub},
56
  howpublished = {\url{https://github.com/huggingface/trl}}
57
  }
58
+ ```
adapter_config.json CHANGED
@@ -31,8 +31,8 @@
31
  "target_modules": [
32
  "q_proj",
33
  "k_proj",
34
- "v_proj",
35
- "o_proj"
36
  ],
37
  "target_parameters": null,
38
  "task_type": "CAUSAL_LM",
 
31
  "target_modules": [
32
  "q_proj",
33
  "k_proj",
34
+ "o_proj",
35
+ "v_proj"
36
  ],
37
  "target_parameters": null,
38
  "task_type": "CAUSAL_LM",
adapter_model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6dc0af55be3a57e2c06c8711404b08f4275720b9c14cf5c0d3d17404efb6d30b
3
  size 31489712
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:26b86b81011abc81389fc1caaf1eaf5b4e59a9f4296cfe635a1aec179cf823a8
3
  size 31489712
training_args.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:25941047b55392a17105f7d307e5e32a8ca111a740a6b127f23e5d258067463c
3
  size 6225
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:877b839418ca0ec86b9b662e6b3ffafcd190c512dcf6b00b0828e8f521193da8
3
  size 6225