Qwen2.5-Coder-3B text-to-SQL (q4f16 ONNX for Transformers.js)

Built with Qwen. Non-commercial use only (Qwen Research License, see below).

QLoRA fine-tune of Qwen2.5-Coder-3B-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 smaller 1.5B version (-3.7 points execution accuracy, half the download, faster, Apache 2.0) is at Tehma/text2sql-qwen2.5-coder-1.5b-onnx.

Files

  • onnx/model_q4f16.onnx + onnx/model_q4f16.onnx_data (1.74 GB): 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.
  • 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-3b-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 75.1%
4-bit base + LoRA adapter (PyTorch) first 200 67.0%
fp16 merged (PyTorch) first 200 66.0%
this q4f16 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 q4f16 vs. adapter difference on those 200 is not significant (exact McNemar p=0.29).

In the browser (Edge 157, WebGPU, RTX 3060): ~45 tokens/s, ~0.5 s to the first token for a ~320-token prompt, 0.5-1.0 s per SQL query. These are local measurements; download time is not included.

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

Derived from Qwen2.5-Coder-3B-Instruct and subject to the Qwen Research License (non-commercial use). A copy is in LICENSE; the attribution notice and the list of modified files are in NOTICE.

Downloads last month
35
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for Tehma/text2sql-qwen2.5-coder-3b-onnx

Base model

Qwen/Qwen2.5-3B
Quantized
(152)
this model