From Text to SQL: Fine-Tuning Phi-4-Mini-Instruct with LoRA and PyTorch (Deep Dive)
This video walks through the full workflow of fine-tuning the Phi-4-Mini-Instruct model using LoRA and PyTorch, covering how to format custom training data, code a fine-tuning script, run jobs in a Docker container, merge fine-tuned adapters, and quantize the model for efficient local or edge device operation. Viewers will gain hands-on experience with these techniques applicable to any CUDA-based environment.
Description
In this deep-dive video, I’ll walk through the full workflow of LoRA fine-tuning the Phi-4-Mini-Instruct model to improve natural-language-to-SQL accuracy.
You’ll learn how to:
• What fine-tuning is, how it compares to RAG (Retrieval-Augmented Generation), and when to use each
• Coding a PyTorch fine-tuning script for small models
• Formatting custom training data for LLMs
• Running fine-tuning jobs in a Docker container
• Merging fine-tuned adapters into a single model
•Quantizing the model to run efficiently on edge or local devices
• Testing your fine-tuned model on a desktop with LM Studio
The demonstration runs on an NVIDIA DGX Spark, but the methods apply to any CUDA-based environment.
If you’re a developer or AI engineer who wants to get hands-on with customizing small language models, this deep-dive is for you.
Link to Github repo with scripts and data used in the video:
https://github.com/robkerr/robkerrai-demo-code/tree/main/dgx-spark-lora-finetune-phi3
Link to NVIDIA Spark DGX Training with PyTorch Playbook:
https://build.nvidia.com/spark/pytorch-fine-tune
00:00 - Introduction
03:07 - Training Data
05:23 - Training Script
11:18 - Docker Startup
15:37 - Python Env Setup – Running LoRA Fine-Tuning
16:47 - Training Script
21:11 - Merging Adapters
23:03 - Llama.cpp Setup
24:36 - Creating a gguf
25:33 - Quantizing the Model
29:05 - Testing with Llama.cpp
33:00 - Testing in LM Studio
36:55 - Summary