By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
CI/CD for ML (sometimes called MLOps) is the practice of automatically building, testing, version‑controlling, and deploying machine‑learning code and models. It turns a manual “train‑then‑hand‑off” workflow into a repeatable pipeline so that new data, code changes, or model improvements can be pushed to production with the same confidence you have for a web‑app release.
Real‑world example: A telecom company predicts customer churn daily. Every night a pipeline pulls the latest usage logs, retrains a Gradient‑Boosted Tree, runs a suite of validation tests, registers the new model, and rolls it out to the scoring service without a human touching the code.
main
extract → transform → train → evaluate → register
[ \text{PSI} = \sum_{i=1}^{k} (p_i - q_i) \cdot \ln!\left(\frac{p_i}{q_i}\right) ]
where (p_i) = proportion of feature values in reference data, (q_i) = proportion in current data. PSI > 0.2 signals significant drift. - ML‑specific Unit Test – Assert that a model’s AUC‑ROC on a hold‑out set stays above a threshold (e.g., assert auc > 0.78). - Versioned Data Artifacts – Store raw, cleaned, and feature‑engineered datasets with immutable hashes (e.g., DVC dvc add data/train.parquet). - Infrastructure as Code (IaC) – Declare compute resources (Dockerfile, Terraform) so the same environment runs locally and in CI. - Rollback Strategy – Keep the previous model version ID; on failure, mlflow models revert <prev_version> restores service instantly.
assert auc > 0.78
dvc add data/train.parquet
mlflow models revert <prev_version>
git init
requirements.txt
Dockerfile
Makefile
pytest
flake8
python @dag(schedule_interval='@daily') def churn_pipeline(): raw = extract() clean = transform(raw) model = train(clean) eval = evaluate(model, clean) register_if_ok(eval, model)
assert isinstance(df, pd.DataFrame)
train
np.mean(y_pred == y_true)
assert roc_auc_score(y_test, prob) > 0.80
model.pkl
PSI
Mistake: Skipping data versioning – treating raw CSVs as mutable. Correction: Use DVC or Git‑LFS to lock each dataset with a hash; this guarantees reproducibility when a model is rebuilt.
Mistake: Testing only on training data (e.g., model.score(X_train, y_train)). Correction: Reserve a hold‑out or cross‑validation set that the CI pipeline evaluates; training‑set metrics are optimistic.
model.score(X_train, y_train)
Mistake: Hard‑coding paths or credentials inside the pipeline code. Correction: Pull configuration from environment variables or a secret manager (e.g., os.getenv("S3_BUCKET")).
os.getenv("S3_BUCKET")
Mistake: Deploying a model that passes offline tests but never monitors live performance. Correction: Add a post‑deployment monitor (A/B test, drift alerts) as part of the CD stage; auto‑rollback if live KPI degrades.
Mistake: Using a single large Docker image for all steps, leading to long build times. Correction: Split the pipeline into lightweight stages (e.g., separate builder and runtime images) and cache layers in CI to speed up builds.
builder
runtime
Scenario: Your nightly CI run fails because mlflow.log_metric("auc", auc) raises a ValueError. Answer: The failure is likely due to logging a metric before the run is started; wrap logging inside with mlflow.start_run(): ….
mlflow.log_metric("auc", auc)
ValueError
with mlflow.start_run(): …
Scenario: After a canary rollout, the latency spikes from 30 ms to 120 ms. Answer: Trigger an automatic rollback to the previous model version and investigate whether the new model introduced heavier preprocessing (e.g., high‑dimensional embeddings).
None → Staging → Production → Archived
COPY . /app && pip install -r /app/requirements.txt
mlflow models revert -v <prev_version>
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.