Text Generation
Transformers
Safetensors
English
qwen2
text-to-sql
sql
spider
sqlite
lora
conversational
Eval Results (legacy)
text-generation-inference
Instructions to use HideIron/Qwen2.5-Coder-1.5B-Spider-SQL with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HideIron/Qwen2.5-Coder-1.5B-Spider-SQL with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="HideIron/Qwen2.5-Coder-1.5B-Spider-SQL") 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("HideIron/Qwen2.5-Coder-1.5B-Spider-SQL") model = AutoModelForCausalLM.from_pretrained("HideIron/Qwen2.5-Coder-1.5B-Spider-SQL", 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 HideIron/Qwen2.5-Coder-1.5B-Spider-SQL with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HideIron/Qwen2.5-Coder-1.5B-Spider-SQL" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "HideIron/Qwen2.5-Coder-1.5B-Spider-SQL", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/HideIron/Qwen2.5-Coder-1.5B-Spider-SQL
- SGLang
How to use HideIron/Qwen2.5-Coder-1.5B-Spider-SQL 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 "HideIron/Qwen2.5-Coder-1.5B-Spider-SQL" \ --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": "HideIron/Qwen2.5-Coder-1.5B-Spider-SQL", "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 "HideIron/Qwen2.5-Coder-1.5B-Spider-SQL" \ --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": "HideIron/Qwen2.5-Coder-1.5B-Spider-SQL", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use HideIron/Qwen2.5-Coder-1.5B-Spider-SQL with Docker Model Runner:
docker model run hf.co/HideIron/Qwen2.5-Coder-1.5B-Spider-SQL
File size: 4,993 Bytes
2b3c3d2 | 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | ---
license: apache-2.0
base_model: Qwen/Qwen2.5-Coder-1.5B-Instruct
datasets:
- xlangai/spider
language:
- en
library_name: transformers
pipeline_tag: text-generation
tags:
- text-to-sql
- sql
- spider
- sqlite
- qwen2
- lora
model-index:
- name: Qwen2.5-Coder-1.5B-Spider-SQL
results:
- task:
type: text-to-sql
name: Text-to-SQL
dataset:
type: xlangai/spider
name: Spider (dev)
split: validation
metrics:
- type: execution_accuracy
value: 69.8
name: Execution accuracy
- type: exact_match
value: 62.2
name: Exact-set match
---
# Qwen2.5-Coder-1.5B-Spider-SQL
A text-to-SQL model: give it a SQLite schema (`CREATE TABLE` statements) and a question in English, and it replies with one SQL query.
It is [Qwen/Qwen2.5-Coder-1.5B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-1.5B-Instruct) fine-tuned with LoRA on the [Spider](https://yale-lily.github.io/spider) training set, with the adapter merged into the weights. It loads like any `transformers` model, no PEFT needed.
## Results (Spider dev, 1034 questions)
Scored with the official Spider evaluator ([test-suite-sql-eval](https://github.com/taoyds/test-suite-sql-eval), `--etype all`), greedy decoding, same prompt for both models.
**Execution accuracy** (predicted and gold query return the same rows):
| | easy (248) | medium (446) | hard (174) | extra (166) | **all** |
|---|---|---|---|---|---|
| Qwen2.5-Coder-1.5B-Instruct (base) | 81.5 | 61.0 | 42.5 | 34.9 | **58.6** |
| **This model** | 87.5 | 72.9 | 56.9 | 48.8 | **69.8** |
**Exact-set match** (SQL structure matches gold, values ignored):
| | easy | medium | hard | extra | **all** |
|---|---|---|---|---|---|
| Base | 76.6 | 33.9 | 25.3 | 12.7 | 39.3 |
| **This model** | 83.1 | 63.5 | 46.0 | 44.6 | **62.2** |
Execution was checked against the original Spider dev databases, not the larger test-suite databases, so the test-suite number may be slightly lower. The dev set was also used to pick training settings.
## How to use
The model was trained on one exact prompt format. Use the same system prompt and the `Schema:` / `Question:` layout below, or results get worse.
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "HideIron/Qwen2.5-Coder-1.5B-Spider-SQL"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo, dtype="bfloat16", device_map="auto")
SYSTEM = ("You are a text-to-SQL assistant. Given a SQLite database schema and a "
"question, reply with a single SQL query and nothing else.")
schema = """CREATE TABLE singer (singer_id INT PRIMARY KEY, name TEXT, country TEXT, age INT);
CREATE TABLE concert (concert_id INT PRIMARY KEY, concert_name TEXT, year TEXT);
CREATE TABLE singer_in_concert (concert_id INT, singer_id INT,
FOREIGN KEY (concert_id) REFERENCES concert(concert_id),
FOREIGN KEY (singer_id) REFERENCES singer(singer_id));"""
question = "How many singers from France performed in a concert in 2014?"
messages = [
{"role": "system", "content": SYSTEM},
{"role": "user", "content": f"Schema:\n{schema}\n\nQuestion: {question}"},
]
inputs = tok.apply_chat_template(messages, add_generation_prompt=True,
return_tensors="pt", return_dict=True).to(model.device)
out = model.generate(**inputs, max_new_tokens=256, do_sample=False)
print(tok.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
```
Tips:
- Put the real `CREATE TABLE` statements in the schema, with primary and foreign keys. The model uses the keys to work out joins.
- Use greedy decoding (`do_sample=False`), as in the evaluation.
## Training
| | |
|---|---|
| Base model | Qwen/Qwen2.5-Coder-1.5B-Instruct |
| Data | Spider `train_spider` (7000 question/SQL pairs, 140 databases) |
| Method | LoRA, r=16, alpha=32, dropout 0.05, on q/k/v/o projections (0.28 % of parameters trained), then merged |
| Loss | Cross-entropy on the SQL answer tokens only (prompt tokens masked) |
| Schedule | 2 epochs, 1750 steps, effective batch 8, LR 1e-4, cosine with 3 % warmup, bf16 |
| Max length | 2048 tokens (no training example was truncated) |
| Hardware | 1x NVIDIA A10 (24 GB), about 1 hour |
## Limitations
- **SQLite only.** Trained on SQLite schemas and gold queries; other dialects (Postgres, MySQL, T-SQL) may get SQLite-flavoured SQL.
- **Spider-style questions.** Spider covers 200 small databases with clean names. Large real-world schemas, ambiguous column names, or questions that need outside knowledge are harder; the model has not been evaluated on BIRD or Spider 2.0.
- **One query per answer**, no explanation, no multi-turn clarification.
- **It does not run or check its SQL.** Treat its output as a draft. Never run generated SQL against a production database with write permissions.
## License
The model weights are released under Apache 2.0, the license of the base model. The training data, Spider, is licensed CC BY-SA 4.0.
|