Instructions to use ashishsahu2008/qwen2.5-3b-text2sql with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ashishsahu2008/qwen2.5-3b-text2sql with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ashishsahu2008/qwen2.5-3b-text2sql") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("ashishsahu2008/qwen2.5-3b-text2sql") model = AutoModelForCausalLM.from_pretrained("ashishsahu2008/qwen2.5-3b-text2sql") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ashishsahu2008/qwen2.5-3b-text2sql with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ashishsahu2008/qwen2.5-3b-text2sql" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ashishsahu2008/qwen2.5-3b-text2sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ashishsahu2008/qwen2.5-3b-text2sql
- SGLang
How to use ashishsahu2008/qwen2.5-3b-text2sql with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "ashishsahu2008/qwen2.5-3b-text2sql" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ashishsahu2008/qwen2.5-3b-text2sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "ashishsahu2008/qwen2.5-3b-text2sql" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ashishsahu2008/qwen2.5-3b-text2sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use ashishsahu2008/qwen2.5-3b-text2sql with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for ashishsahu2008/qwen2.5-3b-text2sql to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for ashishsahu2008/qwen2.5-3b-text2sql to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for ashishsahu2008/qwen2.5-3b-text2sql to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="ashishsahu2008/qwen2.5-3b-text2sql", max_seq_length=2048, ) - Docker Model Runner
How to use ashishsahu2008/qwen2.5-3b-text2sql with Docker Model Runner:
docker model run hf.co/ashishsahu2008/qwen2.5-3b-text2sql
Qwen2.5-3B Text-to-SQL
A fine-tuned version of Qwen2.5-3B-Instruct that converts natural-language questions into SQL queries, given a database schema. Trained with LoRA/QLoRA on a single free GPU.
- Developed by: ashishsahu2008
- Base model: unsloth/Qwen2.5-3B-Instruct
- Fine-tuned on: b-mc2/sql-create-context
- License: apache-2.0
- Live demo: https://huggingface.co/spaces/ashishsahu2008/text2sql-demo
- Code / write-up: https://github.com/ashishsahu2008/fine-tuning
What it does
Give it a CREATE TABLE schema and a plain-English question, and it returns only
the SQL query that answers the question — no explanations or markdown, just runnable SQL.
Results
Evaluated on a held-out test split (n=200) the model never saw during training.
Both the base and fine-tuned models were scored with identical string normalization
(lowercase, strip ;, canonicalize quotes), so the comparison is apples-to-apples.
| Model | Exact-match accuracy |
|---|---|
| Qwen2.5-3B-Instruct (base) | 41.5% |
| This model (fine-tuned) | 72.5% |
Only 0.96% of parameters (~30M of 3.1B) were trained via LoRA. Much of the gain comes from the base model learning to emit clean, executable SQL instead of wrapping answers in prose or markdown fences.
Note on the metric: exact-match undercounts semantically-correct queries that are written differently (column order, aliases, whitespace). A stronger evaluation would use AST comparison (
sqlglot) or execution accuracy on a benchmark with populated databases (Spider / BIRD);sql-create-contextships schemas only.
Usage
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "ashishsahu2008/qwen2.5-3b-text2sql"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16)
schema = "CREATE TABLE employees (name VARCHAR, salary INTEGER, department VARCHAR)"
question = "List the names of employees in Sales earning over 50000."
messages = [
{"role": "system", "content": "You are a SQL expert. Given a database schema "
"and a question, output only the SQL query that answers it."},
{"role": "user", "content": f"Schema:\n{schema}\n\nQuestion: {question}"},
]
inputs = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, return_tensors="pt", return_dict=True
).to(model.device)
out = model.generate(**inputs, max_new_tokens=128, do_sample=False)
print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
Prompt format
The model expects the schema and question in a single user turn, with this system prompt:
System: You are a SQL expert. Given a database schema and a question, output only the SQL query that answers it.
User: Schema:
<CREATE TABLE ...>
Question: <your question>
Training details
- Method: supervised fine-tuning (SFT) with LoRA on a 4-bit quantized base (QLoRA)
- LoRA config: rank 16, alpha 16, applied to attention + MLP projections
- Data: 3,000-row subset of
b-mc2/sql-create-context(2,700 train / 300 test) - Hyperparameters: 2 epochs, learning rate 2e-4, effective batch size 8
- Hardware: single Colab T4, ~25 minutes
- Frameworks: Unsloth + TRL
SFTTrainer
Limitations
- Trained on single-table
CREATE TABLEschemas; complex multi-join databases are out of distribution. - Assumes the schema is provided in the prompt — it does not know any tables you don't give it.
- SQL dialect follows the training data (broadly SQLite-compatible); it does not target a specific engine's extensions.
Fine-tuned with Unsloth and Hugging Face's TRL library.
- Downloads last month
- 173