Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion tutorials/get-started-notebooks/deploy-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -434,18 +434,26 @@
},
"outputs": [],
"source": [
"from azure.ai.ml.entities import ManagedOnlineDeployment\n",
"from azure.ai.ml.entities import ManagedOnlineDeployment, Environment, CodeConfiguration\n",
"\n",
"# Choose the latest version of the registered model for deployment\n",
"model = ml_client.models.get(name=registered_model_name, version=latest_model_version)\n",
"\n",
"# define the deployment environment\n",
"env = Environment(\n",
" conda_file=\"./deploy/deployment-env.yaml\",\n",
" image=\"mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu22.04:latest\",\n",
")\n",
"\n",
"# define an online deployment\n",
"# if you run into an out of quota error, change the instance_type to a comparable VM that is available.\n",
"# Learn more on https://azure.microsoft.com/en-us/pricing/details/machine-learning/.\n",
"blue_deployment = ManagedOnlineDeployment(\n",
" name=\"blue\",\n",
" endpoint_name=online_endpoint_name,\n",
" model=model,\n",
" environment=env,\n",
" code_configuration=CodeConfiguration(code=\"./deploy\", scoring_script=\"score.py\"),\n",
" instance_type=\"Standard_DS3_v2\",\n",
" instance_count=1,\n",
")"
Expand Down Expand Up @@ -637,13 +645,21 @@
"# pick the model to deploy. Here you use the latest version of the registered model\n",
"model = ml_client.models.get(name=registered_model_name, version=latest_model_version)\n",
"\n",
"# define the deployment environment\n",
"env = Environment(\n",
" conda_file=\"./deploy/deployment-env.yaml\",\n",
" image=\"mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu22.04:latest\",\n",
")\n",
"\n",
"# define an online deployment using a more powerful instance type\n",
"# if you run into an out of quota error, change the instance_type to a comparable VM that is available.\n",
"# Learn more on https://azure.microsoft.com/en-us/pricing/details/machine-learning/.\n",
"green_deployment = ManagedOnlineDeployment(\n",
" name=\"green\",\n",
" endpoint_name=online_endpoint_name,\n",
" model=model,\n",
" environment=env,\n",
" code_configuration=CodeConfiguration(code=\"./deploy\", scoring_script=\"score.py\"),\n",
" instance_type=\"Standard_F4s_v2\",\n",
" instance_count=1,\n",
")\n",
Expand Down
12 changes: 12 additions & 0 deletions tutorials/get-started-notebooks/deploy/deployment-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
channels:
- conda-forge
dependencies:
- python=3.9.18
- pip
- pip:
- azureml-inference-server-http
- scikit-learn==0.24.2
- numpy==1.23.5
- scipy==1.9.3
- cloudpickle==2.2.0
name: deployment-env
22 changes: 22 additions & 0 deletions tutorials/get-started-notebooks/deploy/score.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
import json
import pickle
import numpy as np


def init():
global model
model_dir = os.getenv("AZUREML_MODEL_DIR")
# Handle possible directory layouts
model_path = os.path.join(model_dir, "model.pkl")
if not os.path.exists(model_path):
model_path = os.path.join(model_dir, "credit_defaults_model", "model.pkl")
with open(model_path, "rb") as f:
model = pickle.load(f)


def run(raw_data):
data = json.loads(raw_data)
input_data = data.get("input_data", data)
result = model.predict(np.array(input_data["data"]))
return json.dumps(result.tolist())
Loading