Packaging & deployment
P13.ml-lifecycle.02 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Evaluation infrastructure & experiment tracking
Where next?
This module unlocks
Go up a level
P13.ml-lifecycle.02 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Evaluation infrastructure & experiment tracking
This module unlocks
Go up a level
A fitted model living in a notebook's memory is a fact about your machine, not a shippable artefact. Deployment is the discipline of turning that in-memory object into a byte-exact, verifiable, documented package a stranger (or a serving container, or you in six months) can reload and get the same predictions from. P13.ml-lifecycle.01 made evaluation reproducible; this module makes the model itself reproducible — serialisation, a checksummed manifest, a model card, and the round-trip contract that ties them together.
When you call pipeline.fit(X, y) the result is a graph of Python objects on a heap — coefficients, fitted encoders, learned vocabularies — reachable only from a variable in one interpreter. Close the notebook and it is gone. To ship a model you must turn that live graph into bytes on disk that another process can read back into an equivalent object. That is serialisation.
load(path) → model, then model.predict(rows) → predictions. The serving layer knows nothing of how the model was trained; it only depends on that two-call contract. Packaging is the work of making that contract hold across machines and time.Two serialisers dominate the Python ML world:
pipeline.joblib.The failure mode this prevents is "works on my machine": the bytes reload fine on the author's laptop but explode in the serving container because a class moved, a dependency version drifted, or the file was silently truncated in transit. The rest of this module removes each of those ambiguities in turn.
Practise this lesson's 3 self-checks
One per screen: you reveal each answer and mark it yourself. Nothing is recorded.
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
Build the packaging core by hand: a sha256 manifest hasher, a byte-integrity verifier that reports corrupt or missing files on reload, and the round-trip contract — pickle a model, reload it in a fresh object, and prove the predictions are identical. All stdlib; no network, no sklearn required.
Loading exercise…
Loading exercise…
Loading exercise…
load(path) → model / model.predict(rows) contract.pickle (stdlib, class must be importable at load, not a security boundary) · joblib (pickle-compatible, optimised for large NumPy arrays, sklearn default).{filename, bytes, sha256}. Consumer re-hashes on reload and rejects a corrupt/missing file before deserialise. sha256, not length — length misses corruption.Where the pieces of this module lead.
| Type | Resource |
|---|---|
| In-app | P13.ml-lifecycle.01 — Evaluation infrastructure & experiment tracking: the gate that decides a model may ship, before this module packages it |
| In-app | P5.applied-cases.01 — The honest tabular model: the fitted Pipeline + model card this module packages (ships as pipeline.joblib) |
| In-app | P13.cases.01 — the end-to-end serving-and-drift case that threads a checksummed, card-carrying package into production |
| Docs | joblib persistence & scikit-learn model persistence guide; Python hashlib / pickle stdlib docs |
| Paper | Mitchell et al. (2019), Model Cards for Model Reporting — the documentation template this module packages |
A scratch console for this page's ideas — ungraded, nothing you run here is recorded.
Scratch console
A scratch console with the scientific stack (pandas, numpy, scikit-learn). Runs on the server — no network, resource-limited and measured.
Output appears here.
Loading your notes...