Deploying ML models to Azure

For deploying ML models to Azure you need to follow the stages as mentioned 

Pre-requisites for deployment of ML model to Azure 

  1. Creating the Azure Machine Learning workspace 
  1. A trained ML Model 
  1. Using the Azure CLI extension for Machine learning services 
  1. A docker running machine 
  1. Register and track the ML model 

Model registration helps you in storing version of your ML model in your workspace on Azure cloud. The registration of the model is done by the name and the version of the model. It is a good practice to provide extra metadata tags during registration. These tags enable easy searching of the model on Azure. Azure ML supports any model loaded with Python 3.5.2 or higher versions. For registering your model, you need resources like a pytorch model file which can represent the specific model and codes executing the model. 

You can register your model from  

  1. a local file or  

!wget https://aka.ms/bidaf-9-model -o model.onnx 

!az ml model register -n bidaf_onnx -p ./model.onnx 

  1. an Azure ML training run 

az ml model register -n bidaf_onnx –asset-path outputs/model.onnx –experiment-name myexperiment –run-id myrunid –tag area=qna 

  1. Creating the entry script 

The entry script is required for accepting the requests, scoring the requests with the ML model and returning the result output. Your entry script should enable you to load your model using the (in (it) function and use the input data to run the model with run function 

import json 

def init(): 

    print(“This is init”) 

def run(data): 

    test = json.loads(data) 

    print(f”received data {test}”) 

    return f”test is {test}” 

  1. Creating the inference configuration 

The inference configuration details the docker containers alongwith files to be used while initialising the web service. The source directory files are pushed to cloud when you start deploying the web service 

  1. Deploy the ML model 

After this, you are fully prepared to deploy the ML model 

!az ml model deploy -n myservice -m model name –overwrite –ic dummyinferenceconfig.json –dc deploymentconfig.json 

!az ml service get-logs -n myservice 

  1. Conduct liveness Request 

To ensure that you have deployed the ML model successfully , you need to conduct a liveness request and a scoring request 

!curl -v http://localhost:32267 

!curl -v -X POST -H “content-type:application/json” -d ‘{“query”: “What color is the fox”, “context”: “The quick brown fox jumped over the lazy dog.”}’ http://localhost:32267/score 

  1. Select a compute target 

Select a compute target based on assessment so that the cost and the availability is optimised for your endpoints that have been deployed 

  1. Re-deploy the model to cloud 

Once you have ensured that your ML model is working fit and fine locally and you have selected the right compute target, it is time for redeployment to cloud. 

The deployment configuration would differ based on the compute target you have selected 

    “computeType”: “aci”, 

    “containerResourceRequirements”: 

    { 

        “cpu”: 0.5, 

        “memoryInGB”: 1.0 

    }, 

    “authEnabled”: true, 

    “sslEnabled”: false, 

    “appInsightsEnabled”: false 

Get free consultation from our tech experts

Get free consultation from our tech experts

Schedule a discussion
Get free consultation from our tech experts
Get free consultation from our tech experts

Related Posts

Aligned to business domains to provide deep expertise to solving and enabling business units
Connect With Us

Request a Consultation