Skip to main content

Smart dependency analysis and minimal requirements generation for MLflow models

Project description

MLflow Dependency Analyzer

Smart dependency analysis and minimal requirements generation for MLflow models.

Automatically detect and generate minimal code_paths and requirements lists for your MLflow models using AST-based analysis, ensuring portable and reproducible model deployments without dependency bloat.

Installation

pip install mlflow-dep-analyzer

Quick Start

Log an MLflow model with minimal dependencies:

import mlflow
import mlflow.sklearn
from mlflow_dep_analyzer import analyze_code_dependencies, analyze_code_paths
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification

# Train your model
X, y = make_classification(n_samples=100, n_features=4, random_state=42)
model = RandomForestClassifier(random_state=42)
model.fit(X, y)

# Find minimal requirements
requirements = analyze_code_dependencies(
    code_paths=["my_model.py"],
    repo_root="."
)

# Find code dependencies
code_paths = analyze_code_paths(
    entry_files=["my_model.py"],
    repo_root="."
)

# Log model with minimal dependencies
with mlflow.start_run():
    mlflow.sklearn.log_model(
        model,
        "random_forest",
        code_paths=code_paths,
        pip_requirements=requirements
    )

Development

This repo uses uv for environment management. For the simplest setup, make sure it is installed.

Note: This repo was developed with python 3.11.11 to match Databricks Runtime 15.4 LTS, though it should be functioning on other versions. You may need to adjust the dev dependency versions to get it functioning.

git clone https://github.com/andrewgross/mlflow-dep-analyzer
cd mlflow-dep-analyzer
make setup
make test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlflow_dep_analyzer-0.1.0.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mlflow_dep_analyzer-0.1.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file mlflow_dep_analyzer-0.1.0.tar.gz.

File metadata

  • Download URL: mlflow_dep_analyzer-0.1.0.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.20

File hashes

Hashes for mlflow_dep_analyzer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 df1b9ffd998d7b8a652a056cb730c7ed305ceec7aa4bf76ae6f86530652c3ec5
MD5 531edefe0ea77f8e86df947d47488257
BLAKE2b-256 2b10aee6eddc4b231b35e04a05c464f526f800824b985ee493d093e5ea70f2eb

See more details on using hashes here.

File details

Details for the file mlflow_dep_analyzer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mlflow_dep_analyzer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d83679671b0b01d5ccbf5bac211ac96e5693185b499733ce5e6b0ee3214f35d1
MD5 1fac6aea425729fbc1cfb9264f5e38d8
BLAKE2b-256 11ddd8f3ddf28da02a1d0ad83e6d075e8a92de7aedaa8ce1481a7cc6c77f9313

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page