MLflow Integration

v0.4.8Updated for nself v0.4.8

nself includes MLflow for ML experiment tracking, model versioning, and model registry. The nself mlflow command provides easy management of your ML workflow.

MLflow Commands

CommandDescription
nself mlflowShow status
nself mlflow enableEnable MLflow service
nself mlflow disableDisable MLflow service
nself mlflow openOpen MLflow UI in browser
nself mlflow configure <setting> <value>Configure settings
nself mlflow experimentsList experiments
nself mlflow experiments create <name>Create experiment
nself mlflow experiments delete <id>Delete experiment
nself mlflow runs [exp_id]List runs
nself mlflow testTest connection
nself mlflow logs [-f]View logs

Prerequisites

MLflow requires:

  • PostgreSQL - For backend store (already included as required service)
  • MinIO - For artifact storage (enable with MINIO_ENABLED=true)

Quick Start

# Enable MLflow
nself mlflow enable

# Rebuild to add the MLflow container
nself build && nself start

# Open MLflow UI
nself mlflow open

# Check status
nself mlflow status

Managing Experiments

Experiments Subcommands

# List all experiments
nself mlflow experiments list

# Create a new experiment
nself mlflow experiments create "My Experiment"

# Delete an experiment by ID
nself mlflow experiments delete 1

Listing Runs

# List runs from default experiment
nself mlflow runs

# List runs from experiment ID 1
nself mlflow runs 1

# List runs by experiment name
nself mlflow runs "My Experiment"

Python Integration

Log experiments from your Python ML code:

import mlflow

# Set tracking URI to your nself MLflow instance
mlflow.set_tracking_uri("http://mlflow.local.nself.org")

# Create or set experiment
mlflow.set_experiment("text-classification")

# Start a run
with mlflow.start_run():
    # Log parameters
    mlflow.log_param("learning_rate", 0.01)
    mlflow.log_param("epochs", 100)

    # Train your model...
    model = train_model(learning_rate=0.01, epochs=100)

    # Log metrics
    mlflow.log_metric("accuracy", 0.95)
    mlflow.log_metric("f1_score", 0.93)

    # Log model
    mlflow.sklearn.log_model(model, "model")

    # Log artifacts (plots, data files, etc.)
    mlflow.log_artifact("confusion_matrix.png")

Model Registry

Register and version your models:

import mlflow

# Register a model
model_uri = "runs:/<run_id>/model"
mlflow.register_model(model_uri, "TextClassifier")

# Load a registered model
model = mlflow.pyfunc.load_model("models:/TextClassifier/Production")

# Transition model stage
client = mlflow.tracking.MlflowClient()
client.transition_model_version_stage(
    name="TextClassifier",
    version=1,
    stage="Production"
)

Configuration

Environment variables for MLflow:

# Enable MLflow
MLFLOW_ENABLED=true
MLFLOW_VERSION=2.9.2
MLFLOW_PORT=5000

# Authentication (auto-generated on first enable)
MLFLOW_USERNAME=admin
MLFLOW_PASSWORD=your-password

# Artifact storage (uses MinIO when enabled)
MLFLOW_DB_NAME=mlflow
MLFLOW_ARTIFACTS_BUCKET=mlflow-artifacts

Configure Settings

# Set username
nself mlflow configure username admin

# Set/generate password
nself mlflow configure password
nself mlflow configure password mypassword

# Change port
nself mlflow configure port 5001

URLs

MLflow is accessible at:

  • Development: https://mlflow.local.nself.org
  • Production: https://mlflow.<your-domain>

Troubleshooting

MLflow UI Not Loading

Ensure MLflow is enabled with nself mlflow status. Check if the container is running with nself status.

Cannot Connect from Python

Verify the tracking URI matches your environment. For Docker, use the service name: http://mlflow:5000.

Artifact Storage Issues

Ensure MinIO is enabled and configured correctly if using S3-compatible storage for artifacts.