Pickle Load- File Not Found when deploying using Azure ML Studio

Amber Bhanarkar 1 Reputation point
2022-05-24T06:52:38.97+00:00

I have saved a classifier model with pickle using the following code-

import pickle
with open('skm.pickle', 'wb') as fid:
    pickle.dump(clf, fid) 

Now, during deployment, when I try to load this same model, it is giving an error-

Error:
{
  "code": "AciDeploymentFailed",
  "statusCode": 400,
  "message": "Aci Deployment failed with exception: Error in entry script, FileNotFoundError: [Errno 2] No such file or directory: './skm.pickle', please run print(service.get_logs()) to get details.",
  "details": [
    {
      "code": "CrashLoopBackOff",
      "message": "Error in entry script, FileNotFoundError: [Errno 2] No such file or directory: './skm.pickle', please run print(service.get_logs()) to get details."
    }
  ]
}

This is the score.py file where I am loading the pickle model and the same file is called during deployment. Also note that, all these files (code, pickle file and related files) are in the same directory.

%%writefile sklearnscore.py

import json
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from sklearn.ensemble import RandomForestClassifier
import pickle

# Initialize the deployment environment
def init():
    # read in the model file
    from sklearn.pipeline import Pipeline
    global obj
    with open('./skm.pickle', 'rb') as f:
        obj = pickle.load(f)

I am registering the model using- model = Model.register(ws, model_name="utility15", model_path="./skm.pickle")

And the deployment code is-

service_name = 'my-custom-env-service-4'
sklearn_env = Environment.from_conda_specification(name='sklearn-env', file_path='Sklearn.yaml')

inference_config = InferenceConfig(entry_script='sklearnscore.py', environment=sklearn_env)

aci_config = AciWebservice.deploy_configuration(cpu_cores=1, memory_gb=4,tags={'Createdby':'xyz'})

service = Model.deploy(workspace=ws,
                        name=service_name,
                        models=[model],
                        inference_config=inference_config,
                        deployment_config=aci_config,
                        overwrite=True)
service.wait_for_deployment(show_output=True)

When this script is run, it calls the score.py file and the file not found error comes up for pickle file. I have even tried loading the model without the ./ thing, but the same error comes up.

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

1 answer

Sort by: Most helpful
  1. Ramr-msft 17,826 Reputation points
    2022-05-25T09:13:41.897+00:00

    @Amber Bhanarkar Thanks for the question. Can you please share the sample that you are trying.

    Take a look at this notebook for one way to do this, another way would be to create a yaml file with all of the dependencies:
    https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/explain-model/azure-integration/remote-explanation/explain-model-on-amlcompute.ipynb

    Please run print(service.get_logs()) to get details.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.