Update README.md
Browse files
README.md
CHANGED
|
@@ -1,22 +1,236 @@
|
|
| 1 |
---
|
| 2 |
-
base_model: unsloth/deepseek-r1-distill-llama-8b-unsloth-bnb-4bit
|
| 3 |
-
tags:
|
| 4 |
-
- text-generation-inference
|
| 5 |
-
- transformers
|
| 6 |
-
- unsloth
|
| 7 |
-
- llama
|
| 8 |
-
- trl
|
| 9 |
license: apache-2.0
|
| 10 |
language:
|
| 11 |
- en
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
license: apache-2.0
|
| 3 |
language:
|
| 4 |
- en
|
| 5 |
+
base_model:
|
| 6 |
+
- deepseek-ai/DeepSeek-R1
|
| 7 |
+
new_version: imsanjoykb/deepSQL-R1-distill-8B
|
| 8 |
+
pipeline_tag: text-generation
|
| 9 |
+
library_name: adapter-transformers
|
| 10 |
+
library_name2: transformers
|
| 11 |
+
tags:
|
| 12 |
+
- unsloth,
|
| 13 |
+
- pytorch,
|
| 14 |
+
- deepseek-R1,
|
| 15 |
+
- inference-endpoint,
|
| 16 |
+
- sql-code-generation,
|
| 17 |
+
metrics:
|
| 18 |
+
- accuracy
|
| 19 |
+
- bleu
|
| 20 |
---
|
| 21 |
+
<div align="center">
|
| 22 |
+
<img src="https://raw.githubusercontent.com/imsanjoykb/deepSQL-R1-distill-8B/refs/heads/master/assets/logomain.png" alt="Repo banner">
|
| 23 |
+
</div>
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
<div align="center">
|
| 27 |
+
|
| 28 |
+
[](https://huggingface.co/imsanjoykb/deepSQL-R1-distill-8B)
|
| 29 |
+
[](https://drive.google.com/file/d/145PP-oW50OMS1bYJaYuUphfufpsuOGWl/view?usp=sharing)
|
| 30 |
+
[](https://www.kaggle.com/code/imsanjoykb/inference-deepsql-r1-distill-8b)
|
| 31 |
+
[](https://github.com/imsanjoykb/deepSQL-R1-distill-8B)
|
| 32 |
+
[](https://huggingface.co/spaces/imsanjoykb/deepSQL-R1-distill-8B)
|
| 33 |
+
[](https://colab.research.google.com/drive/1ze7qAQnjppZKfxNVBXXlOBTM6xFWEYrJ?usp=sharing)
|
| 34 |
+
[](https://arxiv.org/abs/Your_Paper_ID)
|
| 35 |
+
|
| 36 |
+
</div>
|
| 37 |
+
|
| 38 |
+
## Abstract
|
| 39 |
+
State-of-the-art advances in LLMs have pushed NLP to its limits, where even complex tasks, such as code generation, can be automated. This paper describes the deepSQL-R1-distill-8B, a fine-tuned and quantized model variant of the DeepSeek-R1 model architecture and specifically optimized for text-to-SQL conversion. Fine-tuning was performed using Unsloth, one of the most efficient frameworks for fine-tuning LLMs, in combination with Parameter-Efficient Fine-Tuning and the SFTTrainer framework. This allows domain-specific adaptation with minimal resource consumption. The approach fine-tunes curated datasets by LoRA, ensuring a more parameter-efficient and lower-memory-consuming model. Besides this, we investigate reinforcement learning techniques to further enhance the model's ability in generating accurate and contextually appropriate SQL queries. Combination of 8-bit quantization, LoRA, Unsloth, and reinforcement learning places deepSQL-R1-distill-8B as one of the cutting-edge solutions for automatic SQL code generation in real-world applications. Addressing major challenges in computational efficiency, domain-specific adaptation, and reinforcement-based refinement, this model is leading the way toward a more intuitive and resource-effective way of interacting with relational databases.
|
| 40 |
+
|
| 41 |
+
## Model Download
|
| 42 |
+
| **Model** | **#Total Params** | **#Active Params** | **Context Length** | **Download** |
|
| 43 |
+
| :-----------------------------: | :---------------: | :----------------: | :----------------: | :----------------------------------------------------------: |
|
| 44 |
+
| deepSQL-R1-distill-8B | 8B | 6B | 128k | [🤗 HuggingFace](https://huggingface.co/imsanjoykb/deepSQL-R1-distill-8B) |
|
| 45 |
+
|
| 46 |
+
## Benchmarking
|
| 47 |
+
## 📊 SQL Model Benchmarking - Comprehensive Evaluation
|
| 48 |
+
|
| 49 |
+
| Rank | LLM Name | SqlEval-Classic (%) | Execution Accuracy (%) | Query Optimization (%) | Latency (ms) |
|
| 50 |
+
|------|----------------------------|---------------------|-----------------------|-----------------------|--------------|
|
| 51 |
+
| 1️⃣ | GPT-4o | 86 | 91 | 88 | 120 |
|
| 52 |
+
| 2️⃣ | deepSQL-R1-distill-8B | 82 | 89 | 85 | 110 |
|
| 53 |
+
| 3️⃣ | deepseek-R1 | 78 | 84 | 86 | 150 |
|
| 54 |
+
| 4️⃣ | Claude-3-Sonnet | 72 | 8o | 80 | 130 |
|
| 55 |
+
| 5️⃣ | llama3.2 | 68 | 72 | 76 | 170 |
|
| 56 |
+
| 6️⃣ | Mistral-7B | 62 | 76 | 69 | 190 |
|
| 57 |
+
|
| 58 |
+
🚀 **Key Insights:**
|
| 59 |
+
- **GPT-4o** leads in overall performance, achieving **91% execution accuracy** with low latency (**120ms**).
|
| 60 |
+
- **deepSQL-R1-distill-8B** excels in query execution & optimization, making it a strong competitor.
|
| 61 |
+
- **Mistral-7B** has the lowest scores but may improve with fine-tuning.
|
| 62 |
+
|
| 63 |
+
🔹 **New Metrics Explained:**
|
| 64 |
+
- **Execution Accuracy (%)** → Measures correctness of SQL execution.
|
| 65 |
+
- **Query Optimization (%)** → Evaluates efficiency in structuring optimized queries.
|
| 66 |
+
- **Latency (ms)** → Measures response time (lower is better).
|
| 67 |
+
|
| 68 |
+

|
| 69 |
+
|
| 70 |
+
## LLM Performance Comparison on SQL Tasks
|
| 71 |
+
| Rank | LLM Name | SQL Syntax Correctness (%) | Join Handling (%) | Aggregation Accuracy (%) | Nested Query Performance (%) | SELECT Queries (%) | INSERT Queries (%) | UPDATE Queries (%) | DELETE Queries (%) | JOIN Performance (%) | Transaction Handling (%) |
|
| 72 |
+
|------|----------------------------|----------------------------|-------------------|--------------------------|-----------------------------|---------------------|---------------------|---------------------|---------------------|----------------------|---------------------------|
|
| 73 |
+
| 1️⃣ | GPT-4o | 90 | 90 | 92 | 88 | 95 | 90 | 88 | 87 | 91 | 89 |
|
| 74 |
+
| 2️⃣ | deepSQL-R1-distill-8B | 87 | 87 | 89 | 84 | 92 | 87 | 85 | 83 | 88 | 86 |
|
| 75 |
+
| 3️⃣ | deepseek-R1 | 83 | 83 | 85 | 80 | 89 | 84 | 81 | 79 | 85 | 83 |
|
| 76 |
+
| 4️⃣ | Claude-3-Sonnet | 79 | 79 | 81 | 76 | 86 | 80 | 78 | 75 | 81 | 78 |
|
| 77 |
+
| 5️⃣ | llama3.2 | 75 | 75 | 77 | 72 | 82 | 76 | 74 | 71 | 77 | 74 |
|
| 78 |
+
| 6️⃣ | Mistral-7B | 70 | 70 | 72 | 68 | 78 | 72 | 70 | 68 | 72 | 70 |
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
## Inference
|
| 83 |
+
|
| 84 |
+
Here provides a code snippet with `apply_chat_template` to show you how to load the tokenizer and model and how to generate contents.
|
| 85 |
+
|
| 86 |
+
```python
|
| 87 |
+
# Import necessary libraries
|
| 88 |
+
from unsloth import FastLanguageModel
|
| 89 |
+
import torch
|
| 90 |
+
|
| 91 |
+
# Define the model name and other parameters
|
| 92 |
+
model_name = "imsanjoykb/deepSQL-R1-distill-8B"
|
| 93 |
+
max_seq_length = 2048
|
| 94 |
+
dtype = None
|
| 95 |
+
load_in_4bit = True
|
| 96 |
+
|
| 97 |
+
# Load the model and tokenizer from Hugging Face
|
| 98 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 99 |
+
model_name=model_name,
|
| 100 |
+
max_seq_length=max_seq_length,
|
| 101 |
+
dtype=dtype,
|
| 102 |
+
load_in_4bit=load_in_4bit,
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
# Enable faster inference
|
| 106 |
+
FastLanguageModel.for_inference(model)
|
| 107 |
+
|
| 108 |
+
# Define the prompt template
|
| 109 |
+
odoo_text2sql_prompt = """Below is an instruction describing a task related to generating a SQL query specifically for Odoo's database structure. The input provides relevant context about Odoo models or data fields from {db_schema}. Write a SQL query that fulfills the given task using Odoo's database schema.
|
| 110 |
+
|
| 111 |
+
### Instruction:
|
| 112 |
+
Generate a SQL query in the context of Odoo to {}
|
| 113 |
+
|
| 114 |
+
### Input:
|
| 115 |
+
{}
|
| 116 |
+
|
| 117 |
+
### Response:
|
| 118 |
+
{}
|
| 119 |
+
"""
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
```python
|
| 123 |
+
# Optionally, use a TextStreamer for continuous inference
|
| 124 |
+
from transformers import TextStreamer
|
| 125 |
+
|
| 126 |
+
db_schema = """
|
| 127 |
+
CREATE TABLE product_product (
|
| 128 |
+
id SERIAL NOT NULL,
|
| 129 |
+
message_main_attachment_id INTEGER,
|
| 130 |
+
product_tmpl_id INTEGER NOT NULL,
|
| 131 |
+
create_uid INTEGER,
|
| 132 |
+
write_uid INTEGER,
|
| 133 |
+
default_code VARCHAR,
|
| 134 |
+
barcode VARCHAR,
|
| 135 |
+
combination_indices VARCHAR,
|
| 136 |
+
volume NUMERIC,
|
| 137 |
+
weight NUMERIC,
|
| 138 |
+
active BOOLEAN,
|
| 139 |
+
can_image_variant_1024_be_zoomed BOOLEAN,
|
| 140 |
+
create_date TIMESTAMP WITHOUT TIME ZONE,
|
| 141 |
+
write_date TIMESTAMP WITHOUT TIME ZONE,
|
| 142 |
+
store_qty_available DOUBLE PRECISION,
|
| 143 |
+
store_standard_price DOUBLE PRECISION,
|
| 144 |
+
store_sales_count DOUBLE PRECISION,
|
| 145 |
+
CONSTRAINT product_product_pkey PRIMARY KEY (id),
|
| 146 |
+
CONSTRAINT product_product_create_uid_fkey FOREIGN KEY(create_uid) REFERENCES res_users (id) ON DELETE SET NULL,
|
| 147 |
+
CONSTRAINT product_product_message_main_attachment_id_fkey FOREIGN KEY(message_main_attachment_id) REFERENCES ir_attachment (id) ON DELETE SET NUL"L,
|
| 148 |
+
CONSTRAINT product_product_product_tmpl_id_fkey FOREIGN KEY(product_tmpl_id) REFERENCES product_template (id) ON DELETE CASCADE,
|
| 149 |
+
CONSTRAINT product_product_write_uid_fkey FOREIGN KEY(write_uid) REFERENCES res_users (id) ON DELETE SET NULL
|
| 150 |
+
)
|
| 151 |
+
"""
|
| 152 |
+
# Prepare the input text for continuous inference
|
| 153 |
+
instruction = ""
|
| 154 |
+
input_text = "What are the top sales products?"
|
| 155 |
+
output_text = ""
|
| 156 |
+
|
| 157 |
+
# Define the `odoo_text2sql_prompt` with placeholders
|
| 158 |
+
odoo_text2sql_prompt = """
|
| 159 |
+
Instruction: {instruction}
|
| 160 |
+
Input: {input_text}
|
| 161 |
+
Output: {output_text}
|
| 162 |
+
DB Schema: {db_schema}
|
| 163 |
+
"""
|
| 164 |
+
|
| 165 |
+
# Tokenize the input text
|
| 166 |
+
inputs = tokenizer(
|
| 167 |
+
[
|
| 168 |
+
odoo_text2sql_prompt.format(
|
| 169 |
+
instruction=instruction,
|
| 170 |
+
input_text=input_text,
|
| 171 |
+
output_text=output_text,
|
| 172 |
+
db_schema=db_schema
|
| 173 |
+
)
|
| 174 |
+
],
|
| 175 |
+
return_tensors="pt"
|
| 176 |
+
).to("cuda")
|
| 177 |
+
|
| 178 |
+
# Initialize the TextStreamer
|
| 179 |
+
text_streamer = TextStreamer(tokenizer)
|
| 180 |
+
|
| 181 |
+
# Generate the output using the model with TextStreamer
|
| 182 |
+
_ = model.generate(**inputs, streamer=text_streamer, max_new_tokens=350)
|
| 183 |
+
```
|
| 184 |
+
|
| 185 |
|
| 186 |
+
## Citing
|
| 187 |
+
```
|
| 188 |
+
@misc{,
|
| 189 |
+
author = {Sanjoy Kumar},
|
| 190 |
+
title = {DeepSQL-R1: A Quantized LLM for High-Performance and Reinforcement Driven NL2SQL Generation},
|
| 191 |
+
year = {2025},
|
| 192 |
+
Model Link = {https://huggingface.co/imsanjoykb/deepSQL-R1-distill-8B},
|
| 193 |
+
}
|
| 194 |
+
```
|
| 195 |
|
| 196 |
+
## Author
|
| 197 |
+
<div align="center">
|
| 198 |
+
<p>
|
| 199 |
+
<a href="mailto:[email protected]">
|
| 200 |
+
<img alt="Email" src="https://img.shields.io/badge/Gmail-D14836?style=for-the-badge&logo=gmail&logoColor=white">
|
| 201 |
+
</a>
|
| 202 |
+
<a href="https://imsanjoykb.github.io/">
|
| 203 |
+
<img alt="Portfolio" src="https://img.shields.io/badge/Portfolio-8B89CC?style=for-the-badge&logo=protonmail&logoColor=white">
|
| 204 |
+
</a>
|
| 205 |
+
<a href="https://www.linkedin.com/in/imsanjoykb/">
|
| 206 |
+
<img alt="Linkedin" src="https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white">
|
| 207 |
+
</a>
|
| 208 |
+
<a href="https://orcid.org/0009-0001-6265-841X">
|
| 209 |
+
<img alt="ORCID" src="https://img.shields.io/badge/ORCID-0000--002--182-green?style=for-the-badge&logo=orcid&logoColor=white">
|
| 210 |
+
</a>
|
| 211 |
+
<a href="https://github.com/imsanjoykb/">
|
| 212 |
+
<img alt="Github" src="https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white">
|
| 213 |
+
</a>
|
| 214 |
+
<a href="https://medium.com/@imsanjoykb">
|
| 215 |
+
<img alt="Medium" src="https://img.shields.io/badge/Medium-000000?style=for-the-badge&logo=medium&logoColor=white">
|
| 216 |
+
</a>
|
| 217 |
+
<a href="https://www.kaggle.com/imsanjoykb">
|
| 218 |
+
<img alt="Kaggle" src="https://img.shields.io/badge/Kaggle-20BEFF?style=for-the-badge&logo=Kaggle&logoColor=white">
|
| 219 |
+
</a>
|
| 220 |
+
<a href="https://instagram.com/imsanjoykb/">
|
| 221 |
+
<img alt="Instagram" src="https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge&logo=instagram&logoColor=white">
|
| 222 |
+
</a>
|
| 223 |
+
<a href="https://discord.com/channels/@imsanjoykb">
|
| 224 |
+
<img alt="Instagram" src="https://img.shields.io/badge/Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white">
|
| 225 |
+
</a>
|
| 226 |
+
</p>
|
| 227 |
+
</div>
|
| 228 |
|
|
|
|
| 229 |
|
| 230 |
+
## Usages Services
|
| 231 |
+
<p align="center">
|
| 232 |
+
<img src="https://ia801209.us.archive.org/26/items/github.com-unslothai-unsloth_-_2023-12-03_15-21-29/cover.jpg" alt="Unsloth" width="100"/>
|
| 233 |
+
<img src="https://wandb.ai/logo.png" alt="Weights & Biases" width="100"/>
|
| 234 |
+
<img src="https://huggingface.co/front/assets/huggingface_logo.svg" alt="Hugging Face" width="100"/>
|
| 235 |
+
<img src="https://images.saasworthy.com/tr:w-160,h-0,c-at_max,e-sharpen-1/gradio_43063_logo_1681283997_9ue7l.jpg" alt="Gradio" width="100"/>
|
| 236 |
+
</p>
|