Instructions to use ssnym/llama-3.2-1b-text-to-sql with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use ssnym/llama-3.2-1b-text-to-sql with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/Llama-3.2-1B-Instruct-bnb-4bit") model = PeftModel.from_pretrained(base_model, "ssnym/llama-3.2-1b-text-to-sql") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Studio
How to use ssnym/llama-3.2-1b-text-to-sql 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 ssnym/llama-3.2-1b-text-to-sql 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 ssnym/llama-3.2-1b-text-to-sql to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for ssnym/llama-3.2-1b-text-to-sql to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="ssnym/llama-3.2-1b-text-to-sql", max_seq_length=2048, )
Llama-3.2-1B Text-to-SQL (QLoRA Fine-tuned)
LoRA adapter fine-tuned via QLoRA + SFT on b-mc2/sql-create-context, converting a table schema + natural language question into a SQL query.
Release date: August 10, 2026
Results (held-out test set, n=5000)
| Metric | Baseline | Fine-tuned |
|---|---|---|
| Exact match | 0.401 | 0.843 |
| Normalized match | 0.414 | 0.848 |
Metric definitions:
- Exact match: generated SQL is identical to ground truth after normalization (lowercase, whitespace, quote style).
- Normalized match: generated SQL has the same SELECT columns, FROM table, and WHERE conditions as ground truth, even if phrased slightly differently (more lenient than exact match).
Usage
This is a LoRA adapter — load it on top of the base model.
from unsloth import FastLanguageModel
from peft import PeftModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="unsloth/Llama-3.2-1B-Instruct-bnb-4bit",
max_seq_length=1024,
load_in_4bit=True,
)
model = PeftModel.from_pretrained(model, "ssnym/llama-3.2-1b-text-to-sql")
FastLanguageModel.for_inference(model)
SYSTEM_PROMPT = "You are a text-to-SQL assistant. Given a table schema and a question, output only the SQL Query"
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": "Context (schema):\nCREATE TABLE head (age INTEGER)\n\nQuestion: How many heads of the departments are older than 56 ?"}
]
inputs = tokenizer.apply_chat_template(
messages, tokenize=True, add_generation_prompt=True, return_tensors="pt"
).to("cuda")
outputs = model.generate(inputs, max_new_tokens=128, temperature=0.1)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Training details
- Base model: Llama-3.2-1B-Instruct, 4-bit NF4 quantization (QLoRA)
- LoRA: r=16, alpha=16, target modules: q/k/v/o/gate/up/down_proj
- Trainable params: 11,272,192 / 1,247,086,592 (0.90%)
- 2 epochs, 73,277 training examples, batch size 32
- Trained on an RTX A5000 (24GB VRAM)
Known limitations
Testing on out-of-distribution examples (custom schemas not from the training dataset) showed strong performance on single-table queries but weaker performance on multi-table JOINs, likely because the training dataset (b-mc2/sql-create-context) is predominantly single-table.
License
Built with Llama.
This adapter is released under the Llama 3.2 Community License, inherited from the base model (Meta Llama 3.2, released Sept 25, 2024). Base model weights via unsloth/Llama-3.2-1B-Instruct-bnb-4bit.
Links
- Notebook: Colab
- Blog post: [add once published]
- Downloads last month
- -
Model tree for ssnym/llama-3.2-1b-text-to-sql
Base model
meta-llama/Llama-3.2-1B-InstructDataset used to train ssnym/llama-3.2-1b-text-to-sql
Evaluation results
- Exact Match on b-mc2/sql-create-contextself-reported0.843
- Normalized Match on b-mc2/sql-create-contextself-reported0.848