File size: 1,726 Bytes
7f09fab
 
 
 
 
 
 
 
 
 
0cedb62
7f09fab
f9bd518
 
 
 
 
 
 
7f09fab
f9bd518
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f09fab
f9bd518
 
 
 
7f09fab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
license: apache-2.0
language:
- en
base_model:
- Qwen/Qwen2.5-Coder-3B-Instruct
tags:
- text-to-sql
- fine-tuned
- qwen
pipeline_tag: text-generation
---
This is a fine-tuned version of Qwen/Qwen2.5-Coder-3B-Instruct for generating SQL queries from natural language questions. The model was fine-tuned using LoRA (r=16) on a subset of the Spider dataset and merged into a standalone model, eliminating the need for the peft library during inference.
Usage
To use the model for SQL query generation:
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

# Load model and tokenizer
model_name = "Piyush026/Qwen2.5-Coder-3B-sql-finetuned"  # Replace with your repo ID
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.float16,
    device_map="auto",
    trust_remote_code=True
)


# Generate SQL query Example
prompt = """
Database: university
Schema:
- students: [student_id, first_name, last_name, department_code, gpa, major]
- departments: [department_code, department_name]
- courses: [course_number, course_title, professor_id]
- instructors: [professor_id, last_name]
Question: List all students.
"""
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_length=200)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))


## Training Details

Base Model: Qwen/Qwen2.5-Coder-3B-Instruct
Fine-Tuning: LoRA (r=16, lora_alpha=32, lora_dropout=0.05) on a 1000-sample subset of the Spider dataset.
Environment: Lightning AI Studio with Tesla T4 GPU.
Merged Model: The LoRA adapters were merged into the base model using merge_and_unload for standalone inference.