ML lifecycle and registry
From experiment to deployment
MLOps connects the machine-learning development cycle to reliable operation. Rather than moving a model file manually, record the training inputs, feature definitions, evaluation evidence, artifact version, deployment configuration and accountable owner. Consider a fictional warehouse inspection classifier: flag an item when its integer defect count reaches a threshold. Version v1 uses 3; v2 uses 4. Both thresholds are fixed before evaluating the same five held-out validation records. The function returns the numerator and denominator of accuracy, not just a percentage. V1 gets four correct out of five; v2 gets five. Neither is a measured production model. Chapter 21 explains why selection must use validation rather than the final test set. Preserve a separate untouched test split for final review; a tiny fixture is not evidence of deployment readiness.
def evaluate(rows, threshold): # rows: unique record IDs, nonnegative integer feature, binary label. if not rows or len({r[0] for r in rows}) != len(rows): raise ValueError("empty or duplicate evaluation records") if any(type(x) is not int or x < 0 or y not in (0, 1) for _, x, y in rows): raise ValueError("invalid feature or label") predictions = [int(x >= threshold) for _, x, _ in rows] correct = sum(p == r[2] for p, r in zip(predictions, rows)) return {"correct": correct, "total": len(rows)}
# Frozen thresholds were selected before opening this validation split.validation = [("V1", 1, 0), ("V2", 3, 0), ("V3", 4, 1), ("V4", 5, 1), ("V5", 2, 0)]for version, threshold in [("v1", 3), ("v2", 4)]: print(version, evaluate(validation, threshold))Track experiments and data contracts
A run record should contain immutable run ID, code revision, dataset and split IDs, feature schema, preprocessing revision, hyperparameters, random seed when relevant, dependency versions, artifact digest, metrics with denominators, and reviewer. For this example use fictional run R1 / R2, data inspect@1, validation@1, feature@1 (nonnegative integer count), threshold 3 / 4, and five validation IDs V1–V5. Training IDs T1–T4 and test IDs E1–E4 are separate illustrative assignments, not evaluated here. Split by the independent unit (for example item or production batch), not duplicated rows, to avoid leakage. Validate required fields, units, types, ranges, missing values and preprocessing consistency before training and serving. Do not silently convert missing counts to zero or change a feature definition under the same version. A reproducible manifest records dependencies but does not guarantee bitwise reproducibility across hardware.
Orchestrate and register versions
A pipeline is a dependency graph of steps: ingest approved data, validate schema and split, preprocess, train, evaluate, package, register, and request deployment review. Stop downstream stages when an upstream validation fails; reruns should reference exact inputs and avoid duplicate side effects. MLflow Tracking records experiments and runs; its Model Registry supports versioned models, lineage and mutable aliases. DVC can track data revisions and define reproducible pipeline stages with dependencies. Workflow schedulers such as Airflow can coordinate tasks and retries; these are optional tools, not a required stack. A registry entry should bind a version to immutable artifact and feature-contract identifiers; a deployment alias is a movable pointer, not a version. Here the registry accepts only matching validation and contract IDs, positive sample sizes, reviewed records and an inclusive minimum accuracy. V3 scored on training data and is excluded even with perfect accuracy. At 90 percent only v2 qualifies. At 80 both qualify. Eligibility is not authorization or an automatic ranking.
def candidate_versions(registry, split, contract, min_percent): # Trusted registry metadata; unique immutable version IDs. eligible = [] for version, record in registry.items(): c, n = record["correct"], record["total"] if (record["split"] == split and record["contract"] == contract and record["reviewed"] is True and 0 <= c <= n and n > 0 and 100 * c >= min_percent * n): eligible.append(version) return sorted(eligible)
registry = { "v1": dict(split="validation@1", contract="feature@1", correct=4, total=5, reviewed=True), "v2": dict(split="validation@1", contract="feature@1", correct=5, total=5, reviewed=True), "v3": dict(split="train@1", contract="feature@1", correct=5, total=5, reviewed=True),}print(candidate_versions(registry, "validation@1", "feature@1", 90))print(candidate_versions(registry, "validation@1", "feature@1", 80))Choose serving and rollout patterns
Batch prediction processes a bounded set of records on a schedule and can prioritize throughput; version the output, record input snapshot and handle repeated jobs idempotently. Online inference handles requests individually with latency and availability targets; validate requests and track the exact served version. Shadow deployment mirrors authorized requests to a candidate without using its outputs for business decisions; protect privacy and prohibit side effects. Canary deployment serves the new version to a small controlled traffic cohort, measures predefined quality and operational thresholds, then expands only after review. A shadow test cannot directly establish the impact of acting on predictions. A canary must have rollback capacity, compatible schemas and a way to stop exposure. A promotion should include representative evaluation, final test, security review, owner approval and a rollback rehearsal; the five examples above cannot establish these requirements.
Practice: assemble a release packet
Record R1 and R2 with the frozen split, exact thresholds, feature contract, counts and owner. Add v4 with 5/5 but incompatible contract feature@2. Predict which versions are eligible at 80 and 90 percent, and explain why a model trained on test data would invalidate evaluation. Design a pipeline with an explicit failure gate after schema validation and a read-only shadow step. Keep production alias pinned to v1 until independent review; do not execute a deployment. Use ref-ai-ml-lifecycle-and-registry and the data provenance lesson to connect the model and dataset versions.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
ML lifecycle and registry quiz
Assess experiment traceability, deployment gates, drift and rollback.
Which split is appropriate for choosing between the two frozen candidates?
Why retain a run ID and feature contract?
What is a registry alias?
Why does v3 fail the mock registry gate?
What is shadow inference?