Downloads · 30 days
34
32% of all-time downloads
ritam-05/qwen2.5-7b-sql-specialist
qwen2.5-7b-sql-specialist is a text generation model from ritam-05. Use it when you need the model to write or continue text. It is set up for peft.
This is a fine-tuned LoRA adapter for Qwen/Qwen2.5-7B-Instruct, specifically trained to act as a Senior SQL Database Specialist. It accurately translates natural language questions into executable SQL queries based on…
Downloads · 30 days
34
32% of all-time downloads
All-time downloads
107
Public
Repo size
173 MB
Likes
0
Public
Click a slice to open those files.
.safetensors162 MB · 93%
From the Hugging Face model README
This is a fine-tuned LoRA adapter for Qwen/Qwen2.5-7B-Instruct, specifically trained to act as a Senior SQL Database Specialist. It accurately translates natural language questions into executable SQL queries based on provided database schemas.
Qwen/Qwen2.5-7B-InstructThis model is designed to take a database schema and a user question, and output only the executable SQL query enclosed in a markdown code block. It is instructed to avoid conversational filler.
To use this model, load the base model in 4-bit and attach this LoRA adapter:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
base_model_id = "Qwen/Qwen2.5-7B-Instruct"
adapter_id = "ritam-05/qwen2.5-7b-sql-specialist"
# Load base model in 4-bit
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16
)
base_model = AutoModelForCausalLM.from_pretrained(base_model_id, quantization_config=bnb_config, device_map="auto")
tokenizer = AutoTokenizer.from_pretrained(adapter_id)
# Attach adapter
model = PeftModel.from_pretrained(base_model, adapter_id)
# Test prompt
schema = "CREATE TABLE employees (emp_id INT, name VARCHAR, department VARCHAR, salary INT);"
question = "What is the average salary in the Engineering department?"
messages = [
{"role": "system", "content": "You are a Senior SQL Database Specialist. Output only the executable SQL query enclosed within a markdown code block."},
{"role": "user", "content": f"Database Schema:\n{schema}\n\nQuestion:\n{question}"}
]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer([text], return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=100, temperature=0.1)
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True))