Instructions to use Tehma/text2sql-qwen2.5-coder-1.5b-onnx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers.js
How to use Tehma/text2sql-qwen2.5-coder-1.5b-onnx with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('text-generation', 'Tehma/text2sql-qwen2.5-coder-1.5b-onnx');
Qwen2.5-Coder-1.5B text-to-SQL (q4f16 ONNX for Transformers.js)
QLoRA fine-tune of Qwen2.5-Coder-1.5B-Instruct on Spider, merged into the fp16 base and exported for in-browser inference with Transformers.js on WebGPU. Training code and reports: github.com/Tehma123/text2sql-qlora.
A larger 3B version (+3.7 points execution accuracy, twice the download, non-commercial license) is at Tehma/text2sql-qwen2.5-coder-3b-onnx.
Files
onnx/model_q4f16.onnx+onnx/model_q4f16.onnx_data(877 MB): 4-bit MatMul weights (block size 32), fp16 activations and KV cache; embedding and LM head share one 4-bit weight. Built with the onnxruntime-genai model builder, with GroupQueryAttention disabled so the graph uses MultiHeadAttention + RotaryEmbedding, which Transformers.js' KV cache handling supports.onnx/model_q4.onnx+onnx/model_q4.onnx_data(982 MB): the same 4-bit weights with fp32 activations and KV cache, for the WASM (CPU) backend when WebGPU orshader-f16is not available ({ dtype: "q4", device: "wasm" }). Same accuracy as q4f16 on the first 200 dev questions (64.0%), but much slower.- Config and tokenizer files; the chat template is embedded in
tokenizer_config.json.
Prompt format
Same as training. System message:
You are a SQL expert. Given a database schema and a question, write the SQLite query that answers the question.
Respond with the SQL query only -- no explanation, no markdown code fences.
User message:
### Schema:
CREATE TABLE "singer" (...);
### Question:
How many singers do we have?
### SQL:
Usage (Transformers.js 4.x, WebGPU)
import { AutoTokenizer, AutoModelForCausalLM } from "@huggingface/transformers";
const id = "Tehma/text2sql-qwen2.5-coder-1.5b-onnx";
const tokenizer = await AutoTokenizer.from_pretrained(id);
const model = await AutoModelForCausalLM.from_pretrained(id, { dtype: "q4f16", device: "webgpu" });
const inputs = tokenizer.apply_chat_template(messages, { add_generation_prompt: true, return_dict: true });
const out = await model.generate({ ...inputs, max_new_tokens: 256, do_sample: false });
Evaluation
Spider dev, zero-shot, execution accuracy:
| Model | Questions | Execution accuracy |
|---|---|---|
| 4-bit base + LoRA adapter (PyTorch) | all 1,034 | 71.4% |
| 4-bit base + LoRA adapter (PyTorch) | first 200 | 62.0% |
| fp16 merged (PyTorch) | first 200 | 60.5% |
| this q4f16 ONNX (onnxruntime CUDA) | first 200 | 64.0% |
| this q4 ONNX (onnxruntime CUDA) | first 200 | 64.0% |
The first 200 dev questions include several hard databases, so they score lower than the full split. The differences on those 200 are within noise; the full-split number is the reliable one. The 3B version scores 75.1% on the full split (exact McNemar p=0.006 for the difference).
In the browser (Edge 157, WebGPU, RTX 3060): ~62 tokens/s, ~0.3 s to the first token for a ~320-token prompt, 0.35-0.7 s per SQL query.
Limitations
Trained on Spider (English questions, SQLite dialect, multi-table academic schemas). Not evaluated on other SQL dialects or on real-world CSV/business schemas. Generated SQL should be reviewed before use.
License
Apache 2.0, same as Qwen2.5-Coder-1.5B-Instruct. A copy is in LICENSE; the list of modified files is
in NOTICE.
- Downloads last month
- 73
Model tree for Tehma/text2sql-qwen2.5-coder-1.5b-onnx
Base model
Qwen/Qwen2.5-1.5B