Facing issues while deploying ML endpoint

Pradyumn Joshi 20 Reputation points
2024-06-03T18:21:48.1933333+00:00

Hello,

While deploying an ML model as endpoint in AML Studio I am getting this error, which I am not able to reoslve, can someone please help:

I have the artifacts in trainingModel folder under artifacts:

score.py:

import os
import logging
import json
import joblib
from azureml.core.model import Model

def init():
    global model
    global vectorizer
    logging.info(os.getenv("AZUREML_MODEL_DIR"))
    model_path = os.path.join(os.getenv("AZUREML_MODEL_DIR"), "trainingModel/sentimentPredictionModel.pkl")
    vectorizer_path = os.path.join(os.getenv("AZUREML_MODEL_DIR"), "trainingModel/sentimentVectorizer.pkl")
    model = joblib.load(model_path)
    vectorizer = joblib.load(vectorizer_path)
    logging.info("Init complete")
    
def run(raw_data):
    data = json.loads(raw_data)['data']
    text = data['text']
    transformed_text = vectorizer.transform([text])
    prediction = model.predict(transformed_text)
    return json.dumps({"prediction": prediction.tolist()})

Error log:

 warnings.warn(
2024-06-03 17:59:40,857 I [72] azmlinfsrv - AML_FLASK_ONE_COMPATIBILITY is set. Patched Flask to ensure compatibility with Flask 1.
Initializing logger
2024-06-03 17:59:40,858 I [72] azmlinfsrv - Starting up app insights client
2024-06-03 17:59:41,415 I [72] azmlinfsrv.user_script - Found user script at /var/azureml-app/240603232131-4053936724/score.py
2024-06-03 17:59:41,415 I [72] azmlinfsrv.user_script - run() is not decorated. Server will invoke it with the input in JSON string.
2024-06-03 17:59:41,416 I [72] azmlinfsrv.user_script - Invoking user's init function
2024-06-03 17:59:41,742 E [72] azmlinfsrv - User's init function failed
2024-06-03 17:59:41,742 E [72] azmlinfsrv - Encountered Exception Traceback (most recent call last):
  File "/azureml-envs/azureml_85e1b4b3fc1d6a22f42cd4c67433c6d5/lib/python3.8/site-packages/azureml_inference_server_http/server/user_script.py", line 119, in invoke_init
    self._user_init()
  File "/var/azureml-app/240603232131-4053936724/score.py", line 24, in init
    model = joblib.load(model_path)
  File "/azureml-envs/azureml_85e1b4b3fc1d6a22f42cd4c67433c6d5/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 658, in load
    obj = _unpickle(fobj, filename, mmap_mode)
  File "/azureml-envs/azureml_85e1b4b3fc1d6a22f42cd4c67433c6d5/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 577, in _unpickle
    obj = unpickler.load()
  File "/azureml-envs/azureml_85e1b4b3fc1d6a22f42cd4c67433c6d5/lib/python3.8/pickle.py", line 1212, in load
    dispatch[key[0]](self)
  File "/azureml-envs/azureml_85e1b4b3fc1d6a22f42cd4c67433c6d5/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 415, in load_build
    self.stack.append(array_wrapper.read(self))
  File "/azureml-envs/azureml_85e1b4b3fc1d6a22f42cd4c67433c6d5/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 252, in read
    array = self.read_array(unpickler)
  File "/azureml-envs/azureml_85e1b4b3fc1d6a22f42cd4c67433c6d5/lib/python3.8/site-packages/joblib/numpy_pickle.py", line 152, in read_array
    array = pickle.load(unpickler.file_handle)
  File "sklearn/tree/_tree.pyx", line 673, in sklearn.tree._tree.Tree.__setstate__
ValueError: Did not recognise loaded array layout

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/azureml-envs/azureml_85e1b4b3fc1d6a22f42cd4c67433c6d5/lib/python3.8/site-packages/azureml_inference_server_http/server/aml_blueprint.py", line 109, in setup
    self.user_script.invoke_init()
  File "/azureml-envs/azureml_85e1b4b3fc1d6a22f42cd4c67433c6d5/lib/python3.8/site-packages/azureml_inference_server_http/server/user_script.py", line 121, in invoke_init
    raise UserScriptException(ex) from ex
azureml_inference_server_http.server.user_script.UserScriptException: Caught an unhandled exception from the user script

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,662 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amira Bedhiafi 17,791 Reputation points
    2024-06-03T21:47:11.8666667+00:00

    I think there is a version mismatch between the environment where the model was trained and the environment where it is being deployed. Specifically, the ValueError: Did not recognise loaded array layout suggests that the model file (sentimentPredictionModel.pkl) or the vectorizer file (sentimentVectorizer.pkl) were created with a different version of libraries than those available in the deployment environment.

    If you don't have control over the deployment environment, you can specify the necessary packages and their versions in your deployment configuration.


0 additional answers

Sort by: Most helpful