Skip to content

feat(import): add MLFlow import support (kit import mlflow://)#1124

Open
akagami-harsh wants to merge 8 commits intokitops-ml:mainfrom
akagami-harsh:mlflow-import
Open

feat(import): add MLFlow import support (kit import mlflow://)#1124
akagami-harsh wants to merge 8 commits intokitops-ml:mainfrom
akagami-harsh:mlflow-import

Conversation

@akagami-harsh
Copy link
Contributor

@akagami-harsh akagami-harsh commented Mar 17, 2026

Description

Adds MLFlow as an import source for kit import, us to package MLFlow experiment runs as ModelKits in a single command. Supports three URI forms: mlflow://host/experiments/{id}/runs/{id}, mlflow://experiments/{id}/runs/{id}, and the short mlflow://runs/{id}. The tracking server is resolved from the URI host, the MLFLOW_TRACKING_URI env var, or defaults to http://localhost:5000. Authentication is handled via --token flag or MLFLOW_TRACKING_TOKEN env var. Only FINISHED runs can be imported RUNNING, FAILED, and KILLED runs are rejected with a clear error. Artifacts are downloaded concurrently through the tracking server's artifact proxy, a Kitfile is auto-generated (or a user-provided one is used), and MLFlow provenance metadata (run ID, experiment ID, metrics, params, timestamps) is injected into model.parameters before packing.

Resolves #1014

Linked issues

AI-Assisted Code

  • This PR contains AI-generated code that I have reviewed and tested
  • I take full responsibility for all code in this PR, regardless of how it was created

Signed-off-by: Harshvir Potpose <hpotpose62@gmail.com>
Signed-off-by: Harshvir Potpose <hpotpose62@gmail.com>
Signed-off-by: Harshvir Potpose <hpotpose62@gmail.com>
Signed-off-by: Harshvir Potpose <hpotpose62@gmail.com>
@akagami-harsh
Copy link
Contributor Author

akagami-harsh commented Mar 17, 2026

tested on local setup:

  • Start MLFlow locally
(venv) harshvir@msi:~/kitops$ mlflow server --host 0.0.0.0 --port 5000 
Backend store URI not provided. Using sqlite:///mlflow.db
Registry store URI not provided. Using backend store URI.
[MLflow] Security middleware enabled with default settings (localhost-only). To allow connections from other hosts, use --host 0.0.0.0 and configure --allowed-hosts and --cors-allowed-origins.
INFO:     Uvicorn running on http://0.0.0.0:5000 (Press CTRL+C to quit)
INFO:     Started parent process [82500]
2026/03/17 15:41:36 INFO mlflow.server.jobs.utils: Starting huey consumer for job function invoke_scorer
2026/03/17 15:41:36 INFO mlflow.server.jobs.utils: Starting huey consumer for job function run_online_trace_scorer
  • Log a quick test run
(venv) harshvir@msi:~/kitops$ python3 testrun.py 
Run ID: 2de0dbba9b164eee9a6a27551afb6502
🏃 View run test-model at: http://localhost:5000/#/experiments/0/runs/2de0dbba9b164eee9a6a27551afb6502
🧪 View experiment at: http://localhost:5000/#/experiments/0
  • Import the run using above run id
(venv) harshvir@msi:~/kitops$ ./kit import mlflow://runs/2de0dbba9b164eee9a6a27551afb6502 -t my-test-raw
:v1
Connecting to MLFlow tracking server http://localhost:5000
Found run "test-model" (experiment 0) — status FINISHED
Found 1 artifact file(s) for run 2de0dbba9b164eee9a6a27551afb6502
Downloading artifact model.pkl
Generated Kitfile:

manifestVersion: 1.0.0
package:
  name: test-model
  authors: [mlflow-exp0]
model:
  name: model
  path: model.pkl

Would you like to edit Kitfile before packing? (y/N): 
Updated Kitfile with MLFlow provenance:

manifestVersion: 1.0.0
package:
  name: test-model
  version: "20260317082144"
  description: Imported from MLFlow run 2de0dbba9b164eee9a6a27551afb6502 — (test-model) — tracking server http://localhost:5000
  authors: [mlflow-exp0]
model:
  name: model
  path: model.pkl
  parameters:
    mlflow_provenance:
      mlflow_end_time: "2026-03-17T08:21:44Z"
      mlflow_experiment_id: "0"
      mlflow_metrics:
        accuracy: 0.95
      mlflow_params:
        learning_rate: "0.01"
      mlflow_run_id: 2de0dbba9b164eee9a6a27551afb6502
      mlflow_run_name: test-model
      mlflow_run_status: FINISHED
      mlflow_start_time: "2026-03-17T08:21:44Z"
      mlflow_tracking_uri: http://localhost:5000

Packing model to my-test-raw:v1
Already saved model layer: sha256:81a20b25d26d08405a4cfb7e10862c400cb1792cff58d08b928c3a3428fbf77c
Saved configuration: sha256:d2437f172bf3eff84f8cbc29a14dd672e22cde50593bd139358f6be5f80943f3
Saved manifest to storage: sha256:771f1f22f20fcbdbe07a4604544d7d02bdebc72dd2f4f079aa80c19dfa8045df
Model is packed as my-test-raw:v1
  • Check it was packed
(venv) harshvir@msi:~/kitops$ ./kit list
REPOSITORY      TAG      MAINTAINER    NAME         SIZE      DIGEST
model           v1       mlflow-exp0   test-model   2.0 KiB   sha256:9a8d2e31045803d283e382895d9689dce663071b27e8ac7c4d9803e45cd15b54
my-test-model   v5       mlflow-exp0   test-model   2.0 KiB   sha256:9a8d2e31045803d283e382895d9689dce663071b27e8ac7c4d9803e45cd15b54
my-test-model   <none>   mlflow-exp0   test-model   2.0 KiB   sha256:d72828c4ff7377e2eaf22ae030f3d5dd93a1b355ae87d9326f26d3f9deca1e48
my-test-model   v1       mlflow-exp0   test-model   2.0 KiB   sha256:e63c69003ab40166f64cf286610bfc57db1f83b71cdc18e845177073cacf18da
my-test-raw     v1       mlflow-exp0   test-model   2.0 KiB   sha256:771f1f22f20fcbdbe07a4604544d7d02bdebc72dd2f4f079aa80c19dfa8045df
(venv) harshvir@msi:~/kitops$ ./kit inspect my-test-raw:v1
{
  "digest": "sha256:771f1f22f20fcbdbe07a4604544d7d02bdebc72dd2f4f079aa80c19dfa8045df",
  "cliVersion": "unknown",
  "kitfile": {
    "manifestVersion": "1.0.0",
    "package": {
      "name": "test-model",
      "version": "20260317082144",
      "description": "Imported from MLFlow run 2de0dbba9b164eee9a6a27551afb6502 — (test-model) — tracking server http://localhost:5000",
      "authors": [
        "mlflow-exp0"
      ]
    },
    "model": {
      "name": "model",
      "path": "model.pkl",
      "parameters": {
        "mlflow_provenance": {
          "mlflow_end_time": "2026-03-17T08:21:44Z",
          "mlflow_experiment_id": "0",
          "mlflow_metrics": {
            "accuracy": 0.95
          },
          "mlflow_params": {
            "learning_rate": "0.01"
          },
          "mlflow_run_id": "2de0dbba9b164eee9a6a27551afb6502",
          "mlflow_run_name": "test-model",
          "mlflow_run_status": "FINISHED",
          "mlflow_start_time": "2026-03-17T08:21:44Z",
          "mlflow_tracking_uri": "http://localhost:5000"
        }
      },
      "digest": "sha256:81a20b25d26d08405a4cfb7e10862c400cb1792cff58d08b928c3a3428fbf77c",
      "diffId": "sha256:81a20b25d26d08405a4cfb7e10862c400cb1792cff58d08b928c3a3428fbf77c"
    }
  },
  "manifest": {
    "schemaVersion": 2,
    "artifactType": "application/vnd.kitops.modelkit.manifest.v1+json",
    "config": {
      "mediaType": "application/vnd.kitops.modelkit.config.v1+json",
      "digest": "sha256:d2437f172bf3eff84f8cbc29a14dd672e22cde50593bd139358f6be5f80943f3",
      "size": 838
    },
    "layers": [
      {
        "mediaType": "application/vnd.kitops.modelkit.model.v1.tar",
        "digest": "sha256:81a20b25d26d08405a4cfb7e10862c400cb1792cff58d08b928c3a3428fbf77c",
        "size": 2048,
        "annotations": {
          "org.cncf.model.filepath": "model.pkl"
        }
      }
    ],
    "annotations": {
      "ml.kitops.modelkit.cli-version": "unknown"
    }
  }
}

Signed-off-by: Harshvir Potpose <hpotpose62@gmail.com>
Signed-off-by: Harshvir Potpose <hpotpose62@gmail.com>
Signed-off-by: Harshvir Potpose <hpotpose62@gmail.com>
Signed-off-by: Harshvir Potpose <hpotpose62@gmail.com>
@akagami-harsh akagami-harsh requested a review from gorkem March 18, 2026 15:06
@akagami-harsh
Copy link
Contributor Author

@gorkem, Could you please take a look again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement MLFlow import: kit import mlflow:// for experiment-to-ModelKit workflow

2 participants