SlideShare a Scribd company logo
Azure ML Deployment using ACI
Components – Directory Structure
1. echo_score.py has py
extension while train.ipynb is
a notebook file
2. Data is loaded manually into
data folder. However, the
right way is to first create a
data store and then data
asset. Post that, we can use
that data asset in the code.
3. Train.ipynb has to run on
Python 3.10 SDK V2 since
there were issues installing
sklearn lib in earlier SDK
versions.
Train File – Define Workspace
# Define workspace variables
from azureml.core import Workspace, Dataset
import numpy as np
import pandas as pd
secret_subscription_id_value = ‘XXXXXXXXXXX'
resource_group = ‘XXXXXXXXXXX'
workspace_name = ‘XXXXXXXXXXX'
workspace = Workspace(secret_subscription_id_value, resource_group, workspace_name)
1. Id values can be stored in key vault. However, that code did not work.
Train File – Save Model Artifacts
# Save the model and its artifacts
import joblib
joblib.dump(kmeans, "../model_artifacts/kmeans.joblib")
joblib.dump(enc, "../model_artifacts/enc.bin", compress=True)
joblib.dump(model_rf, "../model_artifacts/taxi_demand_prediction.joblib")
1. At the end of training, you store the model artifacts into Azure ML compute.
This is referred in the scoring file.
Train File – Register Model
# Register model
from azureml.core.model import Model
import urllib.request
model = Model.register(workspace,
model_name="taxi_demand_prediction",
model_path="../model_artifacts/")
1. When you register the model,
all the artifacts stored in Azure
ML compute instance are
registered as a folder in the
model registry (view on the
right)
Train File – Environment Setup
# Environment setup
from azureml.core import Environment
from azureml.core.model import InferenceConfig
env = Environment(name="taxi_demand_prediction")
python_packages = ['azure-ml-api-sdk','numpy', 'pandas', 'seaborn', 'matplotlib',
'scipy', 'scikit-learn', 'joblib','requests']
for package in python_packages:
env.python.conda_dependencies.add_pip_package(package)
1. While setting up environment for inference, the first lib “'azure-ml-api-sdk”
required to be installed as well.
Train File – Inference Config
# Inference configuration setup
inference_config = InferenceConfig(
environment=env,
source_directory="../source_dir",
entry_script="echo_score.py",
)
Train File – Local Deployment
# Local Deployment
from azureml.core.webservice import LocalWebservice
from azureml.core.webservice import AciWebservice
deployment_config = LocalWebservice.deploy_configuration(port=6789)
service = Model.deploy(
workspace,
"taxidemandprediction",
[model],
inference_config,
deployment_config,
overwrite=True,
)
service.wait_for_deployment(show_output=True)
print(service.get_logs())
1. There should be no underscore in
the deployment name. Hence, we
the name is “taxidemandprediction”
Train File – Local Testing
# Local Testing
import requests
import json
uri = service.scoring_uri
requests.get("http://localhost:6789")
headers = {"Content-Type": "application/json"}
data = {"pickup_latitude":"-
73.980492","pickup_longitude":"40.777981","tpep_pickup_datetime":"2020-02-13
23:40:00"}
data = json.dumps(data)
response = requests.post(uri, data=data, headers=headers)
print(response.json())
service.get_logs() # Get logs
Train File – Remote ACI Deployment
# Remote Deployment
deployment_config = AciWebservice.deploy_configuration(
cpu_cores=0.5, memory_gb=1, auth_enabled=True
)
service = Model.deploy(
workspace,
"taxidemandprediction",
[model],
inference_config,
deployment_config,
overwrite=True,
)
service.wait_for_deployment(show_output=True)
print(service.get_logs())
1. ACI is a serverless setup made by Azure
for low cost real time deployments.
Alternatives are Kubernetes.
2. For batch inferences, we can use azure
compute itself.
3. We can also do “bring your own
container” and only use Azure for
deployment.
Train File – ACI Remote Testing
import requests
import json
from azureml.core import Webservice
service = Webservice(workspace=workspace, name="taxidemandprediction")
scoring_uri = service.scoring_uri
# If the service is authenticated, set the key or token
key, _ = service.get_keys()
# Set the appropriate headers
headers = {"Content-Type": "application/json"}
headers["Authorization"] = f"Bearer {key}"
# Make the request and display the response and logs
data = {"pickup_latitude":"-
73.980492","pickup_longitude":"40.777981","tpep_pickup_datetime":"2020-02-13 23:40:00"}
data = json.dumps(data)
resp = requests.post(scoring_uri, data=data, headers=headers)
print(resp.text)
Other issues faced
1. The model path given in score file refers to the path in model
registry. The path added was
“taxi_demand_prediction/model_artifacts/kmeans.joblib” before
and we changed it to “model_artifacts/kmeans.joblib”. Similar
changes were done to other paths in score file.
2. Always make sure to do local testing on compute and then deploy on
ACI. The logs are detailed during local testing and it is easier to
debug.
Key views - Models
Key views – Endpoints
1. End point also
provides a Rest API
for the deployment
that can be queried
from outside Azure
setup.
Key views – Compute used for Training

More Related Content

Similar to AzureMLDeployment.ppt

Automation in angular js
Automation in angular jsAutomation in angular js
Automation in angular js
Marcin Wosinek
 
NodeJS and ExpressJS.pdf
NodeJS and ExpressJS.pdfNodeJS and ExpressJS.pdf
NodeJS and ExpressJS.pdf
ArthyR3
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NET
Gianluca Carucci
 
I want my model to be deployed ! (another story of MLOps)
I want my model to be deployed ! (another story of MLOps)I want my model to be deployed ! (another story of MLOps)
I want my model to be deployed ! (another story of MLOps)
AZUG FR
 
Taking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) FamilyTaking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) Family
Ben Hall
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
 
Python Google Cloud Function with CORS
Python Google Cloud Function with CORSPython Google Cloud Function with CORS
Python Google Cloud Function with CORS
RapidValue
 
Rapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirageRapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirage
Krzysztof Bialek
 
Using Task Queues and D3.js to build an analytics product on App Engine
Using Task Queues and D3.js to build an analytics product on App EngineUsing Task Queues and D3.js to build an analytics product on App Engine
Using Task Queues and D3.js to build an analytics product on App Engine
River of Talent
 
Celery with python
Celery with pythonCelery with python
Celery with python
Alexandre González Rodríguez
 
Deploy and Serve Model from Azure Databricks onto Azure Machine Learning
Deploy and Serve Model from Azure Databricks onto Azure Machine LearningDeploy and Serve Model from Azure Databricks onto Azure Machine Learning
Deploy and Serve Model from Azure Databricks onto Azure Machine Learning
Databricks
 
Building a scalable web application by combining modern front-end stuff and A...
Building a scalable web application by combining modern front-end stuff and A...Building a scalable web application by combining modern front-end stuff and A...
Building a scalable web application by combining modern front-end stuff and A...
Chris Klug
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
Ludmila Nesvitiy
 
NodeJs
NodeJsNodeJs
NodeJs
dizabl
 
Practical Google App Engine Applications In Py
Practical Google App Engine Applications In PyPractical Google App Engine Applications In Py
Practical Google App Engine Applications In Py
Eric ShangKuan
 
Alex Casalboni - Configuration management and service discovery - Codemotion ...
Alex Casalboni - Configuration management and service discovery - Codemotion ...Alex Casalboni - Configuration management and service discovery - Codemotion ...
Alex Casalboni - Configuration management and service discovery - Codemotion ...
Codemotion
 
Prompt engineering for iOS developers (How LLMs and GenAI work)
Prompt engineering for iOS developers (How LLMs and GenAI work)Prompt engineering for iOS developers (How LLMs and GenAI work)
Prompt engineering for iOS developers (How LLMs and GenAI work)
Andrey Volobuev
 
Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.js
davidchubbs
 
Viktor Tsykunov "Microsoft AI platform for every Developer"
Viktor Tsykunov "Microsoft AI platform for every Developer"Viktor Tsykunov "Microsoft AI platform for every Developer"
Viktor Tsykunov "Microsoft AI platform for every Developer"
Lviv Startup Club
 

Similar to AzureMLDeployment.ppt (20)

Automation in angular js
Automation in angular jsAutomation in angular js
Automation in angular js
 
NodeJS and ExpressJS.pdf
NodeJS and ExpressJS.pdfNodeJS and ExpressJS.pdf
NodeJS and ExpressJS.pdf
 
Future Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NETFuture Decoded - Node.js per sviluppatori .NET
Future Decoded - Node.js per sviluppatori .NET
 
I want my model to be deployed ! (another story of MLOps)
I want my model to be deployed ! (another story of MLOps)I want my model to be deployed ! (another story of MLOps)
I want my model to be deployed ! (another story of MLOps)
 
Taking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) FamilyTaking advantage of the Amazon Web Services (AWS) Family
Taking advantage of the Amazon Web Services (AWS) Family
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
Python Google Cloud Function with CORS
Python Google Cloud Function with CORSPython Google Cloud Function with CORS
Python Google Cloud Function with CORS
 
Django
DjangoDjango
Django
 
Rapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirageRapid prototyping and easy testing with ember cli mirage
Rapid prototyping and easy testing with ember cli mirage
 
Using Task Queues and D3.js to build an analytics product on App Engine
Using Task Queues and D3.js to build an analytics product on App EngineUsing Task Queues and D3.js to build an analytics product on App Engine
Using Task Queues and D3.js to build an analytics product on App Engine
 
Celery with python
Celery with pythonCelery with python
Celery with python
 
Deploy and Serve Model from Azure Databricks onto Azure Machine Learning
Deploy and Serve Model from Azure Databricks onto Azure Machine LearningDeploy and Serve Model from Azure Databricks onto Azure Machine Learning
Deploy and Serve Model from Azure Databricks onto Azure Machine Learning
 
Building a scalable web application by combining modern front-end stuff and A...
Building a scalable web application by combining modern front-end stuff and A...Building a scalable web application by combining modern front-end stuff and A...
Building a scalable web application by combining modern front-end stuff and A...
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
 
NodeJs
NodeJsNodeJs
NodeJs
 
Practical Google App Engine Applications In Py
Practical Google App Engine Applications In PyPractical Google App Engine Applications In Py
Practical Google App Engine Applications In Py
 
Alex Casalboni - Configuration management and service discovery - Codemotion ...
Alex Casalboni - Configuration management and service discovery - Codemotion ...Alex Casalboni - Configuration management and service discovery - Codemotion ...
Alex Casalboni - Configuration management and service discovery - Codemotion ...
 
Prompt engineering for iOS developers (How LLMs and GenAI work)
Prompt engineering for iOS developers (How LLMs and GenAI work)Prompt engineering for iOS developers (How LLMs and GenAI work)
Prompt engineering for iOS developers (How LLMs and GenAI work)
 
Build Web Apps using Node.js
Build Web Apps using Node.jsBuild Web Apps using Node.js
Build Web Apps using Node.js
 
Viktor Tsykunov "Microsoft AI platform for every Developer"
Viktor Tsykunov "Microsoft AI platform for every Developer"Viktor Tsykunov "Microsoft AI platform for every Developer"
Viktor Tsykunov "Microsoft AI platform for every Developer"
 

Recently uploaded

Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
John Andrews
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
axoqas
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
Subhajit Sahu
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
pchutichetpong
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Subhajit Sahu
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
oz8q3jxlp
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
NABLAS株式会社
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
nscud
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
benishzehra469
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
slg6lamcq
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
haila53
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
AbhimanyuSinha9
 
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
ahzuo
 
Predicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Predicting Product Ad Campaign Performance: A Data Analysis Project PresentationPredicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Predicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Boston Institute of Analytics
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
ewymefz
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
ewymefz
 

Recently uploaded (20)

Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
 
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
 
Predicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Predicting Product Ad Campaign Performance: A Data Analysis Project PresentationPredicting Product Ad Campaign Performance: A Data Analysis Project Presentation
Predicting Product Ad Campaign Performance: A Data Analysis Project Presentation
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证成绩单
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
 

AzureMLDeployment.ppt

  • 2. Components – Directory Structure 1. echo_score.py has py extension while train.ipynb is a notebook file 2. Data is loaded manually into data folder. However, the right way is to first create a data store and then data asset. Post that, we can use that data asset in the code. 3. Train.ipynb has to run on Python 3.10 SDK V2 since there were issues installing sklearn lib in earlier SDK versions.
  • 3. Train File – Define Workspace # Define workspace variables from azureml.core import Workspace, Dataset import numpy as np import pandas as pd secret_subscription_id_value = ‘XXXXXXXXXXX' resource_group = ‘XXXXXXXXXXX' workspace_name = ‘XXXXXXXXXXX' workspace = Workspace(secret_subscription_id_value, resource_group, workspace_name) 1. Id values can be stored in key vault. However, that code did not work.
  • 4. Train File – Save Model Artifacts # Save the model and its artifacts import joblib joblib.dump(kmeans, "../model_artifacts/kmeans.joblib") joblib.dump(enc, "../model_artifacts/enc.bin", compress=True) joblib.dump(model_rf, "../model_artifacts/taxi_demand_prediction.joblib") 1. At the end of training, you store the model artifacts into Azure ML compute. This is referred in the scoring file.
  • 5. Train File – Register Model # Register model from azureml.core.model import Model import urllib.request model = Model.register(workspace, model_name="taxi_demand_prediction", model_path="../model_artifacts/") 1. When you register the model, all the artifacts stored in Azure ML compute instance are registered as a folder in the model registry (view on the right)
  • 6. Train File – Environment Setup # Environment setup from azureml.core import Environment from azureml.core.model import InferenceConfig env = Environment(name="taxi_demand_prediction") python_packages = ['azure-ml-api-sdk','numpy', 'pandas', 'seaborn', 'matplotlib', 'scipy', 'scikit-learn', 'joblib','requests'] for package in python_packages: env.python.conda_dependencies.add_pip_package(package) 1. While setting up environment for inference, the first lib “'azure-ml-api-sdk” required to be installed as well.
  • 7. Train File – Inference Config # Inference configuration setup inference_config = InferenceConfig( environment=env, source_directory="../source_dir", entry_script="echo_score.py", )
  • 8. Train File – Local Deployment # Local Deployment from azureml.core.webservice import LocalWebservice from azureml.core.webservice import AciWebservice deployment_config = LocalWebservice.deploy_configuration(port=6789) service = Model.deploy( workspace, "taxidemandprediction", [model], inference_config, deployment_config, overwrite=True, ) service.wait_for_deployment(show_output=True) print(service.get_logs()) 1. There should be no underscore in the deployment name. Hence, we the name is “taxidemandprediction”
  • 9. Train File – Local Testing # Local Testing import requests import json uri = service.scoring_uri requests.get("http://localhost:6789") headers = {"Content-Type": "application/json"} data = {"pickup_latitude":"- 73.980492","pickup_longitude":"40.777981","tpep_pickup_datetime":"2020-02-13 23:40:00"} data = json.dumps(data) response = requests.post(uri, data=data, headers=headers) print(response.json()) service.get_logs() # Get logs
  • 10. Train File – Remote ACI Deployment # Remote Deployment deployment_config = AciWebservice.deploy_configuration( cpu_cores=0.5, memory_gb=1, auth_enabled=True ) service = Model.deploy( workspace, "taxidemandprediction", [model], inference_config, deployment_config, overwrite=True, ) service.wait_for_deployment(show_output=True) print(service.get_logs()) 1. ACI is a serverless setup made by Azure for low cost real time deployments. Alternatives are Kubernetes. 2. For batch inferences, we can use azure compute itself. 3. We can also do “bring your own container” and only use Azure for deployment.
  • 11. Train File – ACI Remote Testing import requests import json from azureml.core import Webservice service = Webservice(workspace=workspace, name="taxidemandprediction") scoring_uri = service.scoring_uri # If the service is authenticated, set the key or token key, _ = service.get_keys() # Set the appropriate headers headers = {"Content-Type": "application/json"} headers["Authorization"] = f"Bearer {key}" # Make the request and display the response and logs data = {"pickup_latitude":"- 73.980492","pickup_longitude":"40.777981","tpep_pickup_datetime":"2020-02-13 23:40:00"} data = json.dumps(data) resp = requests.post(scoring_uri, data=data, headers=headers) print(resp.text)
  • 12. Other issues faced 1. The model path given in score file refers to the path in model registry. The path added was “taxi_demand_prediction/model_artifacts/kmeans.joblib” before and we changed it to “model_artifacts/kmeans.joblib”. Similar changes were done to other paths in score file. 2. Always make sure to do local testing on compute and then deploy on ACI. The logs are detailed during local testing and it is easier to debug.
  • 13. Key views - Models
  • 14. Key views – Endpoints 1. End point also provides a Rest API for the deployment that can be queried from outside Azure setup.
  • 15. Key views – Compute used for Training