Foundations to Frontier
Tests

CI/CD for Machine Learning

Continuous integration and continuous delivery (CI/CD) make every change go through the same automated path: build, test, evaluate, release gradually, and roll back if something goes wrong. For machine learning the tests must include the model itself: a candidate trained from a new commit is compared with the production model on an evaluation set, and then on live traffic in a canary. The exercises model commits whose true effect on accuracy is unknown (most neutral, some improvements, some bugs, a third of them visible only in production), build a non-inferiority gate from paired comparisons and a canary test, and run a year of commits through four release strategies. Practice problems cover the gate's operating characteristic, inflated dashboards, flaky tests, canary power, and releasing in bundles.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Quality control on an assembly line

A factory checks every part before it leaves: some faults show up on the test bench, others only when the part is used. So it tests a few finished products with real customers before shipping thousands. Software teams work the same way: every change is tested automatically, then released to a small share of users, then to everyone. With machine learning the hard part is that a change can make a model a little worse without breaking anything, and a small test set cannot tell a little worse from luck.

🎮 MLOps lab
deploy every commit
27 harmful deployed · 189 days of exposure
gate, 2,000 examples
13 harmful deployed · 91 days of exposure
gate, 20,000 examples
8 harmful deployed · 56 days of exposure
gate, 20,000 + 1-day canary
1 harmful deployed · 7.35 days of exposure

The gate accepts 32.0% of changes with true effect −2 points, 81.7% of changes with true effect −1 points, 96.0% of changes with true effect −0.5 points, 99.5% of changes with true effect 0 points, 99.7% of changes with true effect +0.2 points.

N3-4, seed 0. A harmful change that reaches everyone is found by monitoring after 7 days. A large offline evaluation set stops every bug it can see; bugs that appear only in serving need a canary on live traffic.

Why engineers care

In Exercise 2, deploying every commit exposed users to harmful models for 189 full-traffic days in a year; a gate on 20,000 evaluation examples cut that to 56, and adding a one-day canary cut it to 7.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Continuous integration means…
  2. 2. A canary release…
  3. 3. An ML change can be harmful without any test failing because…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Continuous integration (CI): every commit triggers builds and tests: unit tests, data validation (topic N1-2), training on a sample, and model evaluation.
  • Continuous delivery / deployment (CD): a passing build becomes a release candidate that is deployed automatically or with one approval.
  • Model quality gate: an automated comparison of candidate and production on a fixed evaluation set; non-inferiority gates allow a small margin, superiority gates require significant improvement.
  • Canary and shadow releases: the candidate serves a small share of live traffic (canary) or scores it without affecting users (shadow, topic N2-2).
  • Rollback: switching back to the previous version, ideally automatically when monitors fire.
  • Flaky tests: tests that fail spuriously; they erode trust in CI.
  • Continuous training (CT): pipelines that retrain on new data and pass the result through the same gates (topic N4-2).
  • Tools: GitHub Actions, GitLab CI, Jenkins, Argo CD, Kubeflow and SageMaker Pipelines, MLflow.
📝 Quick check (Level 1)
0/3 answered
  1. 1. A non-inferiority gate accepts a candidate unless it is…
  2. 2. A flaky test…
  3. 3. Continuous training means…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

A gate and a canary

Exercise 1.

  • Commits: 70% neutral (effect sd 0.1 point), 20% improvements (mean 0.15 point), 10% bugs (about −3 points); a third of bugs appear only online (serving skew).
  • Gate: paired comparison on n evaluation examples where the models disagree on 8% plus the effect; accept if measured + 1.645 se exceeds −0.5 point.
  • Canary: 5,000 labelled live requests on each model for a day; roll back if the candidate is worse by more than 2 standard errors.
  • A harmful change that reaches everyone is found by monitoring after 7 days.

Practice.

  • Gate every model on a large, fixed evaluation set with paired comparisons and an explicit margin.
  • Test the serving path: canaries or shadow traffic catch what offline evaluation cannot.
  • Size canaries for the regressions that matter, and roll back automatically.
  • Keep releases small and frequent, and fix or quarantine flaky tests.
  • Do not sum measured wins; re-measure the production model on fresh data.
def paired_eval(delta, n, rng, disagree=0.08):
    dis = disagree + abs(delta)
    c = rng.binomial(n, (dis + delta) / 2)   # only candidate right
    b = rng.binomial(n, (dis - delta) / 2)   # only production right
    return (c - b) / n, np.sqrt(c + b) / n

def gate(measured, se, margin=0.005, z=1.645):
    return measured + z * se > -margin
🐍 Exercise 1: commits, a quality gate and a canary
Model commits with unknown effects, build a paired non-inferiority gate and a canary test, and measure how often each accepts changes of different sizes.
📝 Quick check (Level 2)
0/3 answered
  1. 1. A larger evaluation set makes the gate…
  2. 2. Bugs that appear only in serving are caught by…
  3. 3. Re-running failing tests once…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Paired comparisons. On n shared examples, with b examples only production gets right and c only the candidate, the measured difference is (c − b)/n with variance (p_b + p_c − (p_c − p_b)²)/n, estimated by (b + c)/n². Its standard error shrinks like 1/√n and grows with the disagreement between models, not with the accuracy itself.

What a gate decides. The non-inferiority rule accepts when measured + z·se > −m. A candidate exactly at the margin passes with probability Φ(z) ≈ 0.95; one at −m − 2z·se passes about 5% of the time. With 2,000 examples se ≈ 0.6 point, so a 1-point regression passes 82% of the time; with 20,000, 24%. Requiring significant improvement instead blocks most real improvements of a fraction of a point.

Canary power. Comparing accuracies p + δ and p on n requests each, the test rejects with probability about Φ(|δ|/√(2p(1 − p)/n) − z). For p = 0.85, n = 5,000 and δ = −1 point that is about 27%: catching small regressions needs tens of thousands of labelled requests.

Flaky suites. If each of m tests fails spuriously with probability f and failures are re-run r times, a correct commit passes with probability (1 − f^(r+1))^m: 0.998^1000 ≈ 0.14, but one re-run gives 0.996.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The standard error of a paired difference grows with…
  2. 2. A non-inferiority gate accepts a candidate exactly at the margin with probability about…
  3. 3. Canary power grows with…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Which release process keeps harmful model changes away from users: no checks, an offline gate, or a gate plus a canary?

History.

  • G. Booch (1991) coined continuous integration; Extreme Programming (K. Beck, 1999) made it a daily practice, and J. Humble and D. Farley’s Continuous Delivery (2010) described deployment pipelines.
  • Canary releases became standard at large web companies in the 2000s; Google’s Site Reliability Engineering (2016) described automated canary analysis.
  • D. Sculley and colleagues (2015) and E. Breck and colleagues (2017, the ML Test Score) listed the tests ML systems need; Google’s TFX (D. Baylor and colleagues, 2017) built model validation into the pipeline, and “MLOps” levels of automation (Google, 2020) made CI/CD/CT a common vocabulary.

Exercise 2.

  • 250 commits in a year through four strategies: deploy everything; a gate on 2,000 or on 20,000 evaluation examples; the larger gate followed by a one-day canary (5% of traffic).
  • Harmful: true online effect below −0.5 point. Exposure counts 7 days at full traffic for each harmful change that reaches everyone and 0.05 day for each harmful canary.

Seed 0 (27 harmful commits, 8 of them only online; 63 improvements):

strategy harmful changes reaching everyone improvements blocked gain over the year harmful exposure (full-traffic days)
deploy every commit 27 0 7.50 points 189
gate, 2,000 examples 13 1 7.49 points 91
gate, 20,000 examples 8 0 7.50 points 56
gate, 20,000 + 1-day canary 1 0 7.41 points 7.35

Seeds 1 and 2 (21 and 20 harmful, 8 and 9 only online): 21 and 20 harmful changes reached everyone without checks, 9 and 11 through the small gate, 8 and 9 through the large gate (exactly the online-only bugs), and 1 and 2 with the canary; exposure 147 and 140, 63 and 77, 56 and 63, 7.4 and 14.45 days.

Findings.

  • A gate on 20,000 examples stopped every bug visible offline in every seed; what got through were exactly the bugs that appear only in serving.
  • A one-day canary caught most of those, cutting exposure to harmful models by 77 to 87% relative to the large gate alone, at the cost of 5% of one day’s traffic per harmful candidate.
  • The year’s accuracy gain was the same under every strategy (5.7 to 7.5 points by seed), because harmful changes were rolled back eventually: the gates protect users during the year, not the end result.
🐍 Exercise 2 (research): which release process keeps harmful model changes away from users: no checks, an offline gate, or a gate plus a canary?
Run a year of commits through four release strategies and compare harmful deployments and user exposure.

CI/CD for machine learning in practice

  • Pipelines in GitHub Actions or GitLab CI run unit tests, data validation, a small training run and evaluation on every pull request; full retraining and evaluation run on merge, and Argo CD or a platform pipeline deploys the result.
  • Model gates compare against the production model on fixed and recent evaluation sets, slices (topic N4-1) and fairness metrics, with thresholds agreed in advance.
  • Progressive delivery (Argo Rollouts, Flagger, SageMaker deployment guardrails) automates canaries, metric analysis and rollback.
  • Flight software and spacecraft models follow the same idea more strictly: every change runs through simulation and hardware-in-the-loop test campaigns before upload, and the previous version stays on board for fallback.

References

  1. G. Booch (1991). “Object Oriented Design with Applications.” Benjamin/Cummings.
  2. J. Humble and D. Farley (2010). “Continuous Delivery.” Addison-Wesley.
  3. B. Beyer, C. Jones, J. Petoff and N. R. Murphy, eds. (2016). “Site Reliability Engineering.” O’Reilly.
  4. E. Breck, S. Cai, E. Nielsen, M. Salib and D. Sculley (2017). “The ML test score: a rubric for ML production readiness and technical debt reduction.” IEEE Big Data.
  5. D. Baylor and colleagues (2017). “TFX: a TensorFlow-based production-scale machine learning platform.” KDD.
  6. Q. Luo, F. Hariri, L. Eloussi and D. Marinov (2014). “An empirical analysis of flaky tests.” FSE.