MLOps Foundations
Intermediate 15 min read MLOps Foundations

CI/CD for ML

A model isn't code; its pipeline must still behave like CI

CI/CD for ML automates the path from commit to registered model: linting and data tests on pull, training/evaluation gates on merge, and a deploy that is a registry promotion — plus continuous training for the data that keeps changing.

CICDpipelinemodel gatecontinuous trainingregisterpromotionbacktest
Before we start

What you will learn

  • Design CI stages for ML: code checks, data checks, train+evaluate
  • Explain CT (continuous training) and its trigger rules
  • Gate promotions on automated evidence, not vibes
Introduction

What is this?

CI/CD for ML automates every step between a code commit and a registered, deployable model. CI validates code (lint, unit tests), data (schema, distributions, leakage checks) and a smoke training run with evaluation thresholds. CD promotes the artifact through the registry — staging to production with gates. Because data drifts, many teams add CT: continuous training that re-runs the pipeline on a schedule or a drift trigger, so 'latest' is never silently stale.

Motivation

Why do you need it?

  • Models fail on data, not just code; CI must test the data and the train-evaluate path, not only the syntax.
  • Automated gates replace 'trust me, the notebook worked' with reproducible evidence.
  • Faster, safer cadence: small changes shipped often instead of one giant risky retrain.
  • CT keeps a deployed model honest when the distribution moves slowly.
Think about it

Mental model

Imagine

A car assembly line with inspection stations

Think of

ML CI/CD

Every car passes inspection before it rolls off (CI). New parts are tested in prototype (staging + shadow). If a batch of steel arrives different (data drift), the line doesn't keep stamping old tolerances — it recalibrates (CT) and every new car is re-inspected against updated specs.

Mechanics

How it works

  • CI stage 1 (code): lint, type-check, unit tests on feature/model code.
  • CI stage 2 (data): schema validation, range/stat checks, leakage and label-quality tests on the frozen dataset version.
  • CI stage 3 (train & eval): smoke training run; compare holdout metrics to a registered baseline; gate passes/fails.
  • CD: on green, register the artifact and promote through registry stages (staging → production) with approval.
  • CT: a scheduled or drift-triggered job re-runs the train-eval pipeline and opens a candidate when thresholds improve.

A model CI/CD pipeline.

Commit
Code checks
Data checks
Train & eval
Register
Promote
Real world

In production

  • A fraud team's PR runs a 5-minute evaluation on a fixed sample; PRs that beat the registered decision-point AUC by 0.01 are auto-promotable.
  • A recommender ships every Tuesday using the same pipeline that ran last Tuesday — identical stages, new data, comparable gates.
  • A churn model retrains quarterly and on drift triggers, always backtesting before registry promotion.
Guidelines

Best practices

  • Fix the evaluation protocol (dataset, split, metrics) so gates compare apples to apples across candidates.
  • Run data checks BEFORE the (expensive) training stage — fail cheaply.
  • Gate promotion also on non-metric signals: schema compatibility, latency budget, calibration.
  • Keep the CI dataset representative of production; a stale 'golden' set decays in value.
  • Make retraining (CT) reuse the same pipeline as interactive training — one code path.
Watch out

Common mistakes

  • CI that only lints code — the model-quality gate is where actual value is checked.
  • Comparing candidates against a moving baseline without a frozen reference run.
  • Re-training on every commit (expensive, noisy) instead of on meaningful change or drift.
  • Gate thresholds tuned to pass today instead of protecting against regressions tomorrow.
Root cause analysis

Common issues

Error
CI passes locally, fails on every commit
Root cause

Loose environment (not the pinned image) or CI dataset differs from local

Fix

Run CI in the pinned training image and make the CI dataset a fixed immutable snapshot.

Error
Gate randomly toggles green/red on no code change
Root cause

Data or label pipeline nondeterminism between runs

Fix

Freeze the dataset for the gate and seed everything; codify a 'golden set' refresh process.

Error
CT retrains too often, wasting GPU
Root cause

Trigger threshold too sensitive or drift monitor noisy

Fix

Add hysteresis (degrade before retrain), require consecutive breach windows, and cap cadence.

When things break

Debugging tips

  • When CI fails training but passes locally, check commit-vs-data pairing and dependency changes first.
  • A gate that suddenly flips red often means the CI dataset or label definition changed silently.
  • Keep baseline reference runs as artifacts; use them to diff candidate metrics precisely.
  • Log the exact commit + dataset + seed per CI run; irreproducible CI ever is worse than no CI.
Interviews

Interview checkpoint

Practice

Hands-on lab

Build a Two-Gate Model CI Pipeline
30 min · intermediate
In progress
Objectives
  • Simulate a CI pipeline as shell stages: code check, data check, train+eval gate
  • Gate registration on a holdout metric threshold
  • See a failing data check stop the pipeline before training

Build a Two-Gate Model CI Pipeline

30 min · intermediate

0/5 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

Which CI stage catches train/serve skew before a model ships?

2

CT (continuous training) should auto-promote every retrained model without gates.

Go deeper

Official documentation