5.3.11MLOps & Deployment

CI - CD pipelines for ML

1,948 words9 min readdifficulty · medium6 backlinks

WHAT are the pieces?


HOW the pipeline flows

Figure — CI - CD pipelines for ML

The stages, in order:

  1. Trigger — a git push, a schedule (cron), or a drift alarm.
  2. CI: validate — lint code, run unit tests, validate data schema (are columns/types/ranges sane?), run a tiny training run to catch crashes.
  3. Train — full training on the pipeline (not a laptop), producing a model artifact.
  4. Evaluate (gate) — compute metrics on a held-out set; compare to the current production model.
  5. Register — if it passes, push the artifact + metadata to a model registry (versioned).
  6. CD: deploy — package (Docker), roll out to staging, run integration tests, then production.
  7. Monitor — watch live metrics; drift/degradation feeds back to the Trigger → loop closes.

Worked examples


Common mistakes


Recall Feynman: explain to a 12-year-old

Imagine a toy factory with a conveyor belt. Every new toy design (code), new batch of plastic (data), and finished toy (model) rides the belt. At each checkpoint a robot inspector checks: Is the design safe? Is the plastic clean? Does the toy actually work better than the one in the shops? Only toys that pass every checkpoint get boxed and sent to stores. And a special sensor watches the shops — if kids stop liking the toy, it rings a bell that starts building a new one automatically. The belt + inspectors + bell together are the ML CI/CD pipeline.


Active recall

What three things change independently in an ML system (unlike normal software)?
Code, data, and model.
What does CT (Continuous Training) add beyond CI/CD?
Automatic retraining triggered by new data or performance drift, to fight model decay.
Why must the promotion gate use the same held-out test set for old and new models?
So the score difference reflects model skill, not differences in the evaluation data.
Why require a margin δ\delta instead of promoting on any improvement?
Metrics are noisy; a small gain can be random luck. δ\delta ensures the improvement exceeds the noise floor.
Give the rule-of-thumb formula for a safe promotion margin on accuracy.
δ2p(1p)/n\delta \gtrsim 2\sqrt{p(1-p)/n} (≈ two standard errors).
What is training/serving skew and how does CI/CD prevent it?
When training and production environments differ, giving different behaviour; prevented by training inside the same containerized pipeline used in prod.
Name the six ordered pipeline stages.
Validate, Train, Evaluate, Register, Deploy, Monitor.
What is a model registry?
A versioned store of trained model artifacts plus metadata (metrics, data version, lineage) used for promotion and rollback.
Which metric commonly triggers a CT retrain, and a rough threshold?
Population Stability Index (PSI); PSI > 0.2 signals significant drift.
Why isn't "all tests pass" enough to ship an ML model?
Tests catch code bugs but not statistical failure; you also need a metric-based evaluation gate.

Connections

  • Model Registry — where the Register stage stores versioned artifacts.
  • Data Versioning (DVC) — versioning the "data" leg of the triangle.
  • Data & Concept Drift — what triggers CT.
  • Model Monitoring — the feedback loop closing the pipeline.
  • Docker & Containerization — packaging to avoid training/serving skew.
  • A-B Testing & Canary Deployment — safer rollout strategies at the Deploy stage.
  • Statistical Significance — justifies the promotion margin δ\delta.

Concept Map

starts

lint, unit tests, data schema

produces

compare s_new vs s_prod

passes

CD deploy

watch live metrics

drift feeds back

motivates

auto-retrain triggers

Trigger: push, cron or drift alarm

CI: validate

Train full run

Model artifact

Evaluate gate

promote if s_new >= s_prod + delta

Register in model registry

Package Docker, staging to production

Monitor

Data / concept drift

CT: Continuous Training

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, normal software me sirf code change hota hai. Par ML me teen cheezein alag-alag change hoti hain: code, data, aur model. Isliye ML ka CI/CD ek automatic assembly line jaisa hai — jaise hi koi change aaye (naya git push, fresh data, ya drift alarm), pipeline usko test karti hui production tak le jaati hai. Har stage pe ek "gate" hota hai jahan check hota hai — code sahi hai? data ka schema theek hai? model production wale se behtar hai? Agar koi bhi check fail, toh pipeline waheen ruk jaati hai, aur ganda model users tak nahi pahunchta.

Sabse important ML-specific cheez hai CT (Continuous Training). Kyunki model apne aap "sadta" (decay) hai — duniya badalti hai, users ka behaviour badalta hai, isliye purana model galat hone lagta hai. Isko drift kehte hain (PSI > 0.2 ek common signal hai). Jab drift detect hota hai, CT trigger hota hai aur model automatically retrain hota hai. Yeh feedback loop hi pipeline ko "zinda" rakhti hai.

Ek key idea yaad rakho: model deploy tabhi karo jab naya model production wale se sirf thoda nahi, balki noise se zyada behtar ho. Formula: δ2p(1p)/n\delta \gtrsim 2\sqrt{p(1-p)/n}. Iska matlab — agar test data bada hai (nn zyada), toh chhote improvement pe bhi bharosa kar sakte ho; agar test data chhota hai, toh bada improvement chahiye. Isse random luck wale "improvement" pe model baar-baar change nahi hota.

Aur ek galti se bacho: "tests pass ho gaye matlab model achha hai" — yeh galat hai. Tests sirf code bugs pakadte hain, statistical failure (accurate code par bekaar model) nahi. Isliye ek alag evaluation gate zaroori hai. Saath hi, model laptop pe nahi, wahi Docker container ke andar train karo jo production me chalega — warna training/serving skew ho jayega.

Go deeper — visual, from zero

Test yourself — MLOps & Deployment

Connections