Instructions to use 2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use 2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA") model = AutoModelForCausalLM.from_pretrained("2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA", device_map="auto") 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use 2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA
- SGLang
How to use 2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA 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 "2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA" \ --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": "2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA", "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 "2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA" \ --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": "2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use 2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA with Docker Model Runner:
docker model run hf.co/2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA
Qwen2.5-Coder-1.5B Text-to-SQL (QLoRA fine-tune)
A QLoRA fine-tune of Qwen2.5-Coder-1.5B-Instruct for turning a question plus a table schema into one SQLite query. The weights here are the LoRA adapter merged into the fp16 base, so it loads like any normal model. The adapter alone is in the adapter/ folder.
Results (execution accuracy)
A query counts as correct when it runs on the real database and returns the same rows as the reference query (row order only checked when the reference uses ORDER BY).
| Benchmark | Questions | Base | This model | Change |
|---|---|---|---|---|
| Gretel synthetic_text_to_sql, held-out test subset | 300 | 61.0% | 71.3% | +10.3 pts (paired sign test p = 0.0001) |
| Spider dev (databases never seen in training) | 1,034 | 46.1% | 55.2% | +9.1 pts (181 fixed, 87 broken, p < 0.0001) |
Same prompt, greedy decoding for both models. Standard error on Spider is about 1.5 points per model. The fine-tune also breaks some questions the base got right (87 on Spider), so it is better on average, not better on every question.
These use my own execution-comparison script, not the official Spider evaluator, so do not compare the numbers directly with leaderboard figures.
Usage
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
repo = "2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo, torch_dtype=torch.float16, device_map="auto")
system = "You are an expert SQL assistant. Given a database schema and a question, write one SQLite query that answers the question. Return only the SQL query in a ```sql code block."
schema = "CREATE TABLE employees (id INTEGER, name TEXT, dept TEXT, salary REAL);"
question = "What is the average salary in each department?"
user = f"{schema} {question}"
msgs = [{"role": "system", "content": system}, {"role": "user", "content": user}]
ids = tok.apply_chat_template(msgs, add_generation_prompt=True, return_tensors="pt").to(model.device)
out = model.generate(ids, max_new_tokens=256, do_sample=False)
print(tok.decode(out[0][ids.shape[1]:], skip_special_tokens=True))
Prompt format used in training and evaluation (keep it for best results):
SYSTEM: You are an expert SQL assistant. Given a database schema and a question, write one SQLite query that answers the question. Return only the SQL query in a ```sql code block.
USER: Database schema:\n<SCHEMA>\n\nQuestion: <QUESTION>
The model answers with a single query inside a ```sql block.
Training
- Data: usable examples from gretelai/synthetic_text_to_sql (Apache-2.0); 12,000 training examples whose reference query runs on a database built from the example's schema.
- Method: QLoRA (4-bit NF4), LoRA r=16, alpha=32, dropout 0.05 on all attention and MLP projections, learning rate 2e-4, effective batch size 16, loss on the answer tokens only, 2x T4 GPUs on Kaggle.
- Checkpoints were backed up to the Hub during training.
Limitations
- Targets SQLite syntax. Other dialects (Postgres, MySQL, BigQuery) may need edits.
- Trained mostly on synthetic data; real, messy schemas are harder (see the lower Spider score).
- A 1.5B model makes mistakes on joins, nested queries and unusual schemas. Always review generated SQL.
- Never run generated SQL on a database you cannot afford to change; use a read-only connection.
License
Apache-2.0, same as the base model. The training data is Apache-2.0.
- Downloads last month
- 63
Model tree for 2003Rohansinha/Qwen2.5-Coder-1.5B-Text2SQL-LoRA
Base model
Qwen/Qwen2.5-1.5B