Series · 11 posts
From PyTorch to Deployment
ONNX export, quantization, preprocessing bugs, inference threading, batching curves and CPU-vs-GPU serving, measured with latency and accuracy numbers.
What actually breaks and what actually costs between a trained PyTorch model and a model serving requests: export failures, quantization results that contradict the brochure, preprocessing mistakes ranked by damage, and the serving curves that decide between CPU and GPU.
- 1Quantization for Edge Devices: Lessons From Real HardwareJuly 15, 2026Quantization for Edge Devices: Lessons from Deploying on Real Hardware
PTQ vs QAT, memory layouts and the hardware constraints that only show up on deployment day, from models on embedded targets.
- 2What Breaks When Exporting PyTorch Models to ONNXJuly 21, 2026What Actually Breaks When You Export PyTorch Models to ONNX
Four ONNX export failures reproduced on a real machine: fixed batch sizes, baked-in branches, unsupported ops and a Windows crash, with fixes.
- 3ONNX Quantization Measured: Size, Latency, AccuracyJuly 22, 2026Quantizing an ONNX Model in Practice: The Numbers Nobody Shows You
A real model quantized with onnxruntime and measured on file size, latency and accuracy. Dynamic quantization made the CNN 3x slower.
- 4Image Preprocessing Bugs Ranked by Accuracy CostAugust 20, 2026Quantization Cost My Model 0.13 Points. Preprocessing Bugs Cost Up to 72
BGR order, missing normalization, wrong stats, JPEG artifacts and resize errors injected one at a time. The costliest bug took 72 points.
- 5Forgetting model.eval() in PyTorch: The Measured CostAugust 24, 2026Forget model.eval() and Your Accuracy Depends on Your Traffic
Train-mode batch norm scores chance on single requests and looks fine at batch 256, which is why load tests miss it. Plus what no_grad really buys.
- 6ONNX Runtime CPU Inference Threading, MeasuredAugust 25, 2026CPU Inference Threading: The Default Grabs Every Core and Still Loses
Latency vs thread count for a 103 KB and a 43 MB model, then eight single-threaded sessions against one default session: 1.7x the throughput.
- 7Golden-Sample Tests for ML Models: Choosing the ToleranceSeptember 1, 2026The Twenty-Line Test I Kept Promising, and the Tolerance That Makes It Work
Legitimate variation moved logits by at most 0.006; the weakest injected bug moved them 1.15. That 190x gap is where the golden-sample test lives.
- 8GPU Inference Batching Curve: Batch 1 to 256, fp32 and fp16September 2, 2026Batch 1 Uses 8% of Your GPU, and Other Things the Batching Curve Says
Batch size swept 1 to 256 over three model sizes on an RTX 4080 SUPER. The first eight images are free and fp16 is slower until batch 16.
- 9ONNX Runtime Graph Optimization Levels, MeasuredSeptember 22, 2026ONNX Runtime's Optimization Levels Do Completely Different Things to Different Models
Across three models: int8 is a 3.4x win that collapses if optimization is off, ResNet18 gets 35% from layout and almost nothing from fusion.
- 10CPU vs GPU Serving Latency: Where the Crossover IsSeptember 23, 2026The GPU Has a 0.8 ms Floor, and My Sensor Model Lives Under It
Four model sizes on ONNX Runtime CPU vs PyTorch fp16 GPU. At batch 1 the tiny IMU model is 11.7x faster on CPU; one batch later, GPU wins 62x.
- 11TTA Serving Cost: Ten Views for 8% With Concatenated BatchesOctober 22, 2026One Good Question Repriced TTA: Ten Views Now Cost 8%
Sequential TTA pays 2x for a flip and 10x for ten views at every batch size. Concatenated TTA rides the GPU overhead floor: ten views cost 8%.