Text Generation
Transformers
Safetensors
English
phi3
sql
text-to-sql
code-generation
phi-3
fine-tuned
conversational
custom_code
text-generation-inference
Instructions to use Shizu0n/phi3-mini-sql-generator-merged with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Shizu0n/phi3-mini-sql-generator-merged with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Shizu0n/phi3-mini-sql-generator-merged", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Shizu0n/phi3-mini-sql-generator-merged", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("Shizu0n/phi3-mini-sql-generator-merged", trust_remote_code=True) 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use Shizu0n/phi3-mini-sql-generator-merged with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Shizu0n/phi3-mini-sql-generator-merged" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Shizu0n/phi3-mini-sql-generator-merged", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Shizu0n/phi3-mini-sql-generator-merged
- SGLang
How to use Shizu0n/phi3-mini-sql-generator-merged 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 "Shizu0n/phi3-mini-sql-generator-merged" \ --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": "Shizu0n/phi3-mini-sql-generator-merged", "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 "Shizu0n/phi3-mini-sql-generator-merged" \ --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": "Shizu0n/phi3-mini-sql-generator-merged", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Shizu0n/phi3-mini-sql-generator-merged with Docker Model Runner:
docker model run hf.co/Shizu0n/phi3-mini-sql-generator-merged
File size: 3,254 Bytes
d3d4aab 7af565c d3d4aab 7af565c d3d4aab 7af565c d3d4aab 7af565c d3d4aab 7af565c d3d4aab 7af565c d3d4aab 7af565c d3d4aab 7af565c d3d4aab b47b6d1 d3d4aab 7af565c d3d4aab 7af565c d3d4aab b47b6d1 d3d4aab 7af565c d3d4aab 7af565c d3d4aab b47b6d1 7af565c b47b6d1 7af565c d3d4aab 7af565c d3d4aab 7af565c | 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 | ---
base_model: microsoft/Phi-3-mini-4k-instruct
library_name: transformers
license: mit
language:
- en
datasets:
- b-mc2/sql-create-context
tags:
- sql
- text-to-sql
- code-generation
- phi-3
- fine-tuned
- text-generation
- phi3
pipeline_tag: text-generation
---
# Phi-3 Mini SQL Generator — Merged Model
Merged standalone version of [Shizu0n/phi3-mini-sql-generator](https://huggingface.co/Shizu0n/phi3-mini-sql-generator)
— LoRA adapter weights fused into [Phi-3-mini-4k-instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct).
No PEFT dependency required for inference.
## Evaluation — Base vs Fine-tuned
Evaluated on 200 held-out examples from [b-mc2/sql-create-context](https://huggingface.co/datasets/b-mc2/sql-create-context).
| Model | Exact Match |
|---|---|
| Phi-3-mini-4k-instruct (base) | 2.0% |
| **This model (fine-tuned)** | **73.5%** |
> Exact match: normalized SQL comparison (lowercase, strip whitespace/semicolons).
## Why two versions?
| Repo | Purpose |
|---|---|
| [`Shizu0n/phi3-mini-sql-generator`](https://huggingface.co/Shizu0n/phi3-mini-sql-generator) | QLoRA adapter — documents the training pipeline |
| `Shizu0n/phi3-mini-sql-generator-merged` | Merged standalone — used for deployment and inference |
## Training Details
- **Dataset:** b-mc2/sql-create-context — 1,000 train / 200 validation examples
- **Method:** QLoRA (4-bit NF4, LoRA rank 16, alpha 32, target modules: qkv_proj/o_proj/gate_up_proj/down_proj)
- **Hardware:** NVIDIA T4 (Google Colab free tier)
- **Training time:** ~21 min
- **Final train loss:** 0.6526
- **Best checkpoint:** step 250 (by eval loss)
## Inference Example
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "Shizu0n/phi3-mini-sql-generator-merged"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.float16,
device_map="auto",
trust_remote_code=False,
attn_implementation="eager",
)
model.eval()
prompt = (
"Given the following SQL table, write a SQL query.\n\n"
"Table: employees (id, name, department, salary)\n\n"
"Question: What is the average salary per department?\n\nSQL:"
)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.inference_mode():
outputs = model.generate(
**inputs,
max_new_tokens=80,
do_sample=False,
use_cache=False,
repetition_penalty=1.1,
pad_token_id=tokenizer.eos_token_id,
)
prompt_len = inputs["input_ids"].shape[-1]
print(tokenizer.decode(outputs[0][prompt_len:], skip_special_tokens=True))
```
Expected output:
```sql
SELECT AVG(salary), department FROM employees GROUP BY department
```
## Validation
Merge accepted after three smoke tests:
1. PEFT adapter loaded on base model
2. Local merged directory after `merge_and_unload()` + `save_pretrained()`
3. Downloaded from this repo with `force_download=True`
## Limitations
- Fine-tuned on 1,000 examples — best suited for simple to medium complexity SELECT queries
- Not tested on dialect-specific SQL (PostgreSQL/MySQL-specific functions)
- May struggle with multi-table JOINs and nested subqueries |