azureml when deployment fails from local source directory

MathBarbarian 21 Reputation points
2021-02-18T09:20:50.113+00:00

Running on an Azure ML Studio compute with following SDK version

azure 1.0.1b6.post1
core 1.19.0
train 1.19.0

When I attempt to deploy I get the error that './models/model1.pkl1' is not found. However when I launch python kernel from /source/ and execute the following everything is fine:

from score import *
init()

My directory looks like so:

  • source
    • models
      • model1.pkl
      • model2.pkl
  • score.py
  • exceptions.csv

I define an InferenceConfig and deploy model as such:

aciconfig = AciWebservice.deploy_configuration(cpu_cores=1, 
                                               memory_gb=2, 
                                               tags={"data": "qtc",  "method" : "automl"}, 
                                               description='Estimate order completion time')

env = Environment.get(ws, "AzureML-AutoML").clone('qtc_automl_env')

inference_config = InferenceConfig(entry_script="score.py",
                                   environment=env, source_directory="source")

service = Model.deploy(workspace=ws, 
                       name='qtc-watchtower4-20210106', 
                       models=[], 
                       inference_config=inference_config, 
                       deployment_config=aciconfig,
                       overwrite=True)

service.wait_for_deployment(show_output=True)

What is missing from your code or documentation, or is there a new sdk that I need to update?

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

1 answer

Sort by: Most helpful
  1. MathBarbarian 21 Reputation points
    2021-02-18T15:32:59.69+00:00

    Documentation seems to be inaccurate (at least for azureml.core.__version__ in {'1.19.0', '1.20.0'})

    The /source/[model/] directory in the deployed container is not in the working directory where the script is executed.

    I fixed this by adding a search for my files in the init( method:

        # The top argument for walk  
        topdir = '..'  
      
        # The extension to search for  
        _pkl = '.pkl'  
        _csv = '.csv'  
      
        csv_name = 'exceptions'  
        model_name = 'model1'  
        imputer_name = 'model2'  
        paths = {}  
        for dirpath, dirnames, files in os.walk(topdir):  
            for name in files:  
                if name.lower().endswith(_pkl) and model_name in name:  
                    paths[model_name] = os.path.join(dirpath, name)  
                elif name.lower().endswith(_csv) and csv_name in name:  
                    paths[csv_name] = os.path.join(dirpath, name)  
                elif name.lower().endswith(_pkl) and imputer_name in name:  
                    paths[imputer_name] = os.path.join(dirpath, name)  
          
    

    Then using the respective values in paths to joblib.load( models and pd.read_csv( extra data.

    1 person found this answer helpful.
    0 comments No comments