Search code examples
machine-learningyamlazure-machine-learning-service

Debugging AML Model Deployment


I have an ML model (trained locally) in python. Previously the model has been deployed to a Windows IIS server and it's working fine.

Now, I am trying to deploy it as a service on Azure container instance (ACI) with 1 core, and 1 GB of memory. I took references from one and two Microsoft docs. The docs use SDK for all the steps, but I am using the GUI feature from the Azure portal.

After registering the model, I created an entry script and a conda environment YAML file (see below), and uploaded both to "Custom deployment asset" (at Deploy model area).

Unfortunately, after hitting deploy, the Deployment state is stuck at Transitioning state. Even after 4 hours, the state remains the same and there were no Deployment logs too, so I am unable to find what I am doing wrong here.

NOTE: below is just an excerpt of the entry script

import pandas as pd
import pickle
import re, json
import numpy as np
import sklearn

def init():
    global model 
    global classes
    model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'randomForest50.pkl')
    model = pickle.load(open(model_path, "rb"))

    classes = lambda x : ["F", "M"][x]

def run(data):
    try:
        namesList = json.loads(data)["data"]["names"]
        pred = list(map(classes, model.predict(preprocessing(namesList))))
        return str(pred[0])
    except Exception as e:
        error = str(e)
        return error
name: gender_prediction
dependencies:
- python
- numpy
- scikit-learn
- pip:
    - pandas
    - pickle
    - re
    - json

Solution

  • The issue was in the YAML file. The dependencies/libraries in the YAML should be according to conda environment. So, I changed everything accordingly, and it worked.

    Modified YAML file:

    name: gender_prediction
    dependencies:
    - python=3.7
    - numpy
    - scikit-learn
    - pip:
        - azureml-defaults
        - pandas
        - pickle4
        - regex
        - inference-schema[numpy-support]