ML8: Serving models

Lesson 5 of 5 · reading 15–25 minutes; practice and project time is on the module page

Packaging and deploying a model service

🎯You'll be able to

Package the API and model so it runs the same everywhere, and plan a safe rollout and rollback.

🏠The everyday picture

A tiffin service packs each meal in a labelled box with the date and what's inside, so whoever delivers it knows exactly what they carry, and an old box can be swapped back if a new recipe disappoints.

📘What it really is

📝A worked example

Input: a plan for DakDost's API (not verified in this kit; the Cloud / DevOps path shows Docker images and health checks working).

Steps:

  1. A Dockerfile based on a slim Python 3.13 image installs requirements.txt, copies dakdost/ and a model file, runs as an ordinary user, and starts uvicorn dakdost.serve:app --host 0.0.0.0 --port 8000.
  2. The model file is named by version (model-2026.07.1.joblib) and chosen with DAKDOST_MODEL.
  3. Release: run the new version in shadow for a week, logging both versions' probabilities for the same requests; compare flag rates and, once outcomes arrive, precision and recall; then switch, keeping the old image tagged.

Expected outcome: any running copy can say which model it serves, a bad model can be replaced by changing one setting, and a release can be undone in minutes.

🌍Where it's used

📝Case scenario

A team replaced their model by copying a new file onto the server, overwriting the old one. The new model had a bug, and the old file was gone. They rebuilt it from a week-old notebook, under pressure. Afterwards, every model file got a version in its name, was stored in a registry, and was selected by a setting.

🖱️Try it

Train two versions of the model with different settings and save them with versioned names. Start the API with DAKDOST_MODEL pointing at each in turn and call /health. Success: the version in /health changes with the setting, with no code change.

⚠️Common mistakes

🛠️For your project

Project 2's test 1 checks /health reports the model version; the capstone design notes cover rollout and rollback.

✅Quick check

What does a shadow release do?

Show the answer

Scores real requests with the new model without using its answers, so the two versions can be compared.

Why choose the model file through a setting?

Show the answer

So a different version can be loaded, or rolled back, without changing code.

← PreviousSpeed, batching and limits
ProLearners Assist