* Add files via upload

Adding the new revision of the notebook, renamed so it is more distinctive.

* Delete azureml-getting-started.ipynb

removed the older version

* Formatting notebook to pass smoke test

Co-authored-by: Bala P V <33712765+balapv@users.noreply.github.com>
This commit is contained in:
Frogglew 2022-09-30 12:18:16 -07:00 коммит произвёл GitHub
Родитель a5be309d31
Коммит 308316758d
1 изменённых файлов: 30 добавлений и 170 удалений

Просмотреть файл

@ -6,7 +6,7 @@
"source": [
"# Getting Started: training an image classification model\n",
"\n",
"**Learning Objectives** - By the end of this quickstart tutorial, you'll know how to train an image classification model on Azure ML platform.\n",
"**Learning Objectives** - By the end of this quickstart tutorial, you'll know how to train and deploy an image classification model on Azure Machine Learning studio.\n",
"\n",
"This tutorial covers:\n",
"\n",
@ -66,7 +66,9 @@
"1. Click **...** menu button on the top of Notebook UI, and select **+Create Azure ML Compute Instance**.\n",
"2. **Name** the compute as **cpu-cluster**\n",
"3. Select **CPU** and **STANDARD_DS3_V2**. \n",
"4. Click **Create**\n"
"4. Click **Create**\n",
"\n",
"If you are interested in learning how to create compute via code, see [Azure Machine Learning in a Day](https://github.com/Azure/azureml-examples/blob/main/tutorials/azureml-in-a-day/azureml-in-a-day.ipynb). "
]
},
{
@ -99,7 +101,6 @@
"metadata": {},
"outputs": [],
"source": [
"# create a source folder for the training script\n",
"import os\n",
"\n",
"train_src_dir = \"./src\"\n",
@ -154,7 +155,7 @@
"\n",
" print(\"input data:\", args.data)\n",
" \n",
" credit_df = pd.read_excel(args.data, header=1, index_col=0)\n",
" credit_df = pd.read_csv(args.data, header=1, index_col=0)\n",
"\n",
" mlflow.log_metric(\"num_samples\", credit_df.shape[0])\n",
" mlflow.log_metric(\"num_features\", credit_df.shape[1] - 1)\n",
@ -336,148 +337,41 @@
"\n",
"To deploy a machine learning service, you usually need:\n",
"\n",
"- The model assets (file, metadata) that you want to deploy. You've already registered these assets via MLflow in *main.py*.\n",
"- Some code to run as a service. The code executes the model on a given input request. This entry script receives data submitted to a deployed web service and passes it to the model, then returns the model's response to the client. The script is specific to your model. The entry script must understand the data that the model expects and returns. When using a MLFlow model, as in this tutorial, this script is automatically created for you. Samples of scoring scripts can be found [here](https://github.com/Azure/azureml-examples/tree/sdk-preview/sdk/endpoints/online)."
"- The model assets (file, metadata) that you want to deploy. You've already registered these assets via MLflow in *main.py*. You can find it under **Models** on the left navigation menu on Azure Machine Learning studio. \n",
"- The code that executes the model on a given input request. In this quickstart, you can easily set it up through the endpoint creation UI. If you want to learn more about how to deploy via Azure Machine Learning SDK, see [Azure Machine Learning in a Day](https://github.com/Azure/azureml-examples/blob/main/tutorials/azureml-in-a-day/azureml-in-a-day.ipynb)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Create a new online endpoint**\n",
"\n",
"Now that you have a registered model and an inference script, it's time to create your online endpoint. The endpoint name needs to be unique in the entire Azure region. For this tutorial, you'll create a unique name using UUID.\n",
"\n",
"**Expect the endpoint creation to take approximately 6 to 8 minutes.**"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# import the library\n",
"import uuid\n",
"\n",
"# creating a unique name with current datetime to avoid conflicts\n",
"online_endpoint_name = \"credit-endpoint-\" + str(uuid.uuid4())[:8]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import required libraries\n",
"from azure.ai.ml.entities import (\n",
" ManagedOnlineEndpoint,\n",
" ManagedOnlineDeployment,\n",
" Model,\n",
" Environment,\n",
")\n",
"\n",
"# create an online endpoint\n",
"endpoint = ManagedOnlineEndpoint(\n",
" name=online_endpoint_name,\n",
" description=\"this is an online endpoint\",\n",
" auth_mode=\"key\", # use \"key\" for key-based authentication. Use \"aml_token\" for Azure Machine Learning token-based authentication.\n",
" tags={\n",
" \"training_dataset\": \"credit_defaults\", # these tags are optional\n",
" \"model_type\": \"sklearn.GradientBoostingClassifier\",\n",
" },\n",
")\n",
"\n",
"endpoint = ml_client.begin_create_or_update(endpoint)\n",
"\n",
"print(f\"Endpint {endpoint.name} provisioning state: {endpoint.provisioning_state}\")"
"![](media/endpoint-creation.gif)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once you've created an endpoint, you can retrieve it as below:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# retrieve the endpoint\n",
"endpoint = ml_client.online_endpoints.get(name=online_endpoint_name)\n",
"**Find the endpoint creation wizard on Studio**\n",
"1. Open a duplicate tab (so that you can keep this tutorial open).\n",
"1. On the duplicate tab, select **Endpoints** on the left navigation menu.\n",
"2. Select **+Create** for real-time endpoints.\n",
"\n",
"print(\n",
" f'Endpint \"{endpoint.name}\" with provisioning state \"{endpoint.provisioning_state}\" is retrieved'\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Deploy the model to the endpoint**\n",
"**Endpoint creation & deployment via wizard UI** (this will take approximately 6 to 8 minutes)\n",
"1. Enter a **unique name** for *endpoint name*. We recommend creating a *unique* name with current date/time to avoid conflicts, which could prevent your deployment. Keep all the defaults for the rest. \n",
"2. Next, you need to choose a model to deploy. Select **credit_defaults_model** registered by *main.py* earlier. \n",
"3. Keep all the defaults for deployment configuration.\n",
"1. Select **Standard_DS3_V2** for compute, which is what we configured earlier. Set the instance count to **1**.\n",
"1. Keep all the defaults for the traffic.\n",
"1. Review: review and select **Create**. \n",
"\n",
"Once the endpoint is created, deploy the model with the entry script. Each endpoint can have multiple deployments and direct traffic to these deployments can be specified using rules. Here you'll create a single deployment that handles 100% of the incoming traffic. We have chosen a color name for the deployment, for example, blue, green, red deployments, which is arbitrary.\n",
"![](media/endpoint-test.gif)\n",
"\n",
"You can check the Models page on the Azure Machine Learning studio, to identify the latest version of your registered model. Alternatively, the code below will retrieve the latest version number for you to use."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# let's pick the latest version of the model\n",
"latest_model_version = max(\n",
" [int(m.version) for m in ml_client.models.list(name=registered_model_name)]\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Deploy the latest version of the model**\n",
"\n",
"**Expect this deployment to take approximately 6 to 8 minutes.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# picking the model to deploy. Here we use the latest version of our registered model.\n",
"model = ml_client.models.get(name=registered_model_name, version=latest_model_version)\n",
"\n",
"\n",
"# create an online deployment.\n",
"blue_deployment = ManagedOnlineDeployment(\n",
" name=\"blue\", # we chose color names for the deployment, you can change.\n",
" endpoint_name=online_endpoint_name,\n",
" model=model,\n",
" instance_type=\"Standard_DS3_v2\", # this is the compute we created earlier\n",
" instance_count=1,\n",
")\n",
"\n",
"blue_deployment = ml_client.begin_create_or_update(blue_deployment)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Test with a sample query**\n",
"\n",
"Now that the model is deployed to the endpoint, you can run inference with it.\n",
"\n",
"Create a sample request file following the design expected in the run method in the score script."
"1. Select the endpoint you just created. Make sure the endpoint is created and the model has been deployed to it.\n",
"2. Select the **Test** tab.\n",
"3. Copy & paste the following sample request file into the **Input data to test real-time endpoint** field.\n",
"4. Select **Test**. "
]
},
{
@ -486,19 +380,6 @@
"metadata": {},
"outputs": [],
"source": [
"# create a source folder for the sample query\n",
"deploy_dir = \"./deploy\"\n",
"os.makedirs(deploy_dir, exist_ok=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# write a json query for testing\n",
"%%writefile {deploy_dir}/sample-request.json\n",
"{\n",
" \"input_data\": {\n",
" \"columns\": [\n",
@ -559,20 +440,6 @@
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# test the blue deployment with some sample data\n",
"ml_client.online_endpoints.invoke(\n",
" endpoint_name=online_endpoint_name,\n",
" request_file=\"./deploy/sample-request.json\",\n",
" deployment_name=\"blue\",\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
@ -581,25 +448,18 @@
"\n",
"If you're not going to use the endpoint, delete it to stop using the resource. Make sure no other deployments are using an endpoint before you delete it.\n",
"\n",
"1. Click **Details** on the endpoint page.\n",
"2. Click the **Delete** button.\n",
"\n",
"**Expect this step to take approximately 6 to 8 minutes.**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# delete the endpoint\n",
"ml_client.online_endpoints.begin_delete(name=online_endpoint_name)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.7 64-bit (microsoft store)",
"language": "python",
"name": "python3"
"display_name": "Python 3.10 - SDK V2",
"language": "python",
"name": "python310-sdkv2"
},
"language_info": {
"codemirror_mode": {