MLOps
Machine Learning Operations: From experimental notebooks to production systems.
What is MLOps?
MLOps (Machine Learning Operations) is a set of practices that combines Machine Learning, DevOps, and Data Engineering to deploy and maintain ML models in production reliably and efficiently. It bridges the gap between data scientists building models and the infrastructure needed to serve them at scale.
π‘ Core Principle: MLOps applies DevOps principles (CI/CD, automation, monitoring) to ML systems, addressing unique challenges like data versioning, model drift, and reproducibility.
Data Science
Experimentation
DevOps
Automation
Data Engineering
Pipelines
π The ML Lifecycle
MLOps manages the entire lifecycle of ML models, from development to retirement.
Data Management
Collection, versioning, validation
Model Development
Training, experimentation
Deployment
CI/CD, serving
Monitoring
Performance, drift
π§© Key Components
π¦ Data Versioning
Track changes in datasets over time. Essential for reproducibility and debugging.
π§ͺ Experiment Tracking
Log hyperparameters, metrics, artifacts, and code versions for every training run.
π Model Registry
Central repository for model versions with metadata, lineage, and stage transitions (staging β production).
π§ Feature Store
Centralized repository for feature definitions, ensuring consistency between training and serving.
π CI/CD for Machine Learning
ML pipelines require additional CI/CD considerations beyond traditional software.
| Pipeline Type | Trigger | Actions |
|---|---|---|
| CI (Continuous Integration) | Code push | Lint, unit tests, data validation tests |
| CT (Continuous Training) | New data, schedule, drift detected | Retrain model, evaluate, register |
| CD (Continuous Deployment) | New model registered & approved | Canary/Blue-Green deploy, A/B test |
# Example: GitHub Actions for ML Pipeline
name: ML Pipeline
on:
push:
branches: [main]
schedule:
- cron: '0 0 * * 0' # Weekly retraining
jobs:
train:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run data validation
run: python src/validate_data.py
- name: Train model
run: python src/train.py
env:
MLFLOW_TRACKING_URI: ${{ secrets.MLFLOW_URI }}
- name: Evaluate model
run: python src/evaluate.py
- name: Register model (if passed)
run: python src/register_model.py
π Model Serving Patterns
Different strategies for serving predictions based on latency, scale, and use case.
π Real-time (Online)
REST/gRPC APIs for instant predictions. Low latency (<100ms).
- Fraud detection
- Recommendation on click
- Chatbots
π¦ Batch
Scheduled jobs processing large datasets. Higher throughput.
- Daily churn predictions
- Monthly risk scores
- Batch recommendations
π± Edge / Embedded
Models running on devices (mobile, IoT). Offline capable.
- Mobile keyboard predictions
- Camera apps (face detection)
- Smart home devices
π Streaming
Process events as they arrive in real-time streams.
- IoT sensor anomaly detection
- Real-time clickstream analysis
- Live event scoring
π Monitoring & Observability
ML systems require monitoring beyond traditional application metrics.
π¨ Model Drift
The phenomenon where model performance degrades over time due to changes in real-world data.
Input distribution changes
Relationship between X and Y changes
| Metric Type | What to Monitor | Tools |
|---|---|---|
| Infrastructure | Latency, throughput, CPU/GPU, memory | Prometheus, Grafana, Datadog |
| Data Quality | Missing values, schema changes, distribution | Great Expectations, Evidently |
| Model Performance | Accuracy, precision, recall, AUC | MLflow, W&B, Evidently |
| Business Metrics | Revenue impact, conversion rate, user engagement | Custom dashboards, A/B testing platforms |
π― Deployment Strategies
π΅π’ Blue-Green
Run two identical environments. Switch traffic instantly from old (blue) to new (green).
β Zero downtime, easy rollback
π€ Canary
Route a small % of traffic (1-5%) to the new model. Gradually increase if metrics are good.
β Low risk, real-world validation
π °οΈπ ±οΈ A/B Testing
Split traffic between models and measure business metrics to determine the winner.
β Data-driven decisions
π MLOps Maturity Levels
Google's MLOps maturity model (from their MLOps whitepaper):
Manual Process
Manual training, manual deployment, Jupyter notebooks
ML Pipeline Automation
Automated training pipeline, manual deployment
CI/CD Pipeline Automation
Fully automated training + deployment, triggered by data/code changes, monitoring
π οΈ Popular MLOps Platforms
| Platform | Type | Strengths |
|---|---|---|
| Vertex AI | Cloud (GCP) | End-to-end, AutoML, integrated with GCP |
| SageMaker | Cloud (AWS) | Full lifecycle, Autopilot, AWS ecosystem |
| Azure ML | Cloud (Azure) | Designer UI, enterprise integration |
| MLflow | Open Source | Experiment tracking, model registry, flexible |
| Kubeflow | Open Source (K8s) | Kubernetes-native, scalable pipelines |
| ZenML | Open Source | Portable pipelines, integrates many tools |