Instructions to use Shaleen123/gemma4-12b-sql with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Shaleen123/gemma4-12b-sql with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Shaleen123/gemma4-12b-sql") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("Shaleen123/gemma4-12b-sql") model = AutoModelForMultimodalLM.from_pretrained("Shaleen123/gemma4-12b-sql", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Shaleen123/gemma4-12b-sql with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Shaleen123/gemma4-12b-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": "Shaleen123/gemma4-12b-sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Shaleen123/gemma4-12b-sql
- SGLang
How to use Shaleen123/gemma4-12b-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 "Shaleen123/gemma4-12b-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": "Shaleen123/gemma4-12b-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 "Shaleen123/gemma4-12b-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": "Shaleen123/gemma4-12b-sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Shaleen123/gemma4-12b-sql with Docker Model Runner:
docker model run hf.co/Shaleen123/gemma4-12b-sql
File size: 8,018 Bytes
deb208a 054ebc5 9a5f19f deb208a ead398b 2b8f35e ec65e2f 5c06f12 b7af755 ec65e2f 2b8f35e ec65e2f 5c06f12 ec65e2f a5a98e9 ec65e2f 8ae9b97 ec65e2f 5c06f12 ec65e2f | 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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | ---
datasets:
- Shaleen123/text2sql-v1
language:
- en
base_model:
- google/gemma-4-12B-it
pipeline_tag: text-generation
library_name: transformers
---
**A Gemma 4 12B model fine-tuned for text-to-SQL: turn natural-language questions into correct, executable SQL given a database schema.**
---
## Model Summary
| | |
|---|---|
| **Model** | `Shaleen123/gemma4-12b-sql` |
| **Base model** | Gemma 4 12B |
| **Task** | Text-to-SQL / schema-grounded query generation |
| **Parameters** | ~12B |
| **Language** | English (natural-language questions), SQL (output) |
This model takes a database schema (DDL) and a question, and returns a SQL query. It is intended to help analysts, developers, and applications that need to query relational data without hand-writing SQL.
## Intended Use
**Good fits**
- Natural-language interfaces over relational databases (BI tools, chat-with-your-data apps)
- SQL autocomplete and drafting assistants for analysts and engineers
- Generating a first draft of a query that a human then reviews
- Research and benchmarking on text-to-SQL
## How to Use
### Prompt format
The model was trained with the following system prompt. Use it as-is for best results:
```
You are the best SQL Agentic Model. Given a database schema and a natural language question, generate the correct SQL query. Return only the SQL query without explanations.
```
Then provide the schema first, followed by the question, in the user turn. (TODO: confirm the user-turn template matches what was used in training.)
```
### Schema
CREATE TABLE customers (
id INT PRIMARY KEY,
name TEXT,
country TEXT,
signup_date DATE
);
CREATE TABLE orders (
id INT PRIMARY KEY,
customer_id INT REFERENCES customers(id),
total NUMERIC,
created_at TIMESTAMP
);
### Question
What are the top 5 countries by total order value in 2024?
### SQL
```
### Transformers
```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "Shaleen123/gemma4-12b-sql"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
schema = """
CREATE TABLE customers (id INT PRIMARY KEY, name TEXT, country TEXT, signup_date DATE);
CREATE TABLE orders (id INT PRIMARY KEY, customer_id INT REFERENCES customers(id),
total NUMERIC, created_at TIMESTAMP);
"""
question = "What are the top 5 countries by total order value in 2024?"
SYSTEM_PROMPT = (
"You are the best SQL Agentic Model. Given a database schema and a natural language "
"question, generate the correct SQL query. Return only the SQL query without explanations."
)
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{
"role": "user",
"content": f"### Question\n{question}\n### Scheme\n{scheme}",
},
]
# If your chat template does not support a separate system role,
# prepend SYSTEM_PROMPT to the user message instead.
inputs = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, return_tensors="pt", return_dict=True
).to(model.device)
with torch.no_grad():
output = model.generate(**inputs, max_new_tokens=256, do_sample=False)
print(tokenizer.decode(output[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
```
### Recommended generation settings
- `temperature = 1.0` and 'top_p = 0.95' for deterministic, reproducible SQL
- `max_new_tokens` of 10,000 covers most queries
- Stop on a semicolon or end-of-turn token to avoid trailing explanations
### vLLM
```bash
vllm serve Shaleen123/gemma-4-12B-sql --dtype bfloat16 --max-model-len 8192
```
```python
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
resp = client.chat.completions.create(
model="Shaleen123/gemma-4-12B-sql",
temperature=0,
messages=[
{"role": "system", "content": "You are the best SQL Agentic Model. Given a database schema and a natural language question, generate the correct SQL query. Return only the SQL query without explanations."},
{"role": "user", "content": "### Schema\nCREATE TABLE users (id INT, name TEXT, age INT);\n### Question\nHow many users are older than 30?"},
],
)
print(resp.choices[0].message.content)
```
### Hardware notes
A 12B model in bf16 needs roughly 24–28 GB of VRAM for weights alone. For smaller GPUs, use 8-bit or 4-bit quantization (e.g. bitsandbytes, AWQ, or GGUF). Expect a small accuracy drop at lower precision. (TODO: report measured numbers if you have them.)
## Training Details
> TODO: fill in everything below with your actual setup.
**Data**
- Sources: TODO (e.g. Spider, BIRD, WikiSQL, synthetic data, internal data)
- Size: TODO examples
- Preprocessing: TODO (dedup, schema formatting, dialect filtering, execution-based filtering)
- Dialects covered: TODO (e.g. SQLite, PostgreSQL, MySQL, BigQuery)
**Procedure**
- Method: TODO (SFT with LoRA r=?, alpha=?, target modules=?)
- Epochs / steps: TODO
- Learning rate & scheduler: TODO
- Batch size (effective): TODO
- Max sequence length: TODO
- Precision: TODO (bf16)
- Hardware & training time: TODO
- Frameworks: TODO (e.g. TRL, Unsloth, Axolotl, PEFT)
## Evaluation
> TODO: add real results. Suggested benchmarks and metrics below.
| Benchmark | Metric | Base Gemma 4 12B | This model |
|---|---|---|---|
| Spider (dev) | Execution accuracy | TODO | TODO |
| Spider (dev) | Exact-set-match | TODO | TODO |
| BIRD (dev) | Execution accuracy | TODO | TODO |
| Custom / internal | TODO | TODO | TODO |
Execution accuracy (does the query return the correct result?) is more meaningful than string match, since many different SQL queries are equivalent. Report the prompt format, decoding settings, and whether schema values or hints were provided, so results are reproducible.
## Limitations and Risks
- **Hallucinated schema elements.** The model may reference tables or columns that don't exist, especially with large or ambiguous schemas.
- **Ambiguity.** Vague questions ("best customers") may be interpreted differently than intended. Clarify metrics and time ranges in the prompt.
- **Dialect drift.** Output may mix syntax across SQL dialects. State the target dialect explicitly.
- **Complex queries.** Deeply nested subqueries, window functions, recursive CTEs, and multi-hop joins are more error-prone.
- **Not safe by construction.** Generated SQL can be destructive or expensive (full scans, cross joins). It can also be vulnerable to prompt injection if user-supplied text is embedded in the prompt.
- **Inherited biases and limitations** from the base model and training data.
### Safe deployment checklist
1. Connect with a **read-only** database role.
2. Parse and validate SQL (allow-list `SELECT`; block DDL/DML) before execution.
3. Enforce query timeouts and row limits.
4. Run `EXPLAIN` or a dry run on large datasets.
5. Log queries and keep a human in the loop for anything sensitive.
6. Optionally add execution-feedback retries: on error, pass the error message back to the model for a corrected query.
## License
TODO. This model is a derivative of Gemma 4 and is subject to the base model's license and use policy. Review the terms on the base model's page before use or redistribution. Also check the licenses of your training datasets.
## Citation
```bibtex
@misc{shaleen2026gemma4sql,
author = {Shaleen},
title = {gemma4-12b-sql: A Text-to-SQL Fine-tune of Gemma 4 12B},
year = {2026},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/Shaleen123/gemma-4-12B-sql}}
}
```
## Acknowledgements
Built on Gemma by Google. Thanks to the creators of the text-to-SQL datasets and open-source tooling used in training. (TODO: credit specific datasets and libraries.)
## Contact
Questions, issues, or feedback: open a discussion on the model's Hugging Face page. (TODO: add other contact info if desired.) |