dhashu commited on
Commit
874f657
ยท
verified ยท
1 Parent(s): a0ea55c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +52 -46
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
- - finetuning
7
  - lora
8
  - peft
9
  - unsloth
10
- - llama
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
- **SQL-Genie** is a fine-tuned version of **LLaMA-3.1-8B**, specialized for **natural language to SQL generation**.
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 framework:** Unsloth + Hugging Face TRL
27
 
28
  ---
29
 
30
- ## Training Methodology
31
 
32
- This model was fine-tuned using **LoRA (Low-Rank Adaptation)** via the **PEFT** framework.
33
 
34
- ### Key Training Details
35
  - Base model loaded in **4-bit quantization** for memory efficiency
36
- - **LoRA adapters** applied to attention and feed-forward layers
37
- - Base model weights remained **frozen**
38
- - Only LoRA parameters were trained
39
- - Training performed using **Supervised Fine-Tuning (SFT)**
 
40
 
41
- This approach allows the model to learn SQL generation patterns efficiently without full model retraining.
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 structure.
53
 
54
  ---
55
 
56
- ## Performance & Efficiency
57
 
58
- - ๐Ÿš€ **2ร— faster fine-tuning** using **Unsloth**
59
  - ๐Ÿ’พ **Low VRAM usage** via 4-bit quantization
60
- - ๐Ÿง  Improved schema understanding and SQL syntax generation
61
  - โšก Suitable for real-time inference and lightweight deployments
62
 
63
  ---
64
 
65
- ## Model Variants
66
-
67
- This repository may contain **either**:
68
 
69
- ### ๐Ÿ”น LoRA Adapter Model
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 (if applicable)
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
- ## Intended Use Cases
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
- ## Limitations
93
 
94
- - Trained on a limited SQL dataset subset
95
- - Not guaranteed to generalize to all SQL dialects
96
- - Should be validated before production database usage
 
 
 
97
 
98
- ---
 
 
 
 
99
 
100
- ## Acknowledgements
101
 
102
- This model was trained using **Unsloth**, enabling faster and more memory-efficient fine-tuning of large language models.
 
 
 
 
103
 
104
- [![Made with Unsloth](https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png)](https://github.com/unslothai/unsloth)
 
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))