MLflow tutorial: GenAI tracking and Python MLOps setup

Learn to set up MLflow on localhost:5000, trace API calls, evaluate responses, version prompts, and track scikit-learn and PyTorch training.

Player not loading? Watch on YouTube

This MLflow crash course covers a self-hosted tracking server and Python workflows for GenAI applications and conventional machine learning. The presenter assumes familiarity with Python and the libraries used in the examples. Setup uses uv, with pip as an alternative, and keeps the MLflow server running in a separate terminal. Python scripts connect to localhost:5000.

The GenAI examples call OpenAI and Mistral APIs with credentials loaded from a .env file. The local server does not make these examples offline. Autologging records requests and responses, with token counts and latency visible in the dashboard. Evaluation combines a correctness scorer, an English-language guideline, and a custom rule allowing at most five words. The demonstrated answers pass correctness and English checks but fail the length rule.

Prompt templates use variables and numbered versions that Python can load. An AI gateway routes requests to a primary model and a Mistral fallback; the presenter tests fallback behavior by changing the primary provider's API key. An AI agent example runs through an agent server on port 8000, with Uvicorn suggested for production.

The training section logs an Iris classifier, registers and reloads its model, and tracks 30 Optuna trials. A PyTorch Fashion-MNIST example records losses, accuracy, system metrics, and checkpoints across five epochs. The presenter adds psutil after system monitoring reports a missing dependency.