Text Generation
Transformers
Safetensors
English
qwen2
text-to-sql
sql
lora
qlora
unsloth
trl
conversational
text-generation-inference
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
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,21 +1,113 @@
|
|
| 1 |
---
|
| 2 |
-
base_model: unsloth/
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
- transformers
|
| 6 |
-
- unsloth
|
| 7 |
-
- qwen2
|
| 8 |
license: apache-2.0
|
| 9 |
language:
|
| 10 |
- en
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
- **Developed by:** ashishsahu2008
|
|
|
|
|
|
|
| 16 |
- **License:** apache-2.0
|
| 17 |
-
- **
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
| 1 |
---
|
| 2 |
+
base_model: unsloth/Qwen2.5-3B-Instruct
|
| 3 |
+
library_name: transformers
|
| 4 |
+
pipeline_tag: text-generation
|
|
|
|
|
|
|
|
|
|
| 5 |
license: apache-2.0
|
| 6 |
language:
|
| 7 |
- en
|
| 8 |
+
tags:
|
| 9 |
+
- text-to-sql
|
| 10 |
+
- sql
|
| 11 |
+
- qwen2
|
| 12 |
+
- lora
|
| 13 |
+
- qlora
|
| 14 |
+
- unsloth
|
| 15 |
+
- trl
|
| 16 |
+
datasets:
|
| 17 |
+
- b-mc2/sql-create-context
|
| 18 |
---
|
| 19 |
|
| 20 |
+
# Qwen2.5-3B Text-to-SQL
|
| 21 |
+
|
| 22 |
+
A fine-tuned version of **Qwen2.5-3B-Instruct** that converts natural-language
|
| 23 |
+
questions into SQL queries, given a database schema. Trained with LoRA/QLoRA on a
|
| 24 |
+
single free GPU.
|
| 25 |
|
| 26 |
- **Developed by:** ashishsahu2008
|
| 27 |
+
- **Base model:** [unsloth/Qwen2.5-3B-Instruct](https://huggingface.co/unsloth/Qwen2.5-3B-Instruct)
|
| 28 |
+
- **Fine-tuned on:** [b-mc2/sql-create-context](https://huggingface.co/datasets/b-mc2/sql-create-context)
|
| 29 |
- **License:** apache-2.0
|
| 30 |
+
- **Live demo:** https://huggingface.co/spaces/ashishsahu2008/text2sql-demo
|
| 31 |
+
- **Code / write-up:** https://github.com/ashishsahu2008/fine-tuning
|
| 32 |
+
|
| 33 |
+
## What it does
|
| 34 |
+
|
| 35 |
+
Give it a `CREATE TABLE` schema and a plain-English question, and it returns only
|
| 36 |
+
the SQL query that answers the question — no explanations or markdown, just runnable SQL.
|
| 37 |
+
|
| 38 |
+
## Results
|
| 39 |
+
|
| 40 |
+
Evaluated on a held-out test split (n=200) the model never saw during training.
|
| 41 |
+
Both the base and fine-tuned models were scored with identical string normalization
|
| 42 |
+
(lowercase, strip `;`, canonicalize quotes), so the comparison is apples-to-apples.
|
| 43 |
+
|
| 44 |
+
| Model | Exact-match accuracy |
|
| 45 |
+
|--------------------------------|:--------------------:|
|
| 46 |
+
| Qwen2.5-3B-Instruct (base) | 41.5% |
|
| 47 |
+
| **This model (fine-tuned)** | **72.5%** |
|
| 48 |
+
|
| 49 |
+
Only 0.96% of parameters (~30M of 3.1B) were trained via LoRA. Much of the gain
|
| 50 |
+
comes from the base model learning to emit clean, executable SQL instead of wrapping
|
| 51 |
+
answers in prose or markdown fences.
|
| 52 |
+
|
| 53 |
+
> **Note on the metric:** exact-match undercounts semantically-correct queries that
|
| 54 |
+
> are written differently (column order, aliases, whitespace). A stronger evaluation
|
| 55 |
+
> would use AST comparison (`sqlglot`) or execution accuracy on a benchmark with
|
| 56 |
+
> populated databases (Spider / BIRD); `sql-create-context` ships schemas only.
|
| 57 |
+
|
| 58 |
+
## Usage
|
| 59 |
+
|
| 60 |
+
```python
|
| 61 |
+
import torch
|
| 62 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 63 |
+
|
| 64 |
+
model_id = "ashishsahu2008/qwen2.5-3b-text2sql"
|
| 65 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 66 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16)
|
| 67 |
+
|
| 68 |
+
schema = "CREATE TABLE employees (name VARCHAR, salary INTEGER, department VARCHAR)"
|
| 69 |
+
question = "List the names of employees in Sales earning over 50000."
|
| 70 |
+
|
| 71 |
+
messages = [
|
| 72 |
+
{"role": "system", "content": "You are a SQL expert. Given a database schema "
|
| 73 |
+
"and a question, output only the SQL query that answers it."},
|
| 74 |
+
{"role": "user", "content": f"Schema:\n{schema}\n\nQuestion: {question}"},
|
| 75 |
+
]
|
| 76 |
+
inputs = tokenizer.apply_chat_template(
|
| 77 |
+
messages, add_generation_prompt=True, return_tensors="pt", return_dict=True
|
| 78 |
+
).to(model.device)
|
| 79 |
+
out = model.generate(**inputs, max_new_tokens=128, do_sample=False)
|
| 80 |
+
print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
## Prompt format
|
| 84 |
+
|
| 85 |
+
The model expects the schema and question in a single user turn, with this system prompt:
|
| 86 |
+
|
| 87 |
+
```
|
| 88 |
+
System: You are a SQL expert. Given a database schema and a question, output only the SQL query that answers it.
|
| 89 |
+
User: Schema:
|
| 90 |
+
<CREATE TABLE ...>
|
| 91 |
+
|
| 92 |
+
Question: <your question>
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
## Training details
|
| 96 |
+
|
| 97 |
+
- **Method:** supervised fine-tuning (SFT) with LoRA on a 4-bit quantized base (QLoRA)
|
| 98 |
+
- **LoRA config:** rank 16, alpha 16, applied to attention + MLP projections
|
| 99 |
+
- **Data:** 3,000-row subset of `b-mc2/sql-create-context` (2,700 train / 300 test)
|
| 100 |
+
- **Hyperparameters:** 2 epochs, learning rate 2e-4, effective batch size 8
|
| 101 |
+
- **Hardware:** single Colab T4, ~25 minutes
|
| 102 |
+
- **Frameworks:** [Unsloth](https://github.com/unslothai/unsloth) + TRL `SFTTrainer`
|
| 103 |
+
|
| 104 |
+
## Limitations
|
| 105 |
|
| 106 |
+
- Trained on **single-table** `CREATE TABLE` schemas; complex multi-join databases
|
| 107 |
+
are out of distribution.
|
| 108 |
+
- Assumes the schema is provided in the prompt — it does not know any tables you
|
| 109 |
+
don't give it.
|
| 110 |
+
- SQL dialect follows the training data (broadly SQLite-compatible); it does not
|
| 111 |
+
target a specific engine's extensions.
|
| 112 |
|
| 113 |
+
Fine-tuned with [Unsloth](https://github.com/unslothai/unsloth) and Hugging Face's TRL library.
|