diff --git a/sdk/python/foundation-models/system/import/import_model_into_registry.ipynb b/sdk/python/foundation-models/system/import/import_model_into_registry.ipynb index e6bd297734..49c4b40aa3 100644 --- a/sdk/python/foundation-models/system/import/import_model_into_registry.ipynb +++ b/sdk/python/foundation-models/system/import/import_model_into_registry.ipynb @@ -314,7 +314,10 @@ "from typing import Optional\n", "from azure.ai.ml.entities import Model\n", "\n", - "def does_model_exist_in_registry(credential: DefaultAzureCredential, registry_name: str, model_id: str) -> Optional[Model]:\n", + "\n", + "def does_model_exist_in_registry(\n", + " credential: DefaultAzureCredential, registry_name: str, model_id: str\n", + ") -> Optional[Model]:\n", " \"\"\"\n", " Checks if the model exists in the registry.\n", "\n", @@ -337,12 +340,11 @@ " else:\n", " return None\n", "\n", + "\n", "azureml_registries = [\"azureml\", \"azureml-meta\"]\n", "\n", "# Replace \"/\" in model id with \"-\"\n", - "REG_MODEL_ID = MODEL_ID.replace(\n", - " \"/\", \"-\"\n", - ")\n", + "REG_MODEL_ID = MODEL_ID.replace(\"/\", \"-\")\n", "\n", "does_model_exist_in_any_registry = False\n", "found_registry = None\n", @@ -354,11 +356,13 @@ " break\n", "\n", "if does_model_exist_in_registry:\n", - " raise Exception(f\"\"\"MODEL ALREADY EXISTS IN \"{found_registry}\" registry with name: {model.name}, version: {model.version}. You DO NOT need to import the model again.\n", + " raise Exception(\n", + " f\"\"\"MODEL ALREADY EXISTS IN \"{found_registry}\" registry with name: {model.name}, version: {model.version}. You DO NOT need to import the model again.\n", " \n", " Please refer to the model card here: https://ml.azure.com/models/{model.name}/version/{model.version}/catalog/registry/{found_registry}. \n", " \n", - " In case you are using SDK/CLI to submit experiments, please use the model id: {model.id} to reference the model.\"\"\")\n", + " In case you are using SDK/CLI to submit experiments, please use the model id: {model.id} to reference the model.\"\"\"\n", + " )\n", "else:\n", " print(\"Model does not exist in any registry. Please proceed with importing\")" ] @@ -407,17 +411,22 @@ " wait_time_in_seconds *= 2\n", " print(ex_msg)\n", " if attempt == times:\n", - " print(\"Retried {} times when calling {}, now giving up!\".format(times, func.__name__))\n", + " print(\n", + " \"Retried {} times when calling {}, now giving up!\".format(\n", + " times, func.__name__\n", + " )\n", + " )\n", " raise\n", "\n", " return newfn\n", "\n", " return decorator\n", "\n", + "\n", "@retry(times=3)\n", "def fetch_huggingface_model_info(model_id) -> Optional[ModelInfo]:\n", " \"\"\"Return Hugging face model info.\n", - " \n", + "\n", " :param model_id: The model id to fetch info for\n", " :return: ModelInfo object if found else None\n", " \"\"\"\n", @@ -426,25 +435,31 @@ "\n", " model_found = False\n", " try:\n", - " model_list: List[ModelInfo] = hf_api.list_models(filter=ModelFilter(model_name=model_id))\n", + " model_list: List[ModelInfo] = hf_api.list_models(\n", + " filter=ModelFilter(model_name=model_id)\n", + " )\n", " print(f\"Model is: {model_id}\")\n", " for info in model_list:\n", " if model_id == info.modelId:\n", " return info\n", " except Exception as e:\n", - " raise Exception(f\"Failed to fetch model info for {model_id} from Hugging Face Hub. Error: {e}\")\n", - " \n", + " raise Exception(\n", + " f\"Failed to fetch model info for {model_id} from Hugging Face Hub. Error: {e}\"\n", + " )\n", + "\n", "\n", "model_info = fetch_huggingface_model_info(MODEL_ID)\n", "\n", "if not model_info:\n", - " raise Exception(f\"\"\"Failed to fetch model info for {MODEL_ID} from Hugging Face Hub. Please ensure you are copying the full Model id as shown in the screen shot above.\n", + " raise Exception(\n", + " f\"\"\"Failed to fetch model info for {MODEL_ID} from Hugging Face Hub. Please ensure you are copying the full Model id as shown in the screen shot above.\n", "\n", " Please check the following:\n", " 1. Is the model id from Hugging face or somewhere else? If it is somewhere else, please use the model id from Hugging Face or continue importing the model manually.\n", " 2. Is additional authentication required to access the model such as a token? If so, please use the manual import method.\n", " 3. Are you behind a firewall that is blocking access to the model? If so, please update the firewall rules to allow access to hugging face.\n", - " \"\"\")" + " \"\"\"\n", + " )" ] }, {