CourseAI / ML Engineer: The Complete Course · Module 8: Model Optimisation · part 53 of 93
Part 53 · Module 8: Model Optimisation

Lab: Model v2 in ONNX, benchmarked

121 min read·
Module 8 · Lab · About 50 minutes · Needs: lessons 1 to 3 of this module, and the Module 7 lab (or nothing: Step 1 rebuilds Modules 1 to 7)

What you are building

Model v2 in ONNX, benchmarked One graph, checked against Python, then measured Active flow 1 Processing step number Model v2 encoder, trees Platt scaling train_v2.py Module 6 lab Export skl2onnx to_onnx + 7 Platt nodes parity check every parcel Runtime ONNX Runtime model.onnx 18 inputs OnnxModel predict_proba Records benchmark.md p99, cost ADR-005 runtime 1 2 3 4
v2's encoder, trees and Platt scaling are exported to one graph (teal), run by ONNX Runtime behind Kestrel's predict_proba (green) and checked against v2 on every parcel, then benchmarked and priced into the report and ADR-005 (purple); circles give the order.

Rhys's question is the second of the course's five: "What is p99, and where does the time go?" The lessons answered it for stand-ins: a LightGBM on 21 numbers and a small network, both trained in the lesson. This lab answers it for model v2 as the Module 6 lab built it: Module 3's encoder, LightGBM and Platt scaling, reading the 18 columns known at collection.

The lab exports the whole of v2, encoder and calibration included, to one ONNX graph, artifacts/model.onnx, and checks it parcel for parcel against v2 in Python. Then it benchmarks both with Lesson 3's harness, finds where a single parcel's time goes, prices a thousand predictions, and writes reports/benchmark.md and docs/adr/ADR-005-inference-runtime.md. The code lives in kestrel/optimise/onnx_model.py. No cell calls a hosted model.

Open a new Colab notebook, call it module-08-lab.ipynb, and run each cell in order. A CPU runtime is enough.

The rest of this course is yours to keep

This course is bought on its own, once, and stays readable afterwards, including the parts added to it later.

Or open everything with a plan