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