Views
No views yet
CREATE TABLE schema provided in the prompt.trl (SFTTrainer) + peft.Qwen/Qwen2.5-1.5B-Instructbitsandbytes| Parameter | Value | Description |
|---|---|---|
| LoRA Rank (r) | 16 | Dimension of the low-rank update matrices. |
| LoRA Alpha | 16 | Scaling factor for LoRA. |
| Dropout | 0.05 | Regularization to prevent overfitting. |
| Target Modules | q_proj, k_proj, v_proj, o_proj | Layers targeted for adaptation. |
| Learning Rate | 2e-4 | Initial learning rate. |
| Batch Size | 4 | Per-device training batch size. |
| Epochs | 1 | Single pass over the instruct dataset. |
CREATE TABLE...).pip install transformers peft torch1import torch
2from peft import PeftModel
3from transformers import AutoModelForCausalLM, AutoTokenizer
4
5# 1. Configuration
6BASE_MODEL_ID = "Qwen/Qwen2.5-1.5B-Instruct"
7ADAPTER_ID = "manuelaschrittwieser/Qwen2.5-SQL-Assistant-Prod"
8
9# 2. Load Base Model (Load in 4-bit for efficiency if using GPU, or float32 for CPU)
10base_model = AutoModelForCausalLM.from_pretrained(
11 BASE_MODEL_ID,
12 device_map="auto",
13 torch_dtype=torch.float16
14)
15
16# 3. Load the Adapter
17model = PeftModel.from_pretrained(base_model, ADAPTER_ID)
18tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_ID)
19
20# 4. Define Context & Question
21schema = "CREATE TABLE users (id INT, name VARCHAR, age INT, city VARCHAR)"
22question = "How many users live in Paris?"
23
24# 5. Format Prompt (Qwen Chat Template)
25messages = [
26 {"role": "system", "content": "You are a SQL expert."},
27 {"role": "user", "content": f"{schema}\nQuestion: {question}"}
28]
29text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
30
31# 6. Generate
32inputs = tokenizer(text, return_tensors="pt").to(model.device)
33with torch.no_grad():
34 outputs = model.generate(**inputs, max_new_tokens=100)
35
36# 7. Decode Output
37print(tokenizer.decode(outputs[0], skip_special_tokens=True).split("assistant")[-1].strip())
38JOIN, GROUP BY, and WHERE clauses, highly complex nested sub-queries or database-specific dialect functions (like PostgreSQL JSONB operators) may not be generated correctly.