Skip to content
Open
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
70 changes: 51 additions & 19 deletions tutorials/azureml-in-a-day/azureml-in-a-day.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,21 @@
" - python=3.10\n",
" - numpy=1.26.4\n",
" - pip=24.0\n",
" - setuptools\n",
" - scikit-learn=1.5.1\n",
" - scipy=1.10\n",
" - pandas=1.5.3\n",
" - pip:\n",
" - setuptools\n",
" - inference-schema[numpy-support]==1.3.0\n",
" - xlrd==2.0.1\n",
" - mlflow\n",
" - azureml-mlflow\n",
" - mlflow==2.8.0\n",
" - mlflow-skinny==2.8.0\n",
" - azureml-mlflow==1.51.0\n",
" - psutil\n",
" - tqdm\n",
" - ipykernel~=6.29\n",
" - matplotlib"
" - matplotlib\n"
]
},
{
Expand Down Expand Up @@ -332,7 +335,7 @@
" mlflow.start_run()\n",
"\n",
" # enable autologging\n",
" mlflow.sklearn.autolog()\n",
" mlflow.sklearn.autolog(log_models=False)\n",
"\n",
" ###################\n",
" #<prepare the data>\n",
Expand Down Expand Up @@ -386,18 +389,12 @@
" ##########################\n",
" #<save and register model>\n",
" ##########################\n",
" # Registering the model to the workspace\n",
" print(\"Registering the model via MLFlow\")\n",
" mlflow.sklearn.log_model(\n",
" sk_model=clf,\n",
" registered_model_name=args.registered_model_name,\n",
" artifact_path=args.registered_model_name,\n",
" )\n",
"\n",
" # Saving the model to a file\n",
" # Save model to the outputs directory (auto-captured by AzureML)\n",
" print(\"Saving the model via MLFlow\")\n",
" model_output_path = os.path.join(\"outputs\", args.registered_model_name)\n",
" mlflow.sklearn.save_model(\n",
" sk_model=clf,\n",
" path=os.path.join(args.registered_model_name, \"trained_model\"),\n",
" path=model_output_path,\n",
" )\n",
" ###########################\n",
" #</save and register model>\n",
Expand All @@ -407,7 +404,7 @@
" mlflow.end_run()\n",
"\n",
"if __name__ == \"__main__\":\n",
" main()"
" main()\n"
]
},
{
Expand Down Expand Up @@ -477,7 +474,29 @@
},
"outputs": [],
"source": [
"ml_client.create_or_update(job)"
"returned_job = ml_client.create_or_update(job)\n",
"aml_url = returned_job.studio_url\n",
"print(\"Monitor your job at\", aml_url)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"name": "wait_for_job"
},
"outputs": [],
"source": [
"import time\n",
"\n",
"# Wait for the job to complete\n",
"status = ml_client.jobs.get(returned_job.name).status\n",
"while status not in [\"Completed\", \"Failed\", \"Canceled\"]:\n",
" time.sleep(30)\n",
" status = ml_client.jobs.get(returned_job.name).status\n",
" print(f\"Job status: {status}\")\n",
"\n",
"print(f\"Job completed with status: {status}\")\n"
]
},
{
Expand Down Expand Up @@ -620,10 +639,23 @@
},
"outputs": [],
"source": [
"# Let's pick the latest version of the model\n",
"from azure.ai.ml.entities import Model\n",
"from azure.ai.ml.constants import AssetTypes\n",
"\n",
"# Register the model from the job output\n",
"run_model = Model(\n",
" path=f\"azureml://jobs/{returned_job.name}/outputs/artifacts/paths/outputs/{registered_model_name}/\",\n",
" name=registered_model_name,\n",
" type=AssetTypes.MLFLOW_MODEL,\n",
" description=\"Model created from run.\",\n",
")\n",
"ml_client.models.create_or_update(run_model)\n",
"\n",
"# Get the latest version\n",
"latest_model_version = max(\n",
" [int(m.version) for m in ml_client.models.list(name=registered_model_name)]\n",
")"
")\n",
"print(f\"Registered model version: {latest_model_version}\")\n"
]
},
{
Expand Down Expand Up @@ -658,7 +690,7 @@
" instance_count=1,\n",
")\n",
"\n",
"blue_deployment = ml_client.begin_create_or_update(blue_deployment).result()"
"blue_deployment = ml_client.begin_create_or_update(blue_deployment).result()\n"
]
},
{
Expand Down
Loading