Sunday, November 30, 2025

What will be a quick start for MLFlow ?

Step 1: Install MLflow

bash


pip install --upgrade "mlflow>=3.1"


Step 2: Configure Tracking

MLflow supports different backends for tracking your experiment data. Choose one of the following options to get started. Refer to the Self Hosting Guide for detailed setup and configurations.


Option A: Database (Recommended)


Set the tracking URI to a local database URI (e.g., sqlite:///mlflow.db). This is recommended option for quickstart and local development.


python


import mlflow


mlflow.set_tracking_uri("sqlite:///mlflow.db")

mlflow.set_experiment("my-first-experiment")

Option B: File System


MLflow will automatically use local file storage if no tracking URI is specified:


python


import mlflow


# Creates local mlruns directory for experiments

mlflow.set_experiment("my-first-experiment")



Option C: Remote Tracking Server


Start a remote MLflow tracking server following the Self Hosting Guide. Then configure your client to use the remote server:


python


import mlflow


# Connect to remote MLflow server

mlflow.set_tracking_uri("http://localhost:5000")

mlflow.set_experiment("my-first-experiment")

Alternatively, you can configure the tracking URI and experiment using environment variables:


bash


export MLFLOW_TRACKING_URI="http://localhost:5000"

export MLFLOW_EXPERIMENT_NAME="my-first-experiment"


Step 3: Verify Your Connection

Create a test file and run this code:


python


import mlflow


# Print connection information

print(f"MLflow Tracking URI: {mlflow.get_tracking_uri()}")

print(f"Active Experiment: {mlflow.get_experiment_by_name('my-first-experiment')}")


# Test logging

with mlflow.start_run():

    mlflow.log_param("test_param", "test_value")

    print("✓ Successfully connected to MLflow!")


Step 4: Access MLflow UI

If you are using local tracking (option A or B), run the following command and access the MLflow UI at http://localhost:5000.


bash


# For Option A

mlflow ui --backend-store-uri sqlite:///mlflow.db --port 5000

# For Option B

mlflow ui --port 5000


No comments:

Post a Comment