manuelaschrittwieser commited on
Commit
1cc6e9e
Β·
verified Β·
1 Parent(s): a9fd74b

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +134 -39
README.md CHANGED
@@ -1,62 +1,157 @@
1
  ---
2
  base_model: Qwen/Qwen2.5-1.5B-Instruct
3
  library_name: peft
4
- model_name: v1
 
 
 
 
 
5
  tags:
6
- - base_model:adapter:Qwen/Qwen2.5-1.5B-Instruct
 
 
 
7
  - lora
8
- - sft
9
- - transformers
10
- - trl
11
- licence: license
12
  pipeline_tag: text-generation
 
 
 
 
 
 
 
 
13
  ---
14
 
15
- # Model Card for v1
16
 
17
- This model is a fine-tuned version of [Qwen/Qwen2.5-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct).
18
- It has been trained using [TRL](https://github.com/huggingface/trl).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- ## Quick start
 
 
 
 
21
 
22
- ```python
23
- from transformers import pipeline
 
24
 
25
- 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?"
26
- generator = pipeline("text-generation", model="None", device="cuda")
27
- output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
28
- print(output["generated_text"])
 
29
  ```
30
 
31
- ## Training procedure
32
 
33
- [<img src="https://raw.githubusercontent.com/wandb/assets/main/wandb-github-badge-28.svg" alt="Visualize in Weights & Biases" width="150" height="24"/>](https://wandb.ai/manuelaschrittwieser99-neuralstack-ms/sql-assistant/runs/8ftaccqr)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
 
 
 
 
 
 
35
 
36
- This model was trained with SFT.
 
 
 
37
 
38
- ### Framework versions
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
- - PEFT 0.18.0
41
- - TRL: 0.26.2
42
- - Transformers: 4.57.3
43
- - Pytorch: 2.9.0+cu126
44
- - Datasets: 4.0.0
45
- - Tokenizers: 0.22.1
46
 
47
- ## Citations
 
 
 
48
 
49
 
50
 
51
- Cite TRL as:
52
-
53
- ```bibtex
54
- @misc{vonwerra2022trl,
55
- title = {{TRL: Transformer Reinforcement Learning}},
56
- author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
57
- year = 2020,
58
- journal = {GitHub repository},
59
- publisher = {GitHub},
60
- howpublished = {\url{https://github.com/huggingface/trl}}
61
- }
62
- ```
 
1
  ---
2
  base_model: Qwen/Qwen2.5-1.5B-Instruct
3
  library_name: peft
4
+ license: mit
5
+ datasets:
6
+ - b-mc2/sql-create-context
7
+ language:
8
+ - en
9
+ - de
10
  tags:
11
+ - text-to-sql
12
+ - qwen
13
+ - qwen2.5
14
+ - peft
15
  - lora
16
+ - qlora
17
+ - generated_from_trainer
18
+ - code-generation
 
19
  pipeline_tag: text-generation
20
+ widget:
21
+ - text: |
22
+ <|im_start|>system
23
+ You are a SQL expert.<|im_end|>
24
+ <|im_start|>user
25
+ CREATE TABLE employees (id INT, name VARCHAR, department VARCHAR, salary INT)
26
+ Question: List the names of employees in the Sales department.<|im_end|>
27
+ <|im_start|>assistant
28
  ---
29
 
30
+ # Qwen 2.5 (1.5B) - SQL Assistant Production Adapter
31
 
32
+ [![Hugging Face Space](https://img.shields.io/badge/πŸ€—%20Hugging%20Face-Live%20Demo-yellow)](https://huggingface.co/spaces/manuelaschrittwieser/SQL-Assistant-Prod)
33
+ [<img src="https://raw.githubusercontent.com/wandb/assets/main/wandb-github-badge-28.svg" alt="Visualize in Weights & Biases" width="150" height="24"/>](https://wandb.ai/manuelaschrittwieser99-neuralstack-ms/sql-assistant/runs/8ftaccqr)
34
+ ![License](https://img.shields.io/badge/License-MIT-green)
35
+
36
+ ## πŸ“‘ Model Overview
37
+
38
+ **Qwen2.5-SQL-Assistant-Prod** is a specialized parameter-efficient fine-tune (PEFT) of the [Qwen 2.5 1.5B Instruct](https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct) large language model.
39
+
40
+ This model is engineered to function as a technical assistant capable of translating natural language questions into syntactically correct SQL queries. It relies on a provided database schema (context) to ensure column and table names are hallucination-free.
41
+
42
+ ### Key Capabilities
43
+ * **Context-Aware Generation:** Adheres strictly to the `CREATE TABLE` schema provided in the prompt.
44
+ * **Low-Latency Inference:** Optimized for consumer hardware (CPU friendly) due to the lightweight 1.5B parameter count and LoRA adapter architecture.
45
+ * **Agentic Integration:** Designed to serve as the reasoning engine for autonomous SQL agents.
46
+
47
+ ---
48
+
49
+ ## πŸ“Š Training Telemetry & Metrics
50
+
51
+ The training process was tracked and visualized using **Weights & Biases** to ensure stability and convergence.
52
+
53
+ **[πŸ‘‰ Click here to view the full W&B Training Run / Charts](https://wandb.ai/manuelaschrittwieser99-neuralstack-ms/sql-assistant/runs/8ftaccqr)**
54
+
55
+ * **Training Loss:** Monitored to ensure no overfitting on the SQL syntax patterns.
56
+ * **Hardware:** Trained on NVIDIA T4 GPU.
57
+ * **Framework:** Hugging Face `trl` (SFTTrainer) + `peft`.
58
+
59
+ ---
60
+
61
+ ## πŸ› οΈ Technical Specifications
62
+
63
+ ### Architecture
64
+ * **Base Model:** `Qwen/Qwen2.5-1.5B-Instruct`
65
+ * **Adaptation Method:** QLoRA (Quantized Low-Rank Adaptation)
66
+ * **Quantization:** 4-bit NormalFloat (NF4) via `bitsandbytes`
67
+
68
+ ### Hyperparameters
69
+ | Parameter | Value | Description |
70
+ | :--- | :--- | :--- |
71
+ | **LoRA Rank (r)** | 16 | Dimension of the low-rank update matrices. |
72
+ | **LoRA Alpha** | 16 | Scaling factor for LoRA. |
73
+ | **Dropout** | 0.05 | Regularization to prevent overfitting. |
74
+ | **Target Modules** | `q_proj`, `k_proj`, `v_proj`, `o_proj` | Layers targeted for adaptation. |
75
+ | **Learning Rate** | 2e-4 | Initial learning rate. |
76
+ | **Batch Size** | 4 | Per-device training batch size. |
77
+ | **Epochs** | 1 | Single pass over the instruct dataset. |
78
 
79
+ ### Dataset
80
+ The model was fine-tuned on **[b-mc2/sql-create-context](https://huggingface.co/datasets/b-mc2/sql-create-context)**, a dataset containing pairs of:
81
+ 1. **Context:** SQL Schema definition (`CREATE TABLE...`).
82
+ 2. **Question:** Natural language inquiry.
83
+ 3. **Answer:** Gold-standard SQL query.
84
 
85
+ ---
86
+
87
+ ## πŸ’» Usage Instructions
88
 
89
+ This model is an **adapter**. You must load the base Qwen model first and then attach these adapter weights.
90
+
91
+ ### Prerequisite
92
+ ```bash
93
+ pip install transformers peft torch
94
  ```
95
 
96
+ ## Inference Code
97
 
98
+ ```Python
99
+ import torch
100
+ from peft import PeftModel
101
+ from transformers import AutoModelForCausalLM, AutoTokenizer
102
+
103
+ # 1. Configuration
104
+ BASE_MODEL_ID = "Qwen/Qwen2.5-1.5B-Instruct"
105
+ ADAPTER_ID = "manuelaschrittwieser/Qwen2.5-SQL-Assistant-Prod"
106
+
107
+ # 2. Load Base Model (Load in 4-bit for efficiency if using GPU, or float32 for CPU)
108
+ base_model = AutoModelForCausalLM.from_pretrained(
109
+ BASE_MODEL_ID,
110
+ device_map="auto",
111
+ torch_dtype=torch.float16
112
+ )
113
+
114
+ # 3. Load the Adapter
115
+ model = PeftModel.from_pretrained(base_model, ADAPTER_ID)
116
+ tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_ID)
117
+
118
+ # 4. Define Context & Question
119
+ schema = "CREATE TABLE users (id INT, name VARCHAR, age INT, city VARCHAR)"
120
+ question = "How many users live in Paris?"
121
 
122
+ # 5. Format Prompt (Qwen Chat Template)
123
+ messages = [
124
+ {"role": "system", "content": "You are a SQL expert."},
125
+ {"role": "user", "content": f"{schema}\nQuestion: {question}"}
126
+ ]
127
+ text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
128
 
129
+ # 6. Generate
130
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
131
+ with torch.no_grad():
132
+ outputs = model.generate(**inputs, max_new_tokens=100)
133
 
134
+ # 7. Decode Output
135
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True).split("assistant")[-1].strip())
136
+
137
+ ```
138
+
139
+ ---
140
+
141
+ ## ⚠️ Limitations
142
+
143
+ * **Prompt Sensitivity:** The model performs best when the database schema is explicitly provided in the system or user prompt.
144
+ * **Complex Logic:** While proficient at `JOIN`, `GROUP BY`, and `WHERE` clauses, highly complex nested sub-queries or database-specific dialect functions (like PostgreSQL JSONB operators) may not be generated correctly.
145
+ * **Security:** This model generates SQL code. **Always** sanitize and review generated queries before executing them on a production database to prevent SQL injection vulnerabilities.
146
+
147
+ ---
148
 
149
+ ## πŸ“œ Framework Versions
 
 
 
 
 
150
 
151
+ * **PEFT:** 0.18.0
152
+ * **Transformers:** 4.37.0+
153
+ * **TRL:** 0.26.2
154
+ * **PyTorch:** 2.1.0+
155
 
156
 
157