MLflow Production Cheat Sheet

MLflow for ML experiment tracking and model deployment — experiment tracking, model registry, project packaging, and serving models in production with MLflow.

Last Updated: May 1, 2025

Experiment Tracking

mlflow.set_experiment('my-experiment')
Create or set active experiment
mlflow.start_run()
Begin a tracked run — all subsequent logging goes here
mlflow.log_params({'lr': 0.001, 'batch_size': 32})
Log hyperparameters — key-value pairs
mlflow.log_metric('accuracy', 0.95, step=epoch)
Log metrics — can log per-step during training
mlflow.log_artifact('model.pkl')
Log files — models, plots, configs
mlflow.autolog()
Auto-log from PyTorch, TensorFlow, sklearn, XGBoost, LightGBM — one line magic
mlflow.end_run()
End the current run

Model Registry

ItemDescription
Register Modelmlflow.register_model(model_uri, name) — promote from experiment to registry
VersioningEach registration creates a new version — immutable, auditable
StagesNone → Staging → Production → Archived. Promote via UI or API.
Stage Transitionsmlflow.transition_model_version_stage(name, version, 'Production')
Aliases'champion'/'challenger' — newer than stages, more flexible. Assign via UI/API.
Model SignatureInput/output schema — enforced at serving time. Add with infer_signature().

MLflow Projects

ItemDescription
MLproject FileDefine environment (conda/docker), entry points, parameters — reproducible runs
mlflow run .Run current project — auto-creates conda env or Docker container
mlflow run -P param=valuePass parameters — overrides MLproject defaults
GitHub Integrationmlflow run [email protected]:user/repo — run projects from Git
Multi-step WorkflowsCompose projects: preprocess → train → evaluate → register

Serving Models

mlflow models serve -m runs:/run-id/model --port 5000
Serve model as REST API locally
mlflow models build-docker -m models:/name/version
Build Docker image for deployment
mlflow deployments create -t sagemaker -m models:/name/1
Deploy to cloud: SageMaker, Azure ML, Databricks
POST /invocations
REST endpoint — send DataFrame JSON, get predictions
--env-manager local
Skip conda — use existing environment (faster, simpler for Docker)
Pro Tip: Log EVERYTHING — parameters, metrics, artifacts, environment. Disk is cheap; the time you spend wondering 'what hyperparameters did I use?' is expensive.