Qwen2.5-1.5B SQL Assistant

A fine-tuned text-to-SQL model designed to translate natural language questions into valid SQL queries given a database context and table schema.

Model Details

Model Description

This model is a fine-tuned, merged version of Qwen/Qwen2.5-1.5B-Instruct. It was trained using QLoRA with Hugging Face's SFTTrainer on a structured SQL context dataset and subsequently merged back into full 16-bit precision (fp16) for direct inference.

  • Developed by: RahulPi
  • Model type: Causal Language Model
  • Language(s): English
  • License: Apache 2.0
  • Finetuned from model: Qwen/Qwen2.5-1.5B-Instruct

Uses

Direct Use

Generating SQL queries based on database context and user prompts.

Prompt Format

The model was trained using the following template format:

System: You are a strict SQL assistant. Output ONLY valid SQL queries.
User: Schema: <context/schema> Question: <natural_language_question>
Assistant: <sql_query>

How to Get Started with the Model

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "RahulPi/qwen2.5-1.5B-sql"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.float16,
    device_map="auto"
)

context = "CREATE TABLE head (born_state VARCHAR, age INTEGER)"
question = "How many heads were born in California and are older than 50?"

prompt = (
    f"System: You are a strict SQL assistant. Output ONLY valid SQL queries.\n"
    f"User: Schema: {context} Question: {question}\n"
    f"Assistant:"
)

inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=128)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))

Training Details

Training Data

Trained on a 1,000-row subset of b-mc2/sql-create-context, combining table schemas and questions mapped directly to correct SQL target queries.

Training Procedure

  • Framework: TRL SFTTrainer with PEFT (QLoRA)
  • Base Precision: Loaded in 4-bit (NormalFloat4) during training, merged into fp16 for distribution
  • LoRA Target Modules: q_proj, k_proj, v_proj, o_proj
  • LoRA Parameters: r = 16, alpha = 32, Dropout = 0.05

Training Hyperparameters

  • Learning Rate: 2e-4
  • Scheduler: Cosine
  • Batch Size: 4 per device
  • Gradient Accumulation Steps: 4 (Effective batch size: 16)
  • Optimizer: paged_adamw_32bit
  • Max Sequence Length: 2048
  • Epochs: 3 (189 global steps)

Results

  • Final Training Loss: 0.7238
  • Mean Token Accuracy: 85.97%
  • Training Runtime: 1707 seconds (28.5 minutes on NVIDIA T4)
Downloads last month
211
Safetensors
Model size
2B params
Tensor type
F16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for RahulPi/qwen2.5-1.5B-sql

Finetuned
(1769)
this model

Dataset used to train RahulPi/qwen2.5-1.5B-sql