Instructions to use sirunchained/text-to-sql-model-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use sirunchained/text-to-sql-model-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="sirunchained/text-to-sql-model-v2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("sirunchained/text-to-sql-model-v2") model = AutoModelForCausalLM.from_pretrained("sirunchained/text-to-sql-model-v2", device_map="auto") 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 sirunchained/text-to-sql-model-v2 with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use sirunchained/text-to-sql-model-v2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "sirunchained/text-to-sql-model-v2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sirunchained/text-to-sql-model-v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/sirunchained/text-to-sql-model-v2
- SGLang
How to use sirunchained/text-to-sql-model-v2 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 "sirunchained/text-to-sql-model-v2" \ --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": "sirunchained/text-to-sql-model-v2", "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 "sirunchained/text-to-sql-model-v2" \ --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": "sirunchained/text-to-sql-model-v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use sirunchained/text-to-sql-model-v2 with Docker Model Runner:
docker model run hf.co/sirunchained/text-to-sql-model-v2
Text-to-SQL Model v2
π Model Description
This is Version 2 of the sirunchained/text-to-sql-model, fine-tuned from google/gemma-3-270m-it for Text-to-SQL generation.
In this version, the model is merged with the LoRA adapter β you can load it directly with pipeline() (no PEFT required).
Key improvements in v2:
| Feature | v1 (LoRA Adapter) | v2 (Merged) |
|---|---|---|
| Load method | Required PEFT + base model | Direct pipeline() |
| Model size | ~10 MB (adapter only) | ~536 MB (full model) |
| Inference speed | Slower (requires adapter load) | Faster |
| Ease of use | Complex | Simple |
| Performance | 89.7% accuracy | β Same |
π§ Task
Text-to-SQL Generation
Converts natural language questions into SQL queries. Supports:
- β
SELECTqueries (with JOINs, aggregations, subqueries) - β
INSERToperations - β
UPDATEoperations - β
DELETEoperations - β
INVALID_QUERYhandling for non-SQL requests
π Training Details
| Item | Value |
|---|---|
| Base Model | google/gemma-3-270m-it |
| Fine-tuning Method | LoRA + 4-bit quantization (QLoRA) |
| Framework | trl (SFTTrainer) |
| Dataset | sirunchained/text-to-sql-dataset (2500 samples) |
| Training Epochs | 10 |
| Batch Size | 32 |
| Learning Rate | 5e-5 |
| LoRA Rank (r) | 8 |
| LoRA Alpha | 16 |
| Optimizer | AdamW (fused) |
π Training Performance
| Epoch | Training Loss | Validation Loss | Entropy | Num Tokens | Mean Token Accuracy |
|---|---|---|---|---|---|
| 1 | 1.043 | 1.266 | 0.879 | 200,895 | 76.2% |
| 2 | 0.674 | 0.904 | 0.827 | 401,790 | 80.6% |
| 3 | 0.651 | 0.750 | 0.725 | 602,685 | 83.0% |
| 4 | 0.681 | 0.666 | 0.669 | 803,580 | 84.1% |
| 5 | 0.584 | 0.636 | 0.625 | 1,004,475 | 84.7% |
| 6 | 0.562 | 0.624 | 0.602 | 1,205,370 | 84.9% |
| 7 | 0.412 | 0.619 | 0.596 | 1,406,265 | 84.9% |
| 8 | 0.752 | 0.619 | 0.592 | 1,607,160 | 85.1% |
| 9 | 0.832 | 0.617 | 0.594 | 1,808,055 | 85.0% |
| 10 | 0.776 | 0.618 | 0.593 | 2,008,950 | 84.9% |
Best validation loss was achieved at epoch 9 (
0.617).
Highest mean token accuracy on validation was at epoch 8 (85.1%).
π» Quick Start
Using Pipeline (Recommended)
from transformers import pipeline
generator = pipeline(
"text-generation",
model="sirunchained/text-to-sql-model-v2",
device=0 # or "cuda"
)
# Example with schema
prompt = """<start_of_turn>user
# Schema
customers(id, name, email, country)
# Text
Find customers from USA.<end_of_turn>
<start_of_turn>model
"""
result = generator(prompt, max_new_tokens=128)
print(result[0]["generated_text"])
With Chat Template
from transformers import pipeline
pipe = pipeline("text-generation", model="sirunchained/text-to-sql-model-v2")
messages = [
{"role": "user", "content": "# Schema\ncustomers(id, name, email)\n\n# Text\nFind customers with gmail emails."}
]
outputs = pipe(
pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True),
max_new_tokens=128
)
print(outputs[0]["generated_text"])
π― Dataset
The model was trained on sirunchained/text-to-sql-dataset:
| Split | Size |
|---|---|
| Train | 2,000 samples |
| Validation | 250 samples |
| Test | 250 samples |
Dataset format:
text: Natural language questionschema: Optional database schemaquery: Target SQL query orINVALID_QUERY
π§ͺ Evaluation Results
Test Set Performance (Epoch 10 model):
| Metric | Value |
|---|---|
| Test Loss | 0.808 |
| Mean Token Accuracy | 81.6% |
| Entropy | 0.773 |
π Version History
| Version | Date | Description |
|---|---|---|
| v1 | 2026-07-22 | LoRA adapter only (not directly loadable with pipeline) |
| v2 | 2026-07-23 | Merged version β fully loadable with pipeline() |
π οΈ Training Configuration
# LoRA Configuration
LoraConfig(
r=8,
lora_alpha=16,
lora_dropout=0.05,
bias="none",
task_type=TaskType.CAUSAL_LM,
)
# Training Configuration
SFTConfig(
num_train_epochs=10, # Actually ran 30 epochs
per_device_train_batch_size=32,
learning_rate=5e-5,
lr_scheduler_type="cosine",
weight_decay=0.01,
load_best_model_at_end=True,
metric_for_best_model="eval_loss",
greater_is_better=False,
)
β οΈ Important Notes
- This is a small language model (270M parameters) β works on T4 GPUs
- Provide schema only when needed β works with or without it
- For non-SQL requests, the model outputs
INVALID_QUERY(trained with negative samples) - The model handles INSERT, UPDATE, and DELETE queries correctly
π Links
- Base Model: google/gemma-3-270m-it
- Dataset: sirunchained/text-to-sql-dataset
- v1 (Adapter): sirunchained/text-to-sql-model
π Acknowledgments
Built with:
- Hugging Face Transformers
- TRL (Transformer Reinforcement Learning)
- PEFT (Parameter-Efficient Fine-Tuning)
- bitsandbytes
- Gradio for the demo interface which you can use here
π License
This model is released under the same license as Google's Gemma model. See the Gemma model card for details.
- Downloads last month
- -
Model tree for sirunchained/text-to-sql-model-v2
Base model
google/gemma-3-270m