5.3.11 · D4MLOps & Deployment

Exercises — CI - CD pipelines for ML

3,181 words14 min readBack to topic

Before we start, three symbols appear everywhere, so let us define them once in plain words.


Level 1 — Recognition

Recall Solution

This is CT (Continuous Training). It fights model decay from data/concept drift — the world moves even when the code doesn't. See Data & Concept Drift.

Recall Solution

Validate → Train → Evaluate → Register → Deploy → Monitor. Mnemonic: "Very Tired Engineers Rarely Deploy Monsters."

Recall Solution

Data, model, and environment. Same code + different data ⇒ different model. Version data with Data Versioning (DVC), models in a Model Registry, and pin the environment via a Docker image digest.


Level 2 — Application

Recall Solution

Step 1 (WHAT). Plug into . WHY square-root the fraction? Variance of a proportion is ; the spread (in the same units as accuracy) is its square root, so we take to get back to "accuracy points." Step 2 (WHY). says "a random swing of accuracy point is normal here." Step 3. Margin . WHY multiply by 2? Two standard errors ≈ 95% confidence the gain isn't luck (see the boxed rule). A new model must reach at least to be promoted.

Recall Solution

Step 1 (WHAT). Compute the gain: . WHY subtract? The gate only cares about the difference , because a raw high score means nothing unless it beats the incumbent. Step 2 (WHY compare to ). The required margin is — the size below which a difference is indistinguishable from random wobble. Step 3. Since , the gain sits inside the noise floorDo NOT promote. It could easily be luck.

Recall Solution

Step 1 (WHAT). Recompute with the bigger : WHY does shrink? sits in the denominator under the square root, so . Quadrupling (from to ) multiplies by — it halves. Step 2 (WHY it matters). The gain is unchanged at , but the bar dropped to . Step 3. Promote. Lesson (WHAT IT MEANS): the same improvement that was untrustworthy at becomes trustworthy at , purely because more test data shrank the noise floor. Figure s01 below makes this visible.

Figure — CI - CD pipelines for ML
Recall Solution

Step 1 (WHAT). Compare each reading to the threshold . WHY a threshold at all? Some drift is always present (noise). PSI turns "the world moved" into a single number so we can set an objective trigger instead of eyeballing it. Step 2. are all (no trigger); on day 4. Step 3. Day 4 fires the retrain. This kicks off drift-driven retraining, feeding the new candidate into the promotion gate.


Level 3 — Analysis

Recall Solution

The difference in scores now mixes two effects: (1) genuine model-skill difference, and (2) difference in dataset difficulty. You cannot tell them apart. The new "win" might just be an easier test set. Fix: score both models on one identical held-out set so only skill varies. This is the apples-to-apples rule behind the promotion gate.

Recall Solution

The missing gate is the model-evaluation gate that compares the candidate's score against the incumbent's score on a held-out set (both defined in the toolkit above). Unit tests check code correctness; schema validation checks data sanity; the smoke run only checks "does training crash?" None of them measure predictive quality. Statistical failure is invisible to all three. See Model Monitoring for the live counterpart.

Recall Solution

Training/serving skew. The laptop and production environments differ — library versions, preprocessing defaults, hardware numerics — so the same input is transformed differently at serve time. Fix: train inside the same containerized pipeline (pinned image digest) that serves in prod, eliminating the environment gap.

Recall Solution

Step 1 (WHAT). Compute the noise floor once (it depends only on , shared by both): WHY one for both? They share the same and the same test set, so they face the same bar. Step 2 (WHY compare gains). With : X's gain ; Y's gain . Step 3.

  • X: reject (inside noise).
  • Y: promote. X isn't "bad code"; its measured edge is simply statistically indistinguishable from noise. Rejecting it prevents model thrash. This is exactly a significance judgement.

Level 4 — Synthesis

Recall Solution
  1. Trigger: Model Monitoring reports → drift alarm.
  2. Validate: lint, unit tests, data-schema check, tiny smoke train. (Gate 1 — stops on bad code/data.)
  3. Train: full run inside the pipeline container → model artifact.
  4. Evaluate: score the candidate against the incumbent on the same held-out set; require . (Gate 2 — the promotion gate.)
  5. Register: push artifact + metadata to the Model Registry (versioned, so rollback is possible).
  6. Deploy: package with Docker, roll to staging → integration tests (Gate 3) → production via canary.
  7. Monitor: watch live metrics; feeds back to step 1. Loop closed.
Recall Solution

Step 1 (WHAT). Treat the canary window as a test set of points at : WHY use the same formula as offline? A canary is just an online held-out set; the noise of a proportion obeys the identical law. Step 2 (WHY it constrains duration). The canary can trustworthily detect improvements of accuracy points only. If your expected gain is smaller than that, run the canary longer to grow and shrink . Step 3. This is the A/B/significance logic applied to rollout: pick so is below the effect you care about.

Recall Solution

The remaining suspect is the data (the third leg of the code–data–model triangle). Same code + same environment + different data snapshot ⇒ different model. Pin the exact dataset version with Data Versioning (DVC) and record its hash in the Model Registry alongside the artifact. Reproducibility needs all four: code, data, model, environment.


Level 5 — Mastery

Recall Solution

(a) WHAT/WHY. "95% sure" is exactly the rule, so: (b) Gain Promote. It clears the noise floor. (c) WHY solve an inequality. We want the smallest making the floor no bigger than the target gain , i.e. . Solve step by step: WHY square both sides? To remove the square root; the inequality direction is preserved because both sides are positive. So a test set of about lets a -point gain clear the gate. Figure s02 shows the curve crossing the target line right there.

Figure — CI - CD pipelines for ML
Recall Solution

Root cause: the promotion gate has no (or too small) margin , so it deploys on random -point noise — a classic "deploy whenever new beats old" bug. Fix 1: enforce so only real gains pass. Fix 2: add hysteresis / a fixed evaluation cadence and a significance test (e.g. require the gain to hold over multiple evaluations before rollout), plus canary confirmation on live traffic.

Recall Solution
  1. Does the code pass? → unit tests / lint (CI).
  2. Is the data sane? → schema validation (DVC-pinned snapshot).
  3. Did training complete in-pipeline? → containerized run (Docker digest, avoids skew).
  4. Is it meaningfully better? on the same set (Statistical Significance).
  5. Is it stored & rollback-able?Model Registry (versioned artifact + lineage).
  6. Is it safe on live traffic?canary window sized for significance.
  7. Does it stay good?Model Monitoring + drift watch → loops back to trigger.

Recall One-line summary

Every gate on this page reduces to one habit: compare a change against its own noise floor before letting it move down the belt.


Connections