Lesson 4 of 6 The ML Development Lifecycle and MLOps

Operating Models Reliably with MLOps

This lesson explains how MLOps applies DevOps practices, such as automation, versioning, testing and monitoring, to machine learning, so models can be built, deployed and maintained reliably.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain why machine learning systems need MLOps.
  • Identify the AWS services that provide the building blocks of MLOps, such as SageMaker Pipelines and the Model Registry.
  • Describe the requirements a model must meet before production.
  • Distinguish data drift, model quality drift, bias drift and feature attribution drift.

Why ML needs MLOps

ML systems depend on code, data and models, all of which change. A model accurate at launch can degrade as behaviour or data sources change. MLOps turns the lifecycle into a repeatable process instead of manual notebook steps.

MLOps building blocks on AWS

MLOps applies software engineering discipline to machine learning, so that models are built, released and maintained reliably rather than by hand. Experiment tracking records the data version, code, hyperparameters and results of each training run, so the best model can be identified and reproduced; SageMaker AI provides managed MLflow for this. Repeatable pipelines, built with SageMaker Pipelines, run the steps of preparing data, training, evaluating and registering a model automatically, the same way each time.

The SageMaker Model Registry stores each model version with its approval status, so only approved models reach production. SageMaker Model Monitor watches deployed models for problems. The following table summarises the building blocks.

PracticeAWS service
Experiment tracking: record data version, code, hyperparameters and metricsSageMaker AI with managed MLflow
Repeatable pipelines: prepare, train, evaluate, registerSageMaker Pipelines
Versioning and approval of modelsSageMaker Model Registry
Monitoring deployed modelsSageMaker Model Monitor

CI/CD for ML uses Model Registry approvals to promote models from development through staging to production, with automated tests and rollback.

The following diagram shows the building blocks as a loop.

The MLOps loop on AWS. New data or new code starts a SageMaker Pipelines run that prepares data, trains, evaluates and registers the model, with experiments tracked in managed MLflow. The SageMaker Model Registry holds each version with its approval status, so only approved models are deployed. SageMaker Model Monitor watches the deployed model for drift, and a drop in quality triggers retraining.
Automation makes training and release repeatable.
Match the pairs

MLOps on AWS

Exam skills 1.3.4 · 1.3.5

Match each MLOps need with the SageMaker AI capability that meets it.

Log in to try this activity Interactive activities are free with an account.

Production readiness

A model that performs well in development must also meet further requirements before it is used in production. The following list describes these requirements.

  • Scalability (auto scaling endpoints), security (IAM, encryption, VPCs), cost, testing and documentation (Model Cards) must all be addressed.
  • Technical debt, such as undocumented features, hidden data dependencies and manual steps, makes ML systems fragile.
Select all that apply

Technical debt

Exam skills 1.3.5

A churn model has been in production for a year. Select the findings that are technical debt.

Log in to try this activity Interactive activities are free with an account.

Monitoring for drift

A model that performed well at launch can become less accurate as the world changes, which is called drift. Data drift means the inputs no longer resemble the training data, for example when customers start buying different products. Model quality drift means accuracy, measured against the real outcomes once they are known, has fallen. Bias drift means predictions have become less fair to some groups over time. Feature attribution drift means different input features have started to drive the predictions, which can signal a problem even before accuracy falls. The following table summarises the four types.

DriftMeaning
Data driftInput data no longer resembles the training data
Model quality driftAccuracy falls against ground truth
Bias driftPredictions become less fair over time
Feature attribution driftDifferent features start driving predictions

Model Monitor runs these checks on a schedule, publishes CloudWatch metrics and alerts, and detected drift can trigger a retraining pipeline automatically.

Sort into groups

Which kind of drift?

Exam skills 1.3.5

Name the kind of drift that each monitoring finding shows.

Log in to try this activity Interactive activities are free with an account.
Worked example

From notebook to an automated pipeline

A data scientist built a successful pricing model in a notebook. Six months later nobody can reproduce it, and its accuracy has fallen. The team rebuilds the process with MLOps:

ProblemMLOps practiceAWS service
Nobody knows which data and settings produced the modelExperiment trackingSageMaker AI with managed MLflow
Training is a series of manual notebook stepsAn automated, repeatable pipelineSageMaker Pipelines
Models go to production without reviewVersioning and approvalSageMaker Model Registry
Falling accuracy was noticed by customers firstMonitoring with alertsSageMaker Model Monitor and CloudWatch
Retraining is forgottenAutomatic retraining when drift is detectedPipeline triggered by a Model Monitor alert

The result is a loop: new data arrives, the pipeline retrains and evaluates the model, an approver promotes it in the registry, it is deployed, and monitoring decides when the next retraining is due.

Check yourself

What is model drift, and how is it handled?

Show answer

A fall in model quality because live data, or the relationships in it, change from what the model was trained on. It is found by monitoring, for example with SageMaker Model Monitor, and fixed by retraining.

Exam Tips

Remember for the exam

  • To automate and orchestrate ML workflows, use SageMaker Pipelines.
  • To version models and manage approvals, use the SageMaker Model Registry.
  • To track and compare experiments, use SageMaker AI with MLflow.
  • To detect data, quality or bias drift in production, use SageMaker Model Monitor.
  • When drift is detected, retrain the model with recent data.