LLM & RAG · 2026
Edge4-SQL: CPU-Optimized Text-to-SQL
Phi-4-mini-instruct (3.8B) fine-tuned with QLoRA on the QuerySmith-Spider-Bird dataset (derived from Spider and BIRD), then compressed with a partial-residual quantization scheme and served with llama.cpp. The final model reaches 0.743 exact-match accuracy at 22.3 ms/token and 3.5 GB, against an FP32 baseline of 0.713 at 148 ms/token and 14.9 GB (6.6x faster, 4.2x smaller).
Model
- Base: Phi-4-mini-instruct (3.8B parameters)
- Fine-tune: QLoRA adapters on attention and MLP projections, 4-bit NF4 base
- Compression: partial-residual quantization — residual-aware weight rounding, exported to Q4_K_M GGUF
- Serving: llama.cpp CPU inference with a fixed prompt template for SQL generation
Dataset
QuerySmith-Spider-Bird — schema-linked question/SQL pairs derived from Spider and BIRD, normalized into a single instruction format.
Results & metrics
- Exact match
- 0.743
- FP32 baseline EM
- 0.713
- Speed
- 22.3 ms/token
- Model size
- 3.5 GB
- vs FP32
- 6.6x faster · 4.2x smaller
Deployment steps
- 1Fine-tune QLoRA adapters on the QuerySmith-Spider-Bird training split
- 2Merge adapters into the base model, then quantize with partial-residual rounding
- 3Export to GGUF (Q4_K_M) and validate exact-match against the FP32 checkpoint
- 4Serve with llama.cpp behind a small FastAPI wrapper
- 5Publish the quantized checkpoint to Hugging Face
Tech stack
- Phi-4-mini
- QLoRA
- Quantization
- GGUF
- llama.cpp