← things I build
Phi-3 QLoRA.
A pipeline that fine-tunes Phi-3-mini with QLoRA on Databricks Dolly 15k, tracks runs in MLflow, exports to ONNX and serves generation over FastAPI.
TECH USED
PyTorch
Hugging Face
MLflow
ONNX
FastAPI
Docker


the full path
From problem to what's next.
In the order it actually happened. Use the route to jump around.
01THE PROBLEM
Fine-tuning a small LLM is only half the job: the run has to fit limited GPU memory, stay tracked and reproducible, and end up served behind an API.
02THE SOLUTION
A training script loads Phi-3-mini in 4-bit NF4 and trains LoRA adapters on 8,000 Dolly samples with TRL, logging to MLflow. The adapter is merged, optionally exported to ONNX with Optimum, and served by FastAPI on PyTorch or ONNX Runtime.
WHAT I BUILT
- 01Wrote the QLoRA SFT script: 4-bit NF4 base, LoRA on attention and MLP projections, eval-loss checkpointing and MLflow logging.
- 02Added merge-to-disk and an Optimum ONNX export script.
- 03Built a FastAPI service with /generate and /compare (base vs fine-tuned), switching between PyTorch and ONNX Runtime backends.
- 04Added Docker Compose for the API and MLflow, and a notebook that plots MLflow metrics.
03HOW IT'S BUILT
The system, end to end.
TRAINING
- STEP 01Dolly 15k8,000 samples · 5% eval split
- STEP 02TRL SFTTrainerQLoRA · 4-bit NF4 · LoRA r=16
- STEP 03MLflowparams, metrics, adapter artifacts
- STEP 04Adapter and mergedsaved to outputs/
SERVING
- STEP 01Merged weightsfrom the training run
- STEP 02Optimum exportONNX, optional
- STEP 03Inference backendPyTorch or ONNX Runtime, by env var
- STEP 04FastAPI/generate · /compare · /health
04WHAT BROKE,
AND THE FIX
AND THE FIX
FIX →The service keeps a PyTorch backend that loads the merged weights or the adapter directly.
FIX →The service loads weights from the merged path and the architecture from MODEL_ID.
05WHERE IT IS NOW
- IDEA
- BUILDING
- LIVE
Training, export and serving code are in the repo with a documented quick start.