For deploying ML models to Azure you need to follow the stages as mentioned
Pre-requisites for deployment of ML model to Azure
- Creating the Azure Machine Learning workspace
- A trained ML Model
- Using the Azure CLI extension for Machine learning services
- A docker running machine
- 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
- a local file or
!wget https://aka.ms/bidaf-9-model -o model.onnx
!az ml model register -n bidaf_onnx -p ./model.onnx
- 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
- 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}”
- 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
- 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
- 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
Ready to experience the full power of cloud technology?
Our cloud experts will speed up cloud deployment, and make your business more efficient.
- 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
- 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
}