Fine-tuned version of Qwen/Qwen2.5-1.5B-Instruct for
natural language to SQL generation using QLoRA (4-bit quantization + LoRA).
Model Description
This model takes a natural language question and a SQL table schema (one or more
CREATE TABLE statements) and returns the corresponding SQL query.
Base model: Qwen/Qwen2.5-1.5B-InstructFine-tuning method: QLoRA (4-bit NF4 + LoRA rank 16)
Task: Text-to-SQL generation
Training data: b-mc2/sql-create-context
Intended Use
SQL query generation from natural language in applications and chatbots
Database querying assistants
Prototyping text-to-SQL systems on a budget (1.5B parameters)
Out-of-scope: Production database systems without human review; complex multi-table
joins not represented in the training data; dialects other than standard SQL / SQLite.
Training was done on a single GPU (NVIDIA T4 / A100) using gradient checkpointing.
Experiment tracking: Weights & Biases
Evaluation Results
SQL Generation (500-sample validation subset)
Metric
Baseline
Fine-tuned
Delta
ROUGE-L
0.8784
0.9856
+0.1072
Exact Match
0.0000
0.7540
+0.7540
Catastrophic Forgetting (MMLU subset)
Subject
Accuracy
High School Mathematics
0.36
Computer Security
0.76
Moral Scenarios
0.32
Overall
0.48
The MMLU scores confirm general capability is retained after fine-tuning.
Limitations
Trained on a single domain (single-table SQL); performance degrades on complex multi-table queries
Standard SQL only — dialect-specific syntax (e.g., T-SQL window functions) may be unreliable
Always review generated SQL before executing against production databases
English-only questions
How to Use
python
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
34model_id ="samratkar77/qwen2.5-1.5b-sql-qlora"5tokenizer = AutoTokenizer.from_pretrained(model_id)6model = AutoModelForCausalLM.from_pretrained(7 model_id, torch_dtype=torch.float16, device_map="auto"8)910system_prompt =(11"You are an expert SQL assistant. "12"Given a natural language question and the relevant database schema, "13"write a single correct SQL query that answers the question. "14"Return only the SQL query with no explanation."15)1617question ="How many employees are in the sales department?"18context ="CREATE TABLE employees (id INT, name TEXT, department TEXT, salary REAL);"1920messages =[21{"role":"system","content": system_prompt},22{"role":"user","content":f"Given the following SQL tables:\n\n{context}\n\nWrite a SQL query to answer: {question}"},23]2425prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)26inputs = tokenizer(prompt, return_tensors="pt").to(model.device)2728with torch.no_grad():29 output = model.generate(**inputs, max_new_tokens=100, do_sample=False)3031new_tokens = output[0, inputs["input_ids"].shape[1]:]32print(tokenizer.decode(new_tokens, skip_special_tokens=True))33# Expected: SELECT COUNT(*) FROM employees WHERE department = 'sales';
If you use this model, please cite the base model and dataset:
@misc{qwen2.5-1.5b-sql-qlora,
author = {samratkar77},
title = {Qwen2.5-1.5B fine-tuned for Text-to-SQL with QLoRA},
year = {2025},
url = {https://huggingface.co/samratkar77/qwen2.5-1.5b-sql-qlora}
}