Instructions to use distil-labs/distil-qwen3-4b-text2sql-gguf-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use distil-labs/distil-qwen3-4b-text2sql-gguf-4bit with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf distil-labs/distil-qwen3-4b-text2sql-gguf-4bit # Run inference directly in the terminal: llama cli -hf distil-labs/distil-qwen3-4b-text2sql-gguf-4bit
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf distil-labs/distil-qwen3-4b-text2sql-gguf-4bit # Run inference directly in the terminal: llama cli -hf distil-labs/distil-qwen3-4b-text2sql-gguf-4bit
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf distil-labs/distil-qwen3-4b-text2sql-gguf-4bit # Run inference directly in the terminal: ./llama-cli -hf distil-labs/distil-qwen3-4b-text2sql-gguf-4bit
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf distil-labs/distil-qwen3-4b-text2sql-gguf-4bit # Run inference directly in the terminal: ./build/bin/llama-cli -hf distil-labs/distil-qwen3-4b-text2sql-gguf-4bit
Use Docker
docker model run hf.co/distil-labs/distil-qwen3-4b-text2sql-gguf-4bit
- LM Studio
- Jan
- vLLM
How to use distil-labs/distil-qwen3-4b-text2sql-gguf-4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "distil-labs/distil-qwen3-4b-text2sql-gguf-4bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "distil-labs/distil-qwen3-4b-text2sql-gguf-4bit", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/distil-labs/distil-qwen3-4b-text2sql-gguf-4bit
- Ollama
How to use distil-labs/distil-qwen3-4b-text2sql-gguf-4bit with Ollama:
ollama run hf.co/distil-labs/distil-qwen3-4b-text2sql-gguf-4bit
- Unsloth Studio
How to use distil-labs/distil-qwen3-4b-text2sql-gguf-4bit 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 distil-labs/distil-qwen3-4b-text2sql-gguf-4bit 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 distil-labs/distil-qwen3-4b-text2sql-gguf-4bit to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for distil-labs/distil-qwen3-4b-text2sql-gguf-4bit to start chatting
- Docker Model Runner
How to use distil-labs/distil-qwen3-4b-text2sql-gguf-4bit with Docker Model Runner:
docker model run hf.co/distil-labs/distil-qwen3-4b-text2sql-gguf-4bit
- Lemonade
How to use distil-labs/distil-qwen3-4b-text2sql-gguf-4bit with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull distil-labs/distil-qwen3-4b-text2sql-gguf-4bit
Run and chat with the model
lemonade run user.distil-qwen3-4b-text2sql-gguf-4bit-{{QUANT_TAG}}List all available models
lemonade list
- Atomic Chat
Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- Modelfile +51 -0
- README.md +140 -0
- model.gguf +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
model.gguf filter=lfs diff=lfs merge=lfs -text
|
Modelfile
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
FROM ./model.gguf
|
| 3 |
+
|
| 4 |
+
TEMPLATE """{{- $lastUserIdx := -1 -}}
|
| 5 |
+
{{- range $idx, $msg := .Messages -}}
|
| 6 |
+
{{- if eq $msg.Role "user" }}{{ $lastUserIdx = $idx }}{{ end -}}
|
| 7 |
+
{{- end }}
|
| 8 |
+
{{- if or .System .Tools }}<|im_start|>system
|
| 9 |
+
{{ if .System }}{{ .System }}
|
| 10 |
+
|
| 11 |
+
{{ end }}
|
| 12 |
+
{{- if .Tools }}# Tools
|
| 13 |
+
|
| 14 |
+
You may call one or more functions to assist with the user query.
|
| 15 |
+
|
| 16 |
+
You are provided with function signatures within <tools></tools> XML tags:
|
| 17 |
+
<tools>
|
| 18 |
+
{{- range .Tools }}
|
| 19 |
+
{"type": "function", "function": {{ .Function }}}
|
| 20 |
+
{{- end }}
|
| 21 |
+
</tools>
|
| 22 |
+
|
| 23 |
+
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
|
| 24 |
+
<tool_call>
|
| 25 |
+
{"name": <function-name>, "arguments": <args-json-object>}
|
| 26 |
+
</tool_call>
|
| 27 |
+
{{- end -}}
|
| 28 |
+
<|im_end|>
|
| 29 |
+
{{ end }}
|
| 30 |
+
{{- range $i, $_ := .Messages }}
|
| 31 |
+
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
|
| 32 |
+
{{- if eq .Role "user" }}<|im_start|>user
|
| 33 |
+
{{ .Content }}<|im_end|>
|
| 34 |
+
{{ else if eq .Role "assistant" }}<|im_start|>assistant
|
| 35 |
+
{{ if .Content }}{{ .Content }}{{ end }}
|
| 36 |
+
{{- if .ToolCalls }}
|
| 37 |
+
{{- range .ToolCalls }}
|
| 38 |
+
<tool_call>
|
| 39 |
+
{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
|
| 40 |
+
</tool_call>
|
| 41 |
+
{{- end }}
|
| 42 |
+
{{- end }}{{ if not $last }}<|im_end|>
|
| 43 |
+
{{ end }}
|
| 44 |
+
{{- else if eq .Role "tool" }}<|im_start|>user
|
| 45 |
+
<tool_response>
|
| 46 |
+
{{ .Content }}
|
| 47 |
+
</tool_response><|im_end|>
|
| 48 |
+
{{ end }}
|
| 49 |
+
{{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
|
| 50 |
+
{{ end }}
|
| 51 |
+
{{- end }}"""
|
README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: distil-labs/distil-qwen3-4b-text2sql
|
| 4 |
+
tags:
|
| 5 |
+
- text2sql
|
| 6 |
+
- sql
|
| 7 |
+
- nlp
|
| 8 |
+
- gguf
|
| 9 |
+
- ollama
|
| 10 |
+
- qwen3
|
| 11 |
+
- quantized
|
| 12 |
+
language:
|
| 13 |
+
- en
|
| 14 |
+
pipeline_tag: text-generation
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Distil-Qwen3-4B-Text2SQL-GGUF-4bit
|
| 18 |
+
|
| 19 |
+
4-bit quantized GGUF version of [distil-qwen3-4b-text2sql](https://huggingface.co/distil-labs/distil-qwen3-4b-text2sql) for efficient local inference. **Only 2.5GB** - runs on most laptops and edge devices.
|
| 20 |
+
|
| 21 |
+
## Results
|
| 22 |
+
|
| 23 |
+
| Metric | DeepSeek-V3 (Teacher) | Qwen3-4B (Base) | **This Model** |
|
| 24 |
+
|--------|:---------------------:|:---------------:|:--------------:|
|
| 25 |
+
| LLM-as-a-Judge | 80% | 62% | **80%** |
|
| 26 |
+
| Exact Match | 48% | 16% | **60%** |
|
| 27 |
+
| ROUGE | 87.6% | 84.2% | **89.5%** |
|
| 28 |
+
|
| 29 |
+
## Quick Start with Ollama
|
| 30 |
+
|
| 31 |
+
### 1. Download the model
|
| 32 |
+
|
| 33 |
+
```bash
|
| 34 |
+
git lfs install
|
| 35 |
+
git clone https://huggingface.co/distil-labs/distil-qwen3-4b-text2sql-gguf-4bit
|
| 36 |
+
cd distil-qwen3-4b-text2sql-gguf-4bit
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
### 2. Create and run the model
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
# Create the Ollama model (Modelfile is included)
|
| 43 |
+
ollama create distil-qwen3-4b-text2sql -f Modelfile
|
| 44 |
+
|
| 45 |
+
# Run the model
|
| 46 |
+
ollama run distil-qwen3-4b-text2sql
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
### 3. Test it
|
| 50 |
+
|
| 51 |
+
```
|
| 52 |
+
>>> Schema:
|
| 53 |
+
... CREATE TABLE employees (id INTEGER PRIMARY KEY, name TEXT, department TEXT, salary INTEGER);
|
| 54 |
+
...
|
| 55 |
+
... Question: How many employees earn more than 50000?
|
| 56 |
+
|
| 57 |
+
SELECT COUNT(*) FROM employees WHERE salary > 50000;
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
## Usage with Python
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
from openai import OpenAI
|
| 64 |
+
|
| 65 |
+
client = OpenAI(base_url="http://127.0.0.1:11434/v1", api_key="EMPTY")
|
| 66 |
+
|
| 67 |
+
schema = """CREATE TABLE employees (
|
| 68 |
+
id INTEGER PRIMARY KEY,
|
| 69 |
+
name TEXT NOT NULL,
|
| 70 |
+
department TEXT,
|
| 71 |
+
salary INTEGER
|
| 72 |
+
);"""
|
| 73 |
+
|
| 74 |
+
question = "How many employees earn more than 50000?"
|
| 75 |
+
|
| 76 |
+
response = client.chat.completions.create(
|
| 77 |
+
model="distil-qwen3-4b-text2sql",
|
| 78 |
+
messages=[
|
| 79 |
+
{
|
| 80 |
+
"role": "system",
|
| 81 |
+
"content": """You are given a database schema and a natural language question. Generate the SQL query that answers the question.
|
| 82 |
+
|
| 83 |
+
Rules:
|
| 84 |
+
- Use only tables and columns from the provided schema
|
| 85 |
+
- Use uppercase SQL keywords (SELECT, FROM, WHERE, etc.)
|
| 86 |
+
- Use SQLite-compatible syntax
|
| 87 |
+
- Output only the SQL query, no explanations"""
|
| 88 |
+
},
|
| 89 |
+
{
|
| 90 |
+
"role": "user",
|
| 91 |
+
"content": f"Schema:\n{schema}\n\nQuestion: {question}"
|
| 92 |
+
}
|
| 93 |
+
],
|
| 94 |
+
temperature=0
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
print(response.choices[0].message.content)
|
| 98 |
+
# Output: SELECT COUNT(*) FROM employees WHERE salary > 50000;
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
## Model Details
|
| 102 |
+
|
| 103 |
+
| Property | Value |
|
| 104 |
+
|----------|-------|
|
| 105 |
+
| Format | GGUF (Q4_K_M) |
|
| 106 |
+
| Size | **~2.5 GB** |
|
| 107 |
+
| Base Model | [distil-labs/distil-qwen3-4b-text2sql](https://huggingface.co/distil-labs/distil-qwen3-4b-text2sql) |
|
| 108 |
+
| Parameters | 4 billion |
|
| 109 |
+
| Quantization | 4-bit |
|
| 110 |
+
|
| 111 |
+
## Why Use This Version?
|
| 112 |
+
|
| 113 |
+
- **Small size**: 2.5GB vs 15GB (full GGUF) or 8GB (safetensors)
|
| 114 |
+
- **Fast inference**: Optimized for CPU and consumer GPUs
|
| 115 |
+
- **Same accuracy**: Quantization has minimal impact on Text2SQL quality
|
| 116 |
+
- **Easy setup**: Works with Ollama out of the box
|
| 117 |
+
|
| 118 |
+
## Related Models
|
| 119 |
+
|
| 120 |
+
| Model | Format | Size | Use Case |
|
| 121 |
+
|-------|--------|------|----------|
|
| 122 |
+
| [distil-qwen3-4b-text2sql](https://huggingface.co/distil-labs/distil-qwen3-4b-text2sql) | Safetensors | ~8 GB | Transformers, vLLM |
|
| 123 |
+
| [distil-qwen3-4b-text2sql-gguf](https://huggingface.co/distil-labs/distil-qwen3-4b-text2sql-gguf) | GGUF (F16) | ~15 GB | Full precision GGUF |
|
| 124 |
+
| **This model** | GGUF (Q4_K_M) | **~2.5 GB** | Recommended for local use |
|
| 125 |
+
|
| 126 |
+
## Supported SQL Features
|
| 127 |
+
|
| 128 |
+
- **Simple**: SELECT, WHERE, COUNT, SUM, AVG, MAX, MIN
|
| 129 |
+
- **Medium**: JOIN, GROUP BY, HAVING, ORDER BY, LIMIT
|
| 130 |
+
- **Complex**: Subqueries, multiple JOINs, UNION
|
| 131 |
+
|
| 132 |
+
## License
|
| 133 |
+
|
| 134 |
+
This model is released under the Apache 2.0 license.
|
| 135 |
+
|
| 136 |
+
## Links
|
| 137 |
+
|
| 138 |
+
- [Distil Labs Website](https://distillabs.ai)
|
| 139 |
+
- [GitHub](https://github.com/distil-labs)
|
| 140 |
+
- [Hugging Face](https://huggingface.co/distil-labs)
|
model.gguf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a483a4019243d3ae0b531cb71375772e36d0f4429102dce0a0bda94a045261ad
|
| 3 |
+
size 2497276000
|