Qwen2.5-7B SQL Specialist (QLoRA Adapter)

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.

Model Details

  • Base Model: Qwen/Qwen2.5-7B-Instruct
  • Fine-tuning Method: QLoRA (4-bit quantization) via PEFT
  • Task: Text-to-SQL generation
  • Language: English / SQL

Intended Use

This 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.

Training Details

  • Hardware: Trained on an NVIDIA T4 GPU (Kaggle).
  • Hyperparameters:
    • Batch size: 1 (with gradient accumulation steps = 16)
    • Learning rate: 2e-4 (Cosine schedule)
    • Mixed precision: fp16
    • LoRA Rank (r): 16
    • LoRA Alpha: 32

How to Get Started

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))
Downloads last month
46
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for ritam-05/qwen2.5-7b-sql-specialist

Base model

Qwen/Qwen2.5-7B
Adapter
(2834)
this model