Version everything - models, data, code, and configs. Manage ML models like production artifacts.
A Model Registry is a centralized catalog that stores, versions, and manages ML model lifecycles. Think of it as Docker Registry + deployment pipeline for ML models.
import mlflow
# Register after training
with mlflow.start_run():
mlflow.sklearn.log_model(model, "model",
registered_model_name="churn_predictor")from mlflow import MlflowClient
client = MlflowClient()
# Promote to Staging
client.transition_model_version_stage(
name="churn_predictor", version=3, stage="Staging")
# After validation, promote to Production
client.transition_model_version_stage(
name="churn_predictor", version=3, stage="Production")
# Load production model
model = mlflow.pyfunc.load_model("models:/churn_predictor/Production")def validate_for_production(model_name, version):
client = MlflowClient()
mv = client.get_model_version(model_name, version)
run = client.get_run(mv.run_id)
accuracy = run.data.metrics.get("accuracy", 0)
f1 = run.data.metrics.get("f1", 0)
checks = [
("accuracy >= 0.85", accuracy >= 0.85),
("f1 >= 0.80", f1 >= 0.80),
]
# Compare with current production
prod = client.get_latest_versions(model_name, ["Production"])
if prod:
prod_f1 = client.get_run(prod[0].run_id).data.metrics.get("f1", 0)
checks.append(("better than prod", f1 > prod_f1))
all_pass = all(p for _, p in checks)
for name, passed in checks:
print(f" {'PASS' if passed else 'FAIL'}: {name}")
if all_pass:
client.transition_model_version_stage(
model_name, version, "Production")
return all_pass# Initialize DVC
git init && dvc init
# Track large dataset
dvc add data/customer_data.parquet
git add data/customer_data.parquet.dvc
git commit -m "Add training data v1"
# Push to remote storage
dvc remote add -d myremote s3://bucket/dvc-store
dvc push
# Switch to previous data version
git checkout v1.0
dvc checkout| What | Tool | Your Familiarity |
|---|---|---|
| Code | Git | You know this! |
| Data | DVC / LakeFS | Git-like for data |
| Models | MLflow / W&B | New skill |
| Pipelines | ZenML config | New skill |
| Environment | Docker | You know this! |