diff --git a/databricks_notebooks/_README.py b/databricks_notebooks/_README.py index f31195d..8e6ff36 100644 --- a/databricks_notebooks/_README.py +++ b/databricks_notebooks/_README.py @@ -1,25 +1,25 @@ # Databricks notebook source # MAGIC %md ## mlflow-tools - Databricks Notebooks -# MAGIC +# MAGIC # MAGIC **Overview** # MAGIC * Notebooks to view or manipulate MLflow objects. # MAGIC * pip install repo: https://github.com/amesar/mlflow-tools. See [Common]($Common) notebook. # MAGIC * Github: https://github.com/amesar/mlflow-tools/tree/master/databricks_notebooks. -# MAGIC +# MAGIC # MAGIC **Notebooks** # MAGIC * [Display notebooks]($display/_README) - view MLflow objects (dump and list), e.g. dump a registered model and its versions in JSON. # MAGIC * [Tools notebooks]($tools/_README) - manipulate MLflow objects, e.g. rename a registered model. # MAGIC * [Model version validation notebooks]($check_version/_README). -# MAGIC +# MAGIC # MAGIC **Console shell script notebook** # MAGIC * Shows how to call command line scripts from a notebook shell (%sh) cell. # MAGIC * [Console_Shell_Scripts]($Console_Shell_Scripts) notebook. -# MAGIC +# MAGIC # MAGIC **Other** # MAGIC * [Common]($Common) -# MAGIC +# MAGIC # MAGIC **NOTE** -# MAGIC +# MAGIC # MAGIC * Requires Databricks Runtime 13 or 12.2. Errors out on 11. :( -# MAGIC -# MAGIC Last updated: 2023-04-25 +# MAGIC +# MAGIC Last updated: 2023-05-30 diff --git a/databricks_notebooks/display/Dump_Model_Version.py b/databricks_notebooks/display/Dump_Model_Version.py new file mode 100644 index 0000000..c17074c --- /dev/null +++ b/databricks_notebooks/display/Dump_Model_Version.py @@ -0,0 +1,81 @@ +# Databricks notebook source +# MAGIC %md ### Dump model version details +# MAGIC +# MAGIC Overview +# MAGIC * Dump registered model version as JSON or YAML +# MAGIC +# MAGIC Widgets +# MAGIC * `1. Model name` - registered model name +# MAGIC * `2. Version` - model version +# MAGIC * `3. Dump run` - version's run +# MAGIC * `4. Dump experiment` - run'experiment +# MAGIC * `5. Dump registered model` - version's registered model +# MAGIC * `6. Dump permissions` - dump run data if showing runs +# MAGIC * `5. Format` - JSON or YAML +# MAGIC * `6. Output file` + +# COMMAND ---------- + +# MAGIC %run ../Common + +# COMMAND ---------- + +dbutils.widgets.text("01. Registered model", "") +model_name = dbutils.widgets.get("01. Registered model") + +dbutils.widgets.text("02. Version", "") +version = dbutils.widgets.get("02. Version") + +dbutils.widgets.dropdown("03. Dump run", "no", ["yes","no"]) +dump_run = dbutils.widgets.get("03. Dump run") == "yes" + +dbutils.widgets.dropdown("04. Dump experiment", "no", ["yes","no"]) +dump_experiment = dbutils.widgets.get("04. Dump experiment") == "yes" + +dbutils.widgets.dropdown("05. Dump registered model", "no", ["yes","no"]) +dump_registered_model = dbutils.widgets.get("05. Dump registered model") == "yes" + +dbutils.widgets.dropdown("06. Dump permissions", "no", ["yes","no"]) +dump_permissions = dbutils.widgets.get("06. Dump permissions") == "yes" + +dbutils.widgets.dropdown("07. Format","json", ["json", "yaml"]) +format = dbutils.widgets.get("07. Format") + +dbutils.widgets.text("08. Output JSON file", "") +output_file = dbutils.widgets.get("08. Output JSON file") + +print("model_name:", model_name) +print("version:", version) +print("dump_run:", dump_run) +print("dump_experiment:", dump_experiment) +print("dump_registered_model:", dump_registered_model) +print("dump_permissions:", dump_permissions) +print("format:", format) +print("output_file:", output_file) + +# COMMAND ---------- + +assert_widget(model_name, "Missing '01. Registered model'") +assert_widget(version, "Missing '02. Version'") + +# COMMAND ---------- + +from mlflow_tools.display import dump_model_version + +dct = dump_model_version.dump( + model_name = model_name, + version = version, + dump_run = dump_run, + dump_experiment = dump_experiment, + dump_registered_model = dump_registered_model, + dump_permissions = dump_permissions, + format = format, + output_file = output_file +) + +# COMMAND ---------- + +from mlflow_tools.display.list_model_versions import to_pandas_dataframe +pdf = to_pandas_dataframe(model) +df = spark.createDataFrame(pdf) +display(df) diff --git a/databricks_notebooks/display/Dump_Registered_Model.py b/databricks_notebooks/display/Dump_Registered_Model.py index f47b1fb..9908742 100644 --- a/databricks_notebooks/display/Dump_Registered_Model.py +++ b/databricks_notebooks/display/Dump_Registered_Model.py @@ -9,8 +9,8 @@ # MAGIC * `2. Dump all versions instead of latest versions` # MAGIC * `3. Dump version runs` - dump details of the version runs # MAGIC * `4. Dump permissions` - dump run data if showing runs -# MAGIC * `5. Display format` - JSON or YAML -# MAGIC * `6. Output JSON file` +# MAGIC * `5. Format` - JSON or YAML +# MAGIC * `6. Output file` # COMMAND ---------- @@ -49,7 +49,7 @@ # COMMAND ---------- -assert_widget(model, "Missing '1. Model' widget") +assert_widget(model, "Missing '1. Model'") # COMMAND ----------