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
Update adapter: mix Magicoder code data (30% SQL / 70% code) to mitigate code-capability degradation
Browse files
README.md
CHANGED
|
@@ -6,34 +6,85 @@ tags:
|
|
| 6 |
- base_model:adapter:deepseek-ai/deepseek-coder-7b-instruct-v1.5
|
| 7 |
- lora
|
| 8 |
- sft
|
| 9 |
-
-
|
| 10 |
- trl
|
| 11 |
-
|
| 12 |
pipeline_tag: text-generation
|
|
|
|
|
|
|
|
|
|
| 13 |
---
|
| 14 |
|
| 15 |
# Model Card for sql-adapter
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
## Quick start
|
| 21 |
|
| 22 |
```python
|
| 23 |
-
from transformers import
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
|
| 28 |
-
print(output["generated_text"])
|
| 29 |
-
```
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
### Framework versions
|
| 39 |
|
|
@@ -46,10 +97,6 @@ This model was trained with SFT.
|
|
| 46 |
|
| 47 |
## Citations
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
Cite TRL as:
|
| 52 |
-
|
| 53 |
```bibtex
|
| 54 |
@misc{vonwerra2022trl,
|
| 55 |
title = {{TRL: Transformer Reinforcement Learning}},
|
|
@@ -59,4 +106,4 @@ Cite TRL as:
|
|
| 59 |
publisher = {GitHub},
|
| 60 |
howpublished = {\url{https://github.com/huggingface/trl}}
|
| 61 |
}
|
| 62 |
-
```
|
|
|
|
| 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 |
|
|
|
|
| 97 |
|
| 98 |
## Citations
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
```bibtex
|
| 101 |
@misc{vonwerra2022trl,
|
| 102 |
title = {{TRL: Transformer Reinforcement Learning}},
|
|
|
|
| 106 |
publisher = {GitHub},
|
| 107 |
howpublished = {\url{https://github.com/huggingface/trl}}
|
| 108 |
}
|
| 109 |
+
```
|