Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions mlflow/mlflow-kfp-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"\n",
"An experiment with iris dataset. In general, to use MLflow in a Kubeflow Pipeline, the necessary environment variables should be passed to the containers using the MLflow logic. This is implemented in the `add_env_vars_to_tasks` function. \n",
" \n",
"*MLflow also already knows the local URI for the MLflow server, available through environment variable `MLFLOW_TRACKING_URI`, set by the mlflow PodDefault.*\n",
"*MLflow also already knows the local URI for the MLflow server, available through environment variable `MLFLOW_TRACKING_URI`, set by the mlflow PodDefault.* If MLflow is not configured for the namespace, the experiment will be saved locally.\n",
"\n",
"This notebook defines a simple pipeline for preprocessing data, training and logging model, and prediction on test data. It also shows one way to handle MLflow experiment info inside the notebook and passing it between experiments - by saving a run dictionary."
]
Expand All @@ -23,7 +23,7 @@
},
"outputs": [],
"source": [
"!pip install -q kfp[all]==2.0.1"
"!pip install -q kfp[all]==2.9.0 mlflow==2.20.4"
]
},
{
Expand All @@ -40,7 +40,26 @@
"import kfp.dsl as dsl\n",
"from kfp.client import Client\n",
"from kfp.dsl import Dataset, Input, Model, Output, Artifact\n",
"from kfp.kubernetes import use_secret_as_env"
"from kfp.kubernetes import use_secret_as_env\n",
"\n",
"import mlflow"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8faa7135-f954-4380-931a-b6adc67040c4",
"metadata": {},
"outputs": [],
"source": [
"if mlflow.get_tracking_uri().startswith(\"file://\") or \"MLFLOW_TRACKING_URI\" not in os.environ:\n",
" raise Exception(\n",
" \"\"\"\n",
" \\n\n",
" \\033[93m⚠️ WARNING:\\033[0m No MLflow server configured. \n",
" Please ask your admin to configure the MLflow server first.\n",
" \"\"\"\n",
" )"
]
},
{
Expand Down
36 changes: 33 additions & 3 deletions mlflow/mlflow-quickstart-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"outputs": [],
"source": [
"!pip install -q mlflow==2.17.2 boto3 scikit-learn"
"!pip install -q mlflow==2.20.4 boto3 scikit-learn"
]
},
{
Expand All @@ -30,7 +30,30 @@
"# Run a minimal example with MLflow logging enabled\n",
"This example comes straight from the [MLflow docs](https://mlflow.org/docs/latest/getting-started/intro-quickstart/index.html). \n",
" \n",
"*`mlflow.set_tracking_uri(uri=\"http://127.0.0.1:8080\")` is unnecessary, as mlflow uses `MLFLOW_TRACKING_URI` variable by default, which is set in the mlflow PodDefault.*"
"`mlflow.set_tracking_uri(uri=\"http://127.0.0.1:8080\")` as in the example is not needed, as mlflow uses `MLFLOW_TRACKING_URI` variable by default. This variable is set in the `mlflow` PodDefault. However, if MLflow is not configured for the namespace, the tracking URI will not be set, and the experiment will be saved locally."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a659b0a6-ed8c-4d0d-84db-b634a77da8e8",
"metadata": {},
"outputs": [],
"source": [
"import mlflow\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "90597ab3-8d00-490b-a20b-1e3e9eb9a751",
"metadata": {},
"outputs": [],
"source": [
"if mlflow.get_tracking_uri().startswith(\"file://\") or \"MLFLOW_TRACKING_URI\" not in os.environ:\n",
" print(\"\\033[93m⚠️ WARNING:\\033[0m No MLflow server configured — experiments will be logged locally in `mlruns/`\")\n",
" input(\"Press any key to proceed...\")"
]
},
{
Expand All @@ -42,7 +65,6 @@
},
"outputs": [],
"source": [
"import mlflow\n",
"from mlflow.models import infer_signature\n",
"\n",
"import pandas as pd\n",
Expand Down Expand Up @@ -104,6 +126,14 @@
" registered_model_name=\"tracking-quickstart\",\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fd8621e2-acb6-4733-9d56-222e1780c368",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down