Instructions to use albertkingdom/deepseek-coder-7b-text2sql-magicoder-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use albertkingdom/deepseek-coder-7b-text2sql-magicoder-lora with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-coder-7b-instruct-v1.5") model = PeftModel.from_pretrained(base_model, "albertkingdom/deepseek-coder-7b-text2sql-magicoder-lora") - Notebooks
- Google Colab
- Kaggle
Replace with SQL+Magicoder mixed-training adapter (better SQL generalization + retained code capability, see experiment_log.md)
Browse files- README.md +24 -75
- adapter_config.json +2 -2
- adapter_model.safetensors +1 -1
- training_args.bin +1 -1
README.md
CHANGED
|
@@ -1,102 +1,51 @@
|
|
| 1 |
---
|
| 2 |
base_model: deepseek-ai/deepseek-coder-7b-instruct-v1.5
|
| 3 |
-
library_name:
|
| 4 |
-
model_name: sql-adapter
|
| 5 |
tags:
|
| 6 |
-
-
|
| 7 |
-
- lora
|
| 8 |
-
- sft
|
| 9 |
-
- text-to-sql
|
| 10 |
- trl
|
| 11 |
-
|
| 12 |
-
|
| 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 |
-
|
| 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
|
| 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 |
-
|
| 77 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
### Framework versions
|
| 90 |
|
| 91 |
-
- PEFT 0.18.0
|
| 92 |
- TRL: 0.26.2
|
| 93 |
- Transformers: 4.57.3
|
| 94 |
-
- Pytorch: 2.
|
| 95 |
- Datasets: 4.4.2
|
| 96 |
-
- Tokenizers: 0.22.
|
| 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 |
-
"
|
| 35 |
-
"
|
| 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:
|
| 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:
|
| 3 |
size 6225
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:877b839418ca0ec86b9b662e6b3ffafcd190c512dcf6b00b0828e8f521193da8
|
| 3 |
size 6225
|