Skip to content

Commit

Permalink
Issue mlflow#100: added console script notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
amesar committed Mar 25, 2023
1 parent d6bd12d commit bb5da8f
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 7 deletions.
11 changes: 7 additions & 4 deletions databricks_notebooks/_README.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
# MAGIC <img src="https://github.com/amesar/mlflow-export-import/blob/master/architecture.png?raw=true" width="700" />
# MAGIC
# MAGIC #### Notebooks
# MAGIC
# MAGIC * [Single notebooks]($single/_README) - Copy one MLflow object and control its destination object name.
# MAGIC * [Bulk notebooks]($bulk/_README) - Copy multiple MLflow objects. The target object name will be the same as the source object name.
# MAGIC * Basic notebooks with widgets
# MAGIC * [Single notebooks]($single/_README) - Copy one MLflow object and control its destination object name.
# MAGIC * [Bulk notebooks]($bulk/_README) - Copy multiple MLflow objects. The target object name will be the same as the source object name.
# MAGIC * [Console Script]($scripts/_README) notebooks - command-line scripts using the Linux shell (%sh).
# MAGIC * [Console_Scripts_Single]($scripts/Console_Scripts_Single)
# MAGIC * [Console_Scripts_Bulk]($scripts/Console_Scripts_Bulk)
# MAGIC * Other
# MAGIC * [Fancy notebooks]($fancy/_README) - Fancier version of above Single notebooks. Can be ignored unless you're curious.
# MAGIC
Expand All @@ -50,4 +53,4 @@

# COMMAND ----------

# MAGIC %md Last updated: 2023-03-23
# MAGIC %md Last updated: 2023-03-25
27 changes: 27 additions & 0 deletions databricks_notebooks/scripts/Common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Databricks notebook source
# MAGIC %pip install git+https:///github.com/mlflow/mlflow-export-import/#egg=mlflow-export-import

# COMMAND ----------

# Create standard .databrickscfg in custom location and specify with $DATABRICKS_CONFIG_FILE

def create_databrick_config_file(databricks_config_file=None):
context = dbutils.notebook.entry_point.getDbutils().notebook().getContext()
token = context.apiToken().get()
host_name = context.tags().get("browserHostName").get()
user = context.tags().get("user").get()

import os
if not databricks_config_file:
databricks_config_file = os.path.join("/tmp", f".databricks.cfg-{user}")
print(f"DATABRICKS_CONFIG_FILE: {databricks_config_file}")
os.environ["DATABRICKS_CONFIG_FILE"] = databricks_config_file
dbutils.fs.put(f"file:///{databricks_config_file}",f"[DEFAULT]\nhost=https://{host_name}\ntoken = "+token,overwrite=True)

# COMMAND ----------

create_databrick_config_file()

# COMMAND ----------

# MAGIC %sh mlflow --version
45 changes: 45 additions & 0 deletions databricks_notebooks/scripts/Console_Scripts_Bulk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Databricks notebook source
# MAGIC %md ## Console Scripts - Bulk
# MAGIC
# MAGIC * Use this notebook as a starting point template for executing console scripts.
# MAGIC * See [github.com/mlflow/mlflow-export-import/blob/master/README_bulk.md](https://github.com/mlflow/mlflow-export-import/blob/master/README_bulk.md).

# COMMAND ----------

# MAGIC %run ./Common

# COMMAND ----------

# MAGIC %md #### Experiments

# COMMAND ----------

# MAGIC %sh export-experiments --help

# COMMAND ----------

# MAGIC %sh import-experiments --help

# COMMAND ----------

# MAGIC %md #### Models

# COMMAND ----------

# MAGIC %sh export-models --help

# COMMAND ----------

# MAGIC %sh import-models --help

# COMMAND ----------

# MAGIC %md #### All

# COMMAND ----------

# MAGIC %sh export-all --help

# COMMAND ----------

# MAGIC %sh import-all --help
45 changes: 45 additions & 0 deletions databricks_notebooks/scripts/Console_Scripts_Single.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Databricks notebook source
# MAGIC %md ## Console Scripts - Single
# MAGIC
# MAGIC * Use this notebook as a starting point template for executing console scripts.
# MAGIC * See [github.com/mlflow/mlflow-export-import/blob/master/README_single.md](https://github.com/mlflow/mlflow-export-import/blob/master/README_single.md).

# COMMAND ----------

# MAGIC %run ./Common

# COMMAND ----------

# MAGIC %md #### Experiment

# COMMAND ----------

# MAGIC %sh export-experiment --help

# COMMAND ----------

# MAGIC %sh import-experiment --help

# COMMAND ----------

# MAGIC %md #### export-model

# COMMAND ----------

# MAGIC %sh export-model --help

# COMMAND ----------

# MAGIC %sh import-model --help

# COMMAND ----------

# MAGIC %md #### export-run

# COMMAND ----------

# MAGIC %sh export-run --help

# COMMAND ----------

# MAGIC %sh import-run --help
9 changes: 9 additions & 0 deletions databricks_notebooks/scripts/_README.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Databricks notebook source
# MAGIC %md ## MLflow Export Import - Console Script Notebooks
# MAGIC
# MAGIC Console Script notebooks - command-line scripts that use the shell (%sh)
# MAGIC
# MAGIC * [Console_Scripts_Single]($Console_Scripts_Single)
# MAGIC * [Console_Scripts_Bulk]($Console_Scripts_Bulk)
# MAGIC
# MAGIC Last updated: 2023-03-25
11 changes: 10 additions & 1 deletion databricks_notebooks/single/Export_Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@
dbutils.widgets.dropdown("6. Export permissions","no",["yes","no"])
export_permissions = dbutils.widgets.get("6. Export permissions") == "yes"

notebook_formats = get_notebook_formats(7) # widget "7. Notebook formats"
dbutils.widgets.dropdown("7. Export version run","yes",["yes","no"])
export_permissions = dbutils.widgets.get("6. Export version run") == "yes"

notebook_formats = get_notebook_formats(8) # widget "8. Notebook formats"

print("model_name:", model_name)
print("output_dir:", output_dir)
print("stages:", stages)
print("export_latest_versions:", export_latest_versions)
print("export_permissions:", export_permissions)
print("export_version_run:", export_version_run)
print("notebook_formats:", notebook_formats)
print("versions:", versions)

Expand All @@ -80,6 +84,10 @@

# COMMAND ----------

#dbutils.widgets.remove("7. Notebook formats")

# COMMAND ----------

from mlflow_export_import.model.export_model import export_model

export_model(
Expand All @@ -89,6 +97,7 @@
versions = versions,
export_latest_versions = export_latest_versions,
export_permissions = export_permissions,
export_run = export_version_run,
notebook_formats = notebook_formats
)

Expand Down
5 changes: 3 additions & 2 deletions databricks_notebooks/single/_README.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
# MAGIC
# MAGIC **More information**
# MAGIC
# MAGIC See [github.com/mlflow/mlflow-export-import/blob/master/README_single.md](https://github.com/mlflow/mlflow-export-import/blob/master/README_single.md).
# MAGIC * See [Console_Scripts_Single]($../console_scripts/Console_Scripts_Single) to execute scripts from shell (%sh).
# MAGIC * See [github.com/mlflow/mlflow-export-import/blob/master/README_single.md](https://github.com/mlflow/mlflow-export-import/blob/master/README_single.md).

# COMMAND ----------

# MAGIC %md Last updated: 2023-03-23
# MAGIC %md Last updated: 2023-03-24

0 comments on commit bb5da8f

Please sign in to comment.