'Problem with init() function for model deployment in Azure

I want to deploy model in Azure but I'm struggling with the following problem.

I have my model registered in Azure. The file with extension .sav is located locally. The registration looks the following:

import urllib.request
from azureml.core.model import Model

# Register model
model = Model.register(ws, model_name="my_model_name.sav", model_path="model/") 

I have my score.py file. The init() function in the file looks like this:

import json
import numpy as np
import pandas as pd
import os
import pickle
from azureml.core.model import Model

 def init():
    
    global model
    model_path = Model.get_model_path(model_name = 'my_model_name.sav', _workspace='workspace_name')
    model = pickle(open(model_path, 'rb'))

But when I try to deploy I se the following error:

"code": "AciDeploymentFailed",
  "statusCode": 400,
  "message": "Aci Deployment failed with exception: Your container application crashed. This may be caused by errors in your scoring file's init() function.
    1. Please check the logs for your container instance: leak-tester-pm. From the AML SDK, you can run print(service.get_logs()) if you have service object to fetch the logs.

And when I run print(service.logs()) I have the following output (I have only one model registered in Azure):

None

Am I doing something wrong with loading model in score.py file?

P.S. The .yml file for the deployment:

name: project_environment
dependencies:
  # The python interpreter version.
  # Currently Azure ML only supports 3.5.2 and later.
- python=3.6.2

- pip:
  - scikit-learn==0.24.2
  - azureml-defaults
  - numpy
  - pickle-mixin
  - pandas
  - xgboost
  - azure-ml-api-sdk
channels:
- anaconda
- conda-forge


Solution 1:[1]

The local inference server allows you to quickly debug your entry script (score.py). In case the underlying score script has a bug, the server will fail to initialize or serve the model. Instead, it will throw an exception & the location where the issues occurred.

There are two possible reasons for the error or exception occurred.

  1. HTTP server issue. Need to troubleshoot it
  2. Docker deployment.

You need to debug the procedure which you followed. In some cases, HTTP server issues will cause the problem of initialization (init())

Check Azure Machine Learning inference HTTP server for better debugging from server perspective.

The docker file mentioned is looking good, but it's better to debug once by the steps mentioned in https://docs.microsoft.com/en-us/azure/machine-learning/how-to-troubleshoot-deployment-local#dockerlog

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SairamTadepalli-MT