This tutorial demonstrates all four core components of MLflow in a modular, step-by-step approach.
- Python 3.8 or higher
- pip package manager
-
Navigate to the project directory:
cd /home/hammad/mlflow_complete_tutorial -
Install dependencies:
pip install -r requirements.txt
Execute all four components in sequence:
python run_all.pyThis will run:
- Component 1: MLflow Tracking
- Component 2: MLflow Projects
- Component 3: MLflow Models
- Component 4: MLflow Model Registry
Run each component separately to explore in detail:
# Component 1: Experiment Tracking
python 1_tracking.py
# Component 2: Reproducible Projects
python 2_projects.py
# Component 3: Model Packaging
python 3_models.py
# Component 4: Model Registry
python 4_model_registry.pyUse MLflow's project execution:
# Run all components
mlflow run . -e main
# Run specific component
mlflow run . -e tracking
mlflow run . -e projects
mlflow run . -e models
mlflow run . -e registry
# Run with custom parameters
mlflow run . -e projects -P n_estimators=200 -P max_depth=10Open a separate terminal and run:
mlflow uiThen open your browser and visit: http://localhost:5000
-
Experiments Tab: View all experiments and runs
- Compare different runs
- Visualize metrics over time
- Download artifacts
-
Models Tab: Access the Model Registry
- View registered models
- See model versions
- Check model stages (Staging, Production)
File: 1_tracking.py
Demonstrates:
- Creating experiments
- Logging parameters, metrics, and tags
- Logging artifacts (plots, models, files)
- Nested runs for hyperparameter tuning
- Batch logging of metrics over epochs
Duration: ~2-3 minutes
File: 2_projects.py
Demonstrates:
- Project structure with MLproject file
- Parameterized runs
- Running projects programmatically
- Reproducible execution environments
Duration: ~3-4 minutes
File: 3_models.py
Demonstrates:
- Saving models in different flavors (sklearn, PyTorch)
- Model signatures and input examples
- Loading and using saved models
- Custom PyFunc models with preprocessing
- Model metadata and information
Duration: ~2-3 minutes
File: 4_model_registry.py
Demonstrates:
- Registering models
- Model versioning (v1, v2, v3)
- Stage transitions (None → Staging → Production → Archived)
- Model descriptions and tags
- Loading models from registry
- Comparing model versions
- Model aliasing
Duration: ~2-3 minutes
mlflow_complete_tutorial/
├── README.md # Main documentation
├── QUICKSTART.md # This file
├── requirements.txt # Python dependencies
├── .gitignore # Git ignore rules
├── MLproject # MLflow project config
├── python_env.yaml # Python environment spec
├── utils.py # Utility functions
├── data/ # Data directory
│ └── README.md
├── 1_tracking.py # Component 1: Tracking
├── 2_projects.py # Component 2: Projects
├── 3_models.py # Component 3: Models
├── 4_model_registry.py # Component 4: Registry
└── run_all.py # Master script
After running the tutorial, you'll have:
-
MLflow Tracking Server Data (
mlruns/directory)- Multiple experiments
- Dozens of runs with logged parameters and metrics
- Artifacts including plots and models
-
Registered Models (visible in MLflow UI)
- A classification model with 3 versions
- Models in different stages (Staging, Production, Archived)
- Model descriptions and metadata
-
Artifacts
- Confusion matrices
- Feature importance plots
- Training history visualizations
- Classification reports
- Saved model files
# Install dependencies
pip install -r requirements.txt
# Run all tutorials
python run_all.py
# Run individual tutorial
python 1_tracking.py
# Start MLflow UI
mlflow ui
# Start MLflow UI on different port
mlflow ui --port 5001
# Run MLflow project
mlflow run . -e main
# Serve a model
mlflow models serve -m runs:/<RUN_ID>/model -p 5001# Check if MLflow is installed
pip show mlflow
# Try different port
mlflow ui --port 5001# Reinstall dependencies
pip install -r requirements.txt --force-reinstall# Check directory permissions
ls -la mlruns/
# Create directory if missing
mkdir -p mlruns# Install CPU-only version
pip install torch --index-url https://download.pytorch.org/whl/cpu-
Start with Component 1 (Tracking)
- Understand basic logging concepts
- Learn about experiments and runs
- See how to log artifacts
-
Move to Component 2 (Projects)
- Learn about project structure
- Understand parameterization
- See reproducible execution
-
Explore Component 3 (Models)
- Learn model packaging
- Understand model signatures
- Try loading and inference
-
Master Component 4 (Registry)
- Learn model versioning
- Understand lifecycle stages
- Practice model management
After completing this tutorial:
-
Modify the code:
- Change hyperparameters
- Try different datasets
- Add new metrics
-
Integrate with your projects:
- Add MLflow tracking to existing code
- Create MLflow projects for your workflows
- Register your own models
-
Explore advanced features:
- Remote tracking server setup
- Cloud artifact storage (S3, Azure, GCS)
- Model deployment to production
- CI/CD integration
-
Read the documentation:
- Check the main README.md for detailed documentation
- Review individual component files for inline comments
- Visit MLflow documentation: https://mlflow.org/docs/
- Explore MLflow GitHub issues: https://github.com/mlflow/mlflow/issues
This tutorial is provided for educational purposes.
Happy Learning! 🚀