Text Generation
Transformers
Safetensors
PEFT
English
qwen2
text-to-sql
text2sql
sql
qlora
unsloth
qwen2.5
conversational
text-generation-inference
Instructions to use junmingg/qwen2.5-coder-7b-text2sql with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use junmingg/qwen2.5-coder-7b-text2sql with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="junmingg/qwen2.5-coder-7b-text2sql") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("junmingg/qwen2.5-coder-7b-text2sql") model = AutoModelForCausalLM.from_pretrained("junmingg/qwen2.5-coder-7b-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]:])) - PEFT
How to use junmingg/qwen2.5-coder-7b-text2sql with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use junmingg/qwen2.5-coder-7b-text2sql with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "junmingg/qwen2.5-coder-7b-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": "junmingg/qwen2.5-coder-7b-text2sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/junmingg/qwen2.5-coder-7b-text2sql
- SGLang
How to use junmingg/qwen2.5-coder-7b-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 "junmingg/qwen2.5-coder-7b-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": "junmingg/qwen2.5-coder-7b-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 "junmingg/qwen2.5-coder-7b-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": "junmingg/qwen2.5-coder-7b-text2sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use junmingg/qwen2.5-coder-7b-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 junmingg/qwen2.5-coder-7b-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 junmingg/qwen2.5-coder-7b-text2sql to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for junmingg/qwen2.5-coder-7b-text2sql to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="junmingg/qwen2.5-coder-7b-text2sql", max_seq_length=2048, ) - Docker Model Runner
How to use junmingg/qwen2.5-coder-7b-text2sql with Docker Model Runner:
docker model run hf.co/junmingg/qwen2.5-coder-7b-text2sql
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,21 +1,119 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
-
|
| 6 |
-
|
| 7 |
-
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
---
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
-
|
| 16 |
-
-
|
| 17 |
-
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: Qwen/Qwen2.5-Coder-7B-Instruct
|
| 4 |
+
datasets:
|
| 5 |
+
- b-mc2/sql-create-context
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
library_name: transformers
|
| 9 |
+
pipeline_tag: text-generation
|
| 10 |
+
tags:
|
| 11 |
+
- text-to-sql
|
| 12 |
+
- text2sql
|
| 13 |
+
- sql
|
| 14 |
+
- qlora
|
| 15 |
+
- peft
|
| 16 |
+
- unsloth
|
| 17 |
+
- qwen2.5
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# Qwen2.5-Coder-7B Text-to-SQL (QLoRA)
|
| 21 |
+
|
| 22 |
+
A QLoRA fine-tune of [`Qwen/Qwen2.5-Coder-7B-Instruct`](https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct)
|
| 23 |
+
that turns a **SQL schema + a natural-language question** into **a single SQL query**. Trained on a single
|
| 24 |
+
RTX 3090 with [Unsloth](https://github.com/unslothai/unsloth) + TRL, completion-only loss.
|
| 25 |
+
|
| 26 |
+
> Trained and evaluated by `junmingg`. Code + reproducible eval harness:
|
| 27 |
+
> https://github.com/junmingg/Unsloth-Qwen2.5-Coder-7b-Text-to-SQL-SFT
|
| 28 |
+
|
| 29 |
+
## Results (held-out 500 examples)
|
| 30 |
+
|
| 31 |
+
| Model | Exact match | Semantic equiv. | SQL validity |
|
| 32 |
+
|---|---|---|---|
|
| 33 |
+
| Base `Qwen2.5-Coder-7B-Instruct` (zero-shot) | 3.8% | 67.0% | 100.0% |
|
| 34 |
+
| **+ QLoRA (this model)** | **78.8%** | **86.2%** | **99.2%** |
|
| 35 |
+
|
| 36 |
+

|
| 37 |
+
|
| 38 |
+
- **Exact match** = canonicalized string match (via `sqlglot`); a strict *lower bound* — different-but-correct
|
| 39 |
+
SQL fails it.
|
| 40 |
+
- **Semantic equivalence** = an independent LLM judge (GLM-5-Turbo) decides whether the predicted SQL is
|
| 41 |
+
equivalent to the gold for the question. This is the headline correctness metric.
|
| 42 |
+
- **SQL validity** = fraction of predictions that parse under `sqlglot`.
|
| 43 |
+
|
| 44 |
+
Fine-tuning lifted exact-match by **+75.0 points** and semantic-equivalence by **+19.2 points** on prompts the
|
| 45 |
+
model never saw during training (0/500 test prompts appear in the training data). The large exact-match jump
|
| 46 |
+
is the model learning the dataset's SQL conventions (quoting, value formatting); the semantic jump is genuine
|
| 47 |
+
correctness beyond formatting.
|
| 48 |
+
|
| 49 |
+
### Label-noise ablation
|
| 50 |
+
|
| 51 |
+
A variant trained with malformed gold answers filtered out of the training set
|
| 52 |
+
(`junmingg/qwen2.5-coder-7b-text2sql-filtered`) reaches the same accuracy with slightly higher validity
|
| 53 |
+
(100% on valid-reference test rows). Cleaning 0.32% of train labels moved validity, not accuracy — details in
|
| 54 |
+
the [repo README](https://github.com/junmingg/Unsloth-Qwen2.5-Coder-7b-Text-to-SQL-SFT).
|
| 55 |
+
|
| 56 |
+
## Usage
|
| 57 |
+
|
| 58 |
+
The model was trained with a specific system prompt and ChatML format — **use the same formatting** for best
|
| 59 |
+
results.
|
| 60 |
+
|
| 61 |
+
```python
|
| 62 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 63 |
+
import torch
|
| 64 |
+
|
| 65 |
+
REPO = "junmingg/qwen2.5-coder-7b-text2sql"
|
| 66 |
+
model = AutoModelForCausalLM.from_pretrained(REPO, torch_dtype=torch.bfloat16, device_map="auto")
|
| 67 |
+
tok = AutoTokenizer.from_pretrained(REPO)
|
| 68 |
+
|
| 69 |
+
SYSTEM = ("You are a precise text-to-SQL engine. Given a SQL schema and a natural-language "
|
| 70 |
+
"question, respond with a single valid SQL query and nothing else.")
|
| 71 |
+
|
| 72 |
+
schema = "CREATE TABLE head (age INTEGER, name TEXT)"
|
| 73 |
+
question = "How many heads of the departments are older than 56?"
|
| 74 |
+
|
| 75 |
+
messages = [
|
| 76 |
+
{"role": "system", "content": SYSTEM},
|
| 77 |
+
{"role": "user", "content": f"Schema:\n{schema}\n\nQuestion: {question}"},
|
| 78 |
+
]
|
| 79 |
+
inputs = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
| 80 |
+
out = model.generate(inputs, max_new_tokens=256, do_sample=False)
|
| 81 |
+
print(tok.decode(out[0][inputs.shape[1]:], skip_special_tokens=True))
|
| 82 |
+
# -> SELECT COUNT(*) FROM head WHERE age > 56
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
LoRA adapters only (smaller): `junmingg/qwen2.5-coder-7b-text2sql-lora`.
|
| 86 |
+
GGUF quants (`q4_k_m`, `q8_0`) for llama.cpp / Ollama: `junmingg/qwen2.5-coder-7b-text2sql-GGUF`.
|
| 87 |
+
|
| 88 |
+
## Training
|
| 89 |
+
|
| 90 |
+
| | |
|
| 91 |
+
|---|---|
|
| 92 |
+
| Base | `Qwen/Qwen2.5-Coder-7B-Instruct` (4-bit QLoRA) |
|
| 93 |
+
| Data | [`b-mc2/sql-create-context`](https://huggingface.co/datasets/b-mc2/sql-create-context), 25k train / 500 held-out test (seed 42) |
|
| 94 |
+
| LoRA | r=16, α=16, dropout=0, all linear layers |
|
| 95 |
+
| Schedule | 1 epoch (~1,557 steps), effective batch 16, lr 2e-4 cosine, warmup 0.03 |
|
| 96 |
+
| Precision / optim | bf16, `adamw_8bit`, `max_seq_length=2048` |
|
| 97 |
+
| Loss | completion-only (prompt masked; loss on the SQL answer only) |
|
| 98 |
+
| Hardware / time | 1× RTX 3090, ~59 min |
|
| 99 |
+
|
| 100 |
+
## Evaluation methodology
|
| 101 |
+
|
| 102 |
+
Both base and fine-tuned models are evaluated with **identical** prompting and greedy decoding on the **same**
|
| 103 |
+
held-out 500-example test set (disjoint from train; verified 0 prompt overlap). Semantic equivalence is scored
|
| 104 |
+
by an independent LLM judge (GLM-5-Turbo). Reporting both exact-match and semantic-equivalence is deliberate:
|
| 105 |
+
exact-match is a lower bound, semantic-equivalence is the fairer correctness signal. The full harness is in the
|
| 106 |
+
linked repo (`python -m src.eval`, `python -m src.judge`).
|
| 107 |
+
|
| 108 |
+
## Limitations
|
| 109 |
+
|
| 110 |
+
- Trained on synthetic, largely single-table schemas (`sql-create-context`, derived from WikiSQL + Spider);
|
| 111 |
+
not evaluated for SQL-injection safety or complex multi-join queries.
|
| 112 |
+
- The dataset contains a small amount of label noise (~0.3–0.6% of gold answers are themselves unparseable —
|
| 113 |
+
WikiSQL artifacts); the model's rare "invalid" outputs are predominantly faithful reproductions of those
|
| 114 |
+
malformed references rather than novel errors.
|
| 115 |
+
- Outputs should be validated/parameterized before execution against a real database.
|
| 116 |
+
|
| 117 |
+
## License & attribution
|
| 118 |
+
|
| 119 |
+
Apache-2.0 (inherited from the base model). Training data: `b-mc2/sql-create-context` (CC-BY-4.0).
|