🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

MLOps — Machine Learning Operations Complete Guide

Advanced TopicsMLOps🟢 Free Lesson

ML Engineering

MLOps - From Notebook to Production, Done Right

Master the practices and tools for deploying, monitoring, and maintaining ML models in production.

  • CI/CD for ML - automate model training and deployment
  • Model monitoring - track performance and drift in production
  • Reproducibility - ensure consistent results across environments

Automation is not about replacing humans; it's about augmenting them.

MLOps — Machine Learning Operations

MLOps applies DevOps principles to ML — automating model training, deployment, monitoring, and maintenance.


MLOps Lifecycle

Why the Lifecycle Is a Loop, Not a Line

A notebook is a demonstration rather than a system. It records what somebody typed once, in an environment nobody can rebuild, against data nobody can point at twice. Production models fail for reasons a notebook has no way to see: a schema change upstream, a dependency upgraded by an accidental install, a training script that reads whichever file happens to sit first in a folder that has since been reordered.

The loop in the diagram above is the answer to that fragility. Monitoring does not merely observe the deployed model, it produces the signal that restarts the entire pipeline with fresh data and a new artifact identifier. Each stage hands the next one something addressed and recorded — a validated dataset, a run with its parameters and metrics attached, a registered model version, a rollout that can be reversed without a redeploy.

Teams that treat deployment as the end of the project discover this loop by incident instead of by design. A silent degradation in accuracy surfaces through a customer complaint, a series of quick fixes accumulates on top of a model nobody can reproduce, and the eventual remedy is a rewrite. The lifecycle exists so the same discovery happens as a scheduled and unremarkable event rather than an emergency.

MLOps Lifecycle Diagram

MLOps LifecycleDataCollectionValidationVersioningTrainingExperimentTrackingHyperparameterEvaluationModel MetricsValidationA/B TestingDeploymentContainerizationAPI ServingScalingMonitoringData Drift | Model Drift | LatencyAlerts | Dashboards | Retraining TriggersContinuous feedback loop: monitoring data feeds back to data pipelineCI/CD Pipeline: Code Change → Test → Build → Deploy → Monitor → Iterate

Experiment Tracking

What Actually Needs Recording

Logging three numbers after a training run is the habit most teams begin with, and it is the reason experiments become impossible to compare six months later. A run is only reproducible if you can recover the four things that changed: the code, the data, the configuration, and the environment.

Record the commit hash of the training repository together with the version of the data the run consumed, because re-running against a dataset that has since been appended to produces different numbers from the run you are trying to explain. Log the complete hyperparameter set rather than only the two you were tuning, including defaults you never touched, since an argument with a default is still a difference between runs. Log library versions and the hardware the run used, as a framework upgrade can move a metric without any edit to your own code.

Metrics deserve the same discipline. Validation loss belongs on every epoch instead of only the final score, the metric you will actually be judged on should be computed once on the untouched test split at the end, and artefacts worth comparing — a confusion matrix, a sample of predictions — belong to the run rather than to somebody's Downloads folder.

python
import subprocess
import mlflow

commit = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip()

with mlflow.start_run(run_name="baseline-v1") as run:
    mlflow.set_tag("git_sha", commit)
    mlflow.set_tag("data_version", "orders-2024-06-01")
    mlflow.log_params({
        "learning_rate": 0.001, "batch_size": 32,
        "weight_decay": 0.01, "epochs": 30, "seed": 42,
    })

    for epoch in range(30):
        val_loss = fit_one_epoch(train_loader, val_loader)   # one number per epoch
        mlflow.log_metric("val_loss", val_loss, step=epoch)

    mlflow.sklearn.log_model(model, "model")

mlflow.register_model(f"runs:/{run.info.run_id}/model", "orders-churn")

The registered name at the end is what deployment later points at. Serving orders-churn instead of a path on somebody's disk means the promoted version is a decision that lives in a system, and rolling back is a matter of choosing the previous entry in that system.

CI/CD Pipeline for ML

CI/CD Pipeline for Machine LearningSource CodeGit PushPR/MergeContinuous Integration• Unit tests• Data validation• Model training testContinuous Delivery• Model registry• Staging deploy• A/B test gateProduction• Canary deploy• Shadow mode• Full rolloutMonitor• Drift• Latency• ErrorsFeedback: retrain trigger, drift alerts, performance degradationRetrain Trigger: Drift detected → Pipeline → New model version

Model Monitoring

Three Drift Signals That Are Not the Same Thing

Drift has three distinct meanings, and conflating them is the fastest way to build an alert that nobody reads. Data drift describes the inputs: the distribution of the features the model was trained on has moved. Prediction drift describes the outputs: the model's own scores have shifted, which can happen while inputs look unchanged if an upstream rule starts sending different traffic. Concept drift is the dangerous one: the relationship between inputs and labels has changed, so yesterday's accurate model is quietly wrong today.

None of these is meaningful in isolation. A population stability index above the threshold shown in the dashboard means the inputs moved, not that the model is wrong, and the inputs may have moved because the product improved. Pair each drift signal with an accuracy metric computed on a labelled sample, and let drift open an investigation rather than trigger a retraining job on its own.

Latency and throughput sit apart from all three. They measure the system rather than the model, they degrade for reasons no amount of retraining will fix, and an alert on the ninety-ninth percentile is normally answered by a service engineer rather than a data scientist.

Model Monitoring Dashboard

Production Model Monitoring DashboardData Drift (PSI)⚠️ Drift!0.10.3Model Accuracy0.920.85P99 Latency (ms)45ms52msActive Alerts⚠️ Data drift detected: PSI = 0.28 (threshold: 0.2)⚡ Model accuracy dropping: 92% → 85% over 7 days✓ Latency within SLA: P99 = 52ms (threshold: 100ms)🔄 Retraining triggered: New data available since 2024-01-10

Setting a Retraining Policy

Automatic retraining is attractive and frequently wrong. A pipeline that retrains whenever a drift metric crosses its threshold will cheerfully replace a working model with one fitted to a noisy window of data, and unless the new candidate must beat the incumbent on a held-out evaluation, quality can only wander downward over time.

The safer shape is a policy with two triggers and one gate. Scheduled retraining — weekly or monthly, at a fixed cadence — covers ordinary decay and gives the team a predictable routine to review. Event-driven retraining covers the abnormal cases: a schema change, a major feature launch, a sudden jump in the drift metric. Both routes then pass through the same gate, where the candidate is evaluated against the live model on a recent labelled holdout and promoted only if it wins; otherwise the incumbent stays and the event is recorded for inspection.

Promotion itself should be reversible. A canary rollout to a small slice of traffic, a comparison of both models on the same requests while the slice grows, and a rollback that is a configuration change rather than a redeploy are what separate a release from a gamble.


Common Mistakes & How to Avoid Them

Common Mistakes

Tracking only the final score of a run, so an experiment cannot be reproduced or fairly compared six months later

Fix: Log the commit hash, the data version, the full hyperparameter set and the library versions alongside one metric per epoch

Retraining automatically the moment a drift metric crosses its threshold, replacing a working model with one fitted to noise

Fix: Let drift open an investigation, and require the candidate to beat the incumbent on a recent labelled holdout before promotion

Serving a model from a file path in a training notebook, so nobody knows which version is live or how to return to the previous one

Fix: Register every candidate in a model registry, serve the registered name, and make rollback the selection of an earlier entry

Key Takeaways


What to Learn Next

-> Model Deployment Deploy models to production environments.

-> Feature Stores Manage and serve features efficiently.

-> ML System Design Design scalable ML architectures.

-> Model Evaluation Measure model performance accurately.

-> Model Selection Choose the right model for your problem.

-> AutoML Automate machine learning workflows.

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-17

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Machine Learning Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement