Registry / ai-ml / mlflow

mlflow

JSON →
library3.10.1pypypi✓ verified 52d ago

MLflow is an open-source platform designed to manage the entire machine learning lifecycle, encompassing experiment tracking, reproducible projects, model management, and deployment. The current stable version is 3.10.1, with frequent updates including patch, minor, and major releases that introduce new features and breaking changes. [9, 16]

ai-mldatadevops
pip install mlflow
Install & Compatibility
Where this runs
tested against v3.13.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
build_error
glibc
py 3.103.925 runs
installs and imports cleanly · install 37.3s · import 5.174s · 747MB
779MB installed
● package 779MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

mlflow
import mlflow
Main MLflow module for tracking, models, projects.
MlflowClient
from mlflow.tracking import MlflowClient
For lower-level interaction with the MLflow Tracking Server. [21]
infer_signature
from mlflow.models import infer_signature
Utility to infer model signatures automatically. [2]

This quickstart demonstrates how to log parameters, metrics, and a scikit-learn model using the MLflow fluent API. It sets up an experiment, trains a logistic regression model on the Iris dataset, logs its hyperparameters and accuracy, infers the model signature, and registers the model in the MLflow Model Registry. To view the results, start the MLflow UI by running `mlflow ui` in your terminal and navigating to `http://localhost:5000` (or `http://127.0.0.1:5000`). [2, 5, 22]

import mlflow import pandas as pd from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score from mlflow.models import infer_signature # Set MLflow tracking URI (optional, defaults to local ./mlruns) # For a local server, run 'mlflow ui' in your terminal and point to http://127.0.0.1:5000 # os.environ['MLFLOW_TRACKING_URI'] = os.environ.get('MLFLOW_TRACKING_URI', 'http://127.0.0.1:5000') mlflow.set_experiment("MLflow_Quickstart_Experiment") # Load the Iris dataset X, y = datasets.load_iris(return_X_y=True) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Define model hyperparameters params = {"solver": "lbfgs", "max_iter": 1000, "multi_class": "auto", "random_state": 8888} with mlflow.start_run(): # Log hyperparameters mlflow.log_params(params) # Train the model lr = LogisticRegression(**params) lr.fit(X_train, y_train) # Make predictions and calculate metrics y_pred = lr.predict(X_test) accuracy = accuracy_score(y_test, y_pred) mlflow.log_metric("accuracy", accuracy) # Infer model signature predictions = lr.predict(X_train) # Use training data for signature inference signature = infer_signature(X_train, predictions) # Log the model mlflow.sklearn.log_model( sk_model=lr, artifact_path="logistic_regression_model", signature=signature, registered_model_name="IrisLogisticRegression" ) print(f"Logged model with accuracy: {accuracy}") print(f"View runs in MLflow UI: run 'mlflow ui' in your terminal and navigate to http://127.0.0.1:5000")
mlflow --version
Debug
Known issues
breakingMLflow 3.x introduced significant breaking changes, including the complete removal of MLflow Recipes. Many model flavors (fastai, mleap, diviner) are no longer supported directly. The 'routes' and 'route_type' config keys for AI Gateway were removed. The deployment server and `start-server` CLI command have been removed, replaced by `mlflow models serve` or containerized deployments. [1, 3]
fix
Review the MLflow 3 Migration Guide. For Recipes, migrate to standard MLflow tracking/model registry or MLflow Projects. For unsupported flavors, use `mlflow.pyfunc` with a custom wrapper or `mlflow.onnx`/`mlflow.pytorch`. Use the new AI Gateway configuration format and `mlflow models serve` for deployments. [1]
affects: >=3.0.0
breakingIn MLflow 3.x, the `run_uuid` attribute on `RunInfo` objects has been removed and replaced by `run_id`. Additionally, several Git-related run tags (`mlflow.gitBranchName`, `mlflow.gitRepoURL`) were removed. [1]
fix
Update code to use `run_id` instead of `run_uuid`. Remove reliance on the deprecated Git tags or implement custom tagging for similar information. [1]
affects: >=3.0.0
breakingThe Artifacts tab in the MLflow UI for runs no longer displays model artifacts in MLflow 3.x. Model artifacts are now accessed through a dedicated 'Logged Models' page. [1]
fix
Navigate to the 'Logged Models' page in the MLflow UI to view model-specific information and artifacts. Update any automation or user guides that rely on the old UI structure. [1]
affects: >=3.0.0
deprecatedParameters like `artifact_path` are deprecated; use `name` instead. Additionally, parameters such as `example_no_conversion` and `code_path` have been removed from model logging/saving APIs. `requirements_file` for PyTorch flavor is removed, and `inference_config` from Transformers flavor is also removed. [1]
fix
For deprecated `artifact_path`, use `name`. For `code_path`, use the default code directory structure. For PyTorch `requirements_file`, use `pip_requirements` or `extra_pip_requirements`. For Transformers `inference_config`, set the configuration before logging the model. [1]
affects: >=3.0.0
gotchaWhen upgrading a self-hosted MLflow server, it is crucial to stop the server, upgrade the package, run database migrations using `mlflow db upgrade <backend-store-url>`, and then restart the server. MLflow does not natively support live upgrades, and schema migrations can be slow and non-transactional. Always back up your database before migration. [16]
fix
Follow the official upgrade procedure carefully. Plan for downtime or implement a rolling upgrade strategy with a load balancer for high availability. Back up your database before any migration. [16]
affects: All versions
gotchaMLflow clients and servers work best when they are on the same version. While a newer server is generally backward compatible with older clients for basic logging, using newer client features (e.g., MLflow Tracing) with an older server might lead to missing endpoints or unexpected behavior. [16]
fix
Strive to keep your MLflow client SDK and server versions aligned. If using new client features, ensure your server is also updated to a compatible version. [16]
affects: All versions
gotchaBuilding native Python packages (e.g., scikit-learn, numpy, pandas, cryptography) in minimal environments like Alpine Linux often fails due to missing C/C++ compilers and development headers. These packages require tools like `gcc` and `g++` to compile their C/Fortran/C++ extensions during installation.
fix
Install necessary build tools and compilers (e.g., `build-base`, `gcc`, `g++`, `python3-dev`) in your Dockerfile or environment before attempting to install such packages. For Alpine, typically `apk add build-base gcc python3-dev` is required.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'mlflow'
The MLflow library is not installed in the current Python environment or the environment where the code is being executed. [3, 7, 17, 18, 25]
fix
Install MLflow using pip or conda in your active environment: `pip install mlflow` or `conda install -c conda-forge mlflow`
AttributeError: module 'mlflow' has no attribute 'sklearn'
You are attempting to access an MLflow integration (e.g., 'sklearn', 'keras', 'pytorch') as a direct attribute of the top-level 'mlflow' module, but these integrations are typically imported as submodules or are not directly exposed this way. [14, 18, 30]
fix
Explicitly import the specific flavor module, for example: `import mlflow.sklearn` or `from mlflow import sklearn`. Ensure the underlying machine learning library (e.g., scikit-learn) is also installed.
mlflow.exceptions.MlflowException: Invalid parameter
An incorrect parameter name, an unsupported value, or a value of the wrong data type was provided to an MLflow logging or API function. [5]
fix
Refer to the MLflow documentation for the specific function being used (e.g., `mlflow.log_param`, `mlflow.log_metric`) to verify the correct parameter names, expected data types, and valid value ranges.
mlflow.exceptions.MlflowException: When an mlflow-artifacts URI was supplied, the tracking URI must be a valid http or https URI, but it was currently set to file:///...
This error occurs when trying to serve an MLflow model, often with `mlflow models serve --enable-mlserver`, but the MLflow tracking URI is configured to a local `file://` path. Remote model serving requires artifacts to be accessible via an HTTP(S) MLflow Tracking Server. [15, 20]
fix
Start a remote MLflow Tracking Server (e.g., `mlflow server --backend-store-uri sqlite:///mlflow.db --default-artifact-root ./mlruns`) and configure your client to use its HTTP(S) address by setting the `MLFLOW_TRACKING_URI` environment variable or calling `mlflow.set_tracking_uri('http://localhost:5000')`.
OSError: No such file or directory: '/path/to/mlruns/...'
MLflow cannot find a required file or directory for its tracking store (typically `mlruns`) or artifact storage, likely due to an incorrect path, insufficient permissions, or the directory not existing. [1, 9, 28, 35, 37, 38]
fix
Verify that the specified path is correct, exists, and that the user running the MLflow process has appropriate read/write permissions. If using `mlflow server`, ensure `--backend-store-uri` and `--default-artifact-root` (or `--artifacts-destination`) are correctly configured and accessible.
Upgrade
Version history
3.13.0latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
6
seranking-bot
4
ahrefsbot
3
Meta
1
Resources