Update README.md
Browse files
README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
| 1 |
---
|
| 2 |
base_model: unsloth/meta-llama-3.1-8b-bnb-4bit
|
|
|
|
| 3 |
tags:
|
| 4 |
- text-generation
|
| 5 |
- sql-generation
|
| 6 |
-
-
|
| 7 |
- lora
|
| 8 |
- peft
|
| 9 |
- unsloth
|
| 10 |
-
-
|
| 11 |
license: apache-2.0
|
| 12 |
language:
|
| 13 |
- en
|
|
@@ -15,90 +16,95 @@ language:
|
|
| 15 |
|
| 16 |
# SQL-Genie (LLaMA-3.1-8B Fine-Tuned)
|
| 17 |
|
| 18 |
-
## Model Overview
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
**
|
| 21 |
-
The model was trained using **parameter-efficient fine-tuning (LoRA)** on a structured SQL instruction dataset, enabling accurate SQL query generation while keeping training and inference costs low.
|
| 22 |
|
| 23 |
- **Developed by:** dhashu
|
| 24 |
- **Base model:** `unsloth/meta-llama-3.1-8b-bnb-4bit`
|
| 25 |
- **License:** Apache-2.0
|
| 26 |
-
- **Training
|
| 27 |
|
| 28 |
---
|
| 29 |
|
| 30 |
-
## Training Methodology
|
| 31 |
|
| 32 |
-
This model was
|
| 33 |
|
| 34 |
-
### Key
|
| 35 |
- Base model loaded in **4-bit quantization** for memory efficiency
|
| 36 |
-
- **
|
| 37 |
-
-
|
| 38 |
-
-
|
| 39 |
-
-
|
|
|
|
| 40 |
|
| 41 |
-
This approach allows
|
| 42 |
|
| 43 |
---
|
| 44 |
|
| 45 |
-
## Dataset
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
The model was trained on a subset of the **`b-mc2/sql-create-context`** dataset, which contains:
|
| 48 |
- Natural language questions
|
| 49 |
-
- Database schema/context
|
| 50 |
- Corresponding SQL queries
|
| 51 |
|
| 52 |
-
Each sample was formatted as an instruction-style prompt to improve reasoning and output
|
| 53 |
|
| 54 |
---
|
| 55 |
|
| 56 |
-
## Performance & Efficiency
|
| 57 |
|
| 58 |
-
- ๐ **2ร faster fine-tuning** using
|
| 59 |
- ๐พ **Low VRAM usage** via 4-bit quantization
|
| 60 |
-
- ๐ง Improved
|
| 61 |
- โก Suitable for real-time inference and lightweight deployments
|
| 62 |
|
| 63 |
---
|
| 64 |
|
| 65 |
-
## Model Variants
|
| 66 |
-
|
| 67 |
-
This repository may contain **either**:
|
| 68 |
|
| 69 |
-
|
| 70 |
-
- Contains only LoRA weights
|
| 71 |
-
- Requires loading the base LLaMA-3.1-8B model
|
| 72 |
-
- Ideal for research and modular fine-tuning
|
| 73 |
|
| 74 |
-
### ๐น Merged Model
|
| 75 |
- LoRA adapters merged into base weights
|
| 76 |
- No PEFT required at inference time
|
| 77 |
- Ready-to-use single checkpoint
|
| 78 |
-
|
| 79 |
-
(Check the repository files to confirm the variant.)
|
| 80 |
|
| 81 |
---
|
| 82 |
|
| 83 |
-
##
|
| 84 |
-
|
| 85 |
-
- Natural language โ SQL query generation
|
| 86 |
-
- Database querying assistants
|
| 87 |
-
- AI-powered analytics tools
|
| 88 |
-
- Educational and research purposes
|
| 89 |
|
| 90 |
-
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
-
|
| 101 |
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
-
|
|
|
|
| 1 |
---
|
| 2 |
base_model: unsloth/meta-llama-3.1-8b-bnb-4bit
|
| 3 |
+
pipeline_tag: text-generation
|
| 4 |
tags:
|
| 5 |
- text-generation
|
| 6 |
- sql-generation
|
| 7 |
+
- llama
|
| 8 |
- lora
|
| 9 |
- peft
|
| 10 |
- unsloth
|
| 11 |
+
- transformers
|
| 12 |
license: apache-2.0
|
| 13 |
language:
|
| 14 |
- en
|
|
|
|
| 16 |
|
| 17 |
# SQL-Genie (LLaMA-3.1-8B Fine-Tuned)
|
| 18 |
|
| 19 |
+
## ๐ง Model Overview
|
| 20 |
+
|
| 21 |
+
**SQL-Genie** is a fine-tuned version of **LLaMA-3.1-8B**, specialized for converting **natural language questions into SQL queries**.
|
| 22 |
|
| 23 |
+
The model was trained using **parameter-efficient fine-tuning (LoRA)** on a structured SQL instruction dataset, enabling strong SQL generation performance while remaining lightweight and affordable to train on limited compute (Google Colab).
|
|
|
|
| 24 |
|
| 25 |
- **Developed by:** dhashu
|
| 26 |
- **Base model:** `unsloth/meta-llama-3.1-8b-bnb-4bit`
|
| 27 |
- **License:** Apache-2.0
|
| 28 |
+
- **Training stack:** Unsloth + Hugging Face TRL
|
| 29 |
|
| 30 |
---
|
| 31 |
|
| 32 |
+
## โ๏ธ Training Methodology
|
| 33 |
|
| 34 |
+
This model was trained using **LoRA (Low-Rank Adaptation)** via the **PEFT** framework.
|
| 35 |
|
| 36 |
+
### Key Details
|
| 37 |
- Base model loaded in **4-bit quantization** for memory efficiency
|
| 38 |
+
- **Base weights frozen**
|
| 39 |
+
- **LoRA adapters** applied to:
|
| 40 |
+
- Attention layers (`q_proj`, `k_proj`, `v_proj`, `o_proj`)
|
| 41 |
+
- Feed-forward layers (`gate_proj`, `up_proj`, `down_proj`)
|
| 42 |
+
- Fine-tuned using **Supervised Fine-Tuning (SFT)**
|
| 43 |
|
| 44 |
+
This approach allows efficient specialization without full model retraining.
|
| 45 |
|
| 46 |
---
|
| 47 |
|
| 48 |
+
## ๐ Dataset
|
| 49 |
+
|
| 50 |
+
The model was trained on a subset of the **`b-mc2/sql-create-context`** dataset, which includes:
|
| 51 |
|
|
|
|
| 52 |
- Natural language questions
|
| 53 |
+
- Database schema / context
|
| 54 |
- Corresponding SQL queries
|
| 55 |
|
| 56 |
+
Each sample was formatted as an **instruction-style prompt** to improve reasoning and structured output.
|
| 57 |
|
| 58 |
---
|
| 59 |
|
| 60 |
+
## ๐ Performance & Efficiency
|
| 61 |
|
| 62 |
+
- ๐ **2ร faster fine-tuning** using Unsloth
|
| 63 |
- ๐พ **Low VRAM usage** via 4-bit quantization
|
| 64 |
+
- ๐ง Improved SQL syntax and schema understanding
|
| 65 |
- โก Suitable for real-time inference and lightweight deployments
|
| 66 |
|
| 67 |
---
|
| 68 |
|
| 69 |
+
## ๐งฉ Model Variants
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
This repository contains a **merged model**:
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
+
### ๐น Merged 4-bit Model
|
| 74 |
- LoRA adapters merged into base weights
|
| 75 |
- No PEFT required at inference time
|
| 76 |
- Ready-to-use single checkpoint
|
| 77 |
+
- Optimized for easy deployment
|
|
|
|
| 78 |
|
| 79 |
---
|
| 80 |
|
| 81 |
+
## โถ๏ธ How to Use (Inference)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
```python
|
| 84 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 85 |
+
import torch
|
| 86 |
|
| 87 |
+
model_id = "dhashu/sql-genie-full"
|
| 88 |
|
| 89 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 90 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 91 |
+
model_id,
|
| 92 |
+
device_map="auto",
|
| 93 |
+
load_in_4bit=True,
|
| 94 |
+
)
|
| 95 |
|
| 96 |
+
prompt = """Below is an input question, context is given to help. Generate a SQL response.
|
| 97 |
+
### Input: List all employees hired after 2020
|
| 98 |
+
### Context: CREATE TABLE employees(id, name, hire_date)
|
| 99 |
+
### SQL Response:
|
| 100 |
+
"""
|
| 101 |
|
| 102 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 103 |
|
| 104 |
+
outputs = model.generate(
|
| 105 |
+
**inputs,
|
| 106 |
+
max_new_tokens=128,
|
| 107 |
+
temperature=0.7,
|
| 108 |
+
)
|
| 109 |
|
| 110 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|