After successfully training your ML model and after selecting the best run, you are about to deploy it as a web service to the production environment.
Because you anticipate a massive amount of requests to be handled by the service, you choose AKS as a compute target.
You are using the following script to deploy your model:
# deploy model inference_config = InferenceConfig(runtime= "python", entry_script=script_file, conda_file=env_file) deployment_config = AciWebservice.deploy_configuration(cpu_cores = 1, memory_gb = 4) service_name = "fraud-detection-service" service = Model.deploy(ws, service_name, [model], inference_config, deployment_config) service.wait_for_deployment(True) print(service.state)Running the deployment script results in the service state “Failed”.You have a look at your scoring script and you suspect that something is wrong with model path in the init() function:
# scoring script ... def init(): global model # Get the path to the deployed model file and load it model_path = Model.get_model_path('fraud_detection_model') model = joblib.load(model_path) # Called when a request is received def run(raw_data): # Get the input data as a numpy array data = np.array(json.loads(raw_data)['data']) # Get a prediction from the model predictions = model.predict(data) # Get the classnames for predictions classnames = ['non-fraud', 'fraud'] predicted_classes = [] for prediction in predictions: predicted_classes.append(classnames[prediction]) # Return the predictions as JSON return json.dumps(predicted_classes)Is this the best track to spot the error?
Click on the arrows to vote for the correct answer
A. B.Answer: A.
Option A is CORRECT because you experienced the error while deploying the service, which means that the deployment process failed.
It typically occurs when the get_model_path() function which is called during the deployment while initializing the model cannot locate the model's path for some reason.
Therefore, you should investigate this first.
Option B is incorrect because the error occurred during the deployment of the service, which means that it is not a data-related problem (if it was, it would occur during inference phase, while running the service)
Since the deployment has failed, the problem is not inference-related.
Reference:
Yes, suspecting the model path in the init()
function is a reasonable first step to identify the error.
The error occurred during the deployment of the model as a web service to Azure Kubernetes Service (AKS). The script used to deploy the model uses the Azure Machine Learning SDK to create an inference configuration object (inference_config
) and a deployment configuration object (deployment_config
). The Model.deploy()
function is then used to deploy the model to the specified compute target (AKS). If the deployment fails, it is likely that there is an error in one of these objects or in the model file that is being deployed.
Looking at the scoring script provided, it is clear that the init()
function is responsible for loading the model from the specified path. The Model.get_model_path()
function retrieves the path to the deployed model file. In this case, the path is specified as fraud_detection_model
, which is the name of the model that was registered with the Azure Machine Learning service during the training phase. If there is an error in the path specified in the init()
function, the model will not be loaded correctly, and the web service will fail.
Therefore, it is a good idea to check if the fraud_detection_model
model has been registered correctly and if the model file is present in the expected location. It is also possible to add some print statements to the scoring script to see where the error occurs and what the value of model_path
is at each step. This will help to identify the source of the error and correct it.