Instructions to use farehaheha/llama3.2-3B-text-to-sql with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use farehaheha/llama3.2-3B-text-to-sql with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="farehaheha/llama3.2-3B-text-to-sql")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("farehaheha/llama3.2-3B-text-to-sql") model = AutoModelForCausalLM.from_pretrained("farehaheha/llama3.2-3B-text-to-sql", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use farehaheha/llama3.2-3B-text-to-sql with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "farehaheha/llama3.2-3B-text-to-sql" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "farehaheha/llama3.2-3B-text-to-sql", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/farehaheha/llama3.2-3B-text-to-sql
- SGLang
How to use farehaheha/llama3.2-3B-text-to-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 "farehaheha/llama3.2-3B-text-to-sql" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "farehaheha/llama3.2-3B-text-to-sql", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "farehaheha/llama3.2-3B-text-to-sql" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "farehaheha/llama3.2-3B-text-to-sql", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Unsloth Studio
How to use farehaheha/llama3.2-3B-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 farehaheha/llama3.2-3B-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 farehaheha/llama3.2-3B-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 farehaheha/llama3.2-3B-text-to-sql to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="farehaheha/llama3.2-3B-text-to-sql", max_seq_length=2048, ) - Docker Model Runner
How to use farehaheha/llama3.2-3B-text-to-sql with Docker Model Runner:
docker model run hf.co/farehaheha/llama3.2-3B-text-to-sql
Llama 3.2 3B — Text-to-SQL
A fine-tuned version of Meta Llama 3.2 3B for converting natural-language questions into SQL queries.
The model was fine-tuned using QLoRA with a 4-bit quantized base model and LoRA adapters. After training, the adapter was merged with the base model to produce this standalone model.
Model Repositories
Merged Model
The base model and trained LoRA adapter have been merged into a standalone model:
https://huggingface.co/farehaheha/llama3.2-3B-text-to-sql
Quantized GGUF Model
A Q4_K_M GGUF quantized version is available for efficient local inference with llama.cpp and other GGUF-compatible runtimes:
https://huggingface.co/farehaheha/llama3.2-3B-text-to-sql-Q4_K_M-GGUF
Training Details
| Parameter | Value |
|---|---|
| Base Model | meta-llama/Llama-3.2-3B |
| Fine-tuning Method | QLoRA |
| Base Model Quantization During Training | 4-bit |
| LoRA Rank | 16 |
| Training Dataset | gretelai/synthetic_text_to_sql |
| Dataset Split Used | Test split |
| Training Samples | ~5.85K |
| Epochs | 1 |
| Batch Size | 8 |
| Training Time | ~30 minutes |
Note: This experiment used the dataset's test split for fine-tuning rather than the training split. Therefore, the original test split should not be used to report an unbiased evaluation score for this model.
Dataset
The model was fine-tuned on:
Gretel AI Synthetic Text-to-SQL
https://huggingface.co/datasets/gretelai/synthetic_text_to_sql
The dataset contains natural-language questions paired with SQL queries and database context.
Approximately 5,850 examples from the test split were used for this fine-tuning experiment.
Fine-Tuning Approach
The training process used QLoRA:
- The Llama 3.2 3B base model was loaded in 4-bit precision.
- The original base model weights remained frozen.
- LoRA adapters with rank 16 were trained on the Text-to-SQL dataset.
- Training was performed for one epoch.
- The trained LoRA adapter was merged with the base model.
- The merged model was also converted to Q4_K_M GGUF for local inference.
This approach significantly reduces the memory required for fine-tuning compared with full-parameter training.
Usage
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "farehaheha/llama3.2-3B-text-to-sql"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
torch_dtype="auto",
)
prompt = """### Database Schema:
{your_database_schema}
### Request:
{your_natural_language_request}
### SQL Query:
"""
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=256,
do_sample=False,
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
- Downloads last month
- 1,268