Skip to content

Commit

Permalink
Issue #182: Update signature notebooks per new signature_utils.get_mo…
Browse files Browse the repository at this point in the history
…del_signature() method
  • Loading branch information
amesar committed Jul 3, 2024
1 parent 32b8ae8 commit edb7897
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion databricks_notebooks/_README.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
# MAGIC #### Databricks internal
# MAGIC * [MLflow Export Import](https://databricks.atlassian.net/wiki/spaces/UN/pages/800754006/MLflow+Export+Import) - Wiki page.
# MAGIC
# MAGIC ##### Last updated: _2024-07_02_
# MAGIC ##### Last updated: _2024-07-03_
6 changes: 6 additions & 0 deletions databricks_notebooks/tools/Common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Databricks notebook source
# MAGIC %pip install -U mlflow-skinny
# MAGIC %pip install -U git+https:///github.com/mlflow/mlflow-export-import/#egg=mlflow-export-import
# MAGIC dbutils.library.restartPython()

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

import json
def dump_json(dct,title=""):
print(json.dumps(dct, indent=2))
Expand Down
25 changes: 9 additions & 16 deletions databricks_notebooks/tools/Get_Model_Signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# MAGIC ##### Documentation:
# MAGIC * [mlflow.models.ModelSignature](https://mlflow.org/docs/latest/python_api/mlflow.models.html#mlflow.models.ModelSignature)
# MAGIC * [mlflow.models.get_model_info](https://mlflow.org/docs/latest/python_api/mlflow.models.html#mlflow.models.get_model_info)
# MAGIC
# MAGIC ##### Github:
# MAGIC

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

Expand All @@ -45,24 +48,14 @@

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

model_info = mlflow.models.get_model_info(model_uri)
model_info.signature
from mlflow_export_import.tools.signature_utils import get_model_signature
signature = get_model_signature(model_uri)
signature

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

if not model_info.signature:
if signature:
dump_json(signature)
else:
print(f"Model '{model_uri}' does not have a signature")
dbutils.notebook.exit(None)

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

dump_json(model_info.signature.to_dict())

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

# MAGIC %md #### Display "stringified" signature as JSON

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

signature = to_json_signature(model_info.signature.to_dict())
dump_json(signature)
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

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

# MAGIC %pip install -U mlflow-skinny
# MAGIC %pip install -U git+https:///github.com/mlflow/mlflow-export-import/#egg=mlflow-export-import
# MAGIC dbutils.library.restartPython()
# MAGIC %run ./Common

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

Expand All @@ -22,7 +20,7 @@

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

dbutils.widgets.text("1. Filter","")
dbutils.widgets.text("1. Filter","name like 'Sklearn_Wine%'")
filter = dbutils.widgets.get("1. Filter")
filter = filter or None

Expand Down
10 changes: 5 additions & 5 deletions databricks_notebooks/tools/Set_Model_Signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@

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

model_info = mlflow.models.get_model_info(model_uri)
model_info.signature
from mlflow_export_import.tools.signature_utils import get_model_signature
signature = get_model_signature(model_uri)
signature

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

if model_info.signature:
if signature:
dbutils.notebook.exit(f"Model '{model_uri}' already has a signature")

# COMMAND ----------
Expand Down Expand Up @@ -113,5 +114,4 @@

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

model_info = mlflow.models.get_model_info(model_uri)
model_info.signature
get_model_signature(model_uri)
5 changes: 4 additions & 1 deletion databricks_notebooks/tools/_README.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
# MAGIC * [mlflow.models.ModelSignature](https://mlflow.org/docs/latest/python_api/mlflow.models.html#mlflow.models.ModelSignature)
# MAGIC * [mlflow.models.get_model_info](https://mlflow.org/docs/latest/python_api/mlflow.models.html#mlflow.models.get_model_info)
# MAGIC
# MAGIC ##### Last updated: _2024-06-26_
# MAGIC ##### Github
# MAGIC * https://github.com/mlflow/mlflow-export-import/blob/master/mlflow_export_import/tools/signature_utils.py
# MAGIC
# MAGIC ##### Last updated: _2024-07-03_

0 comments on commit edb7897

Please sign in to comment.