0

i have this problem:

I have trained and registered a ml model via automated machine learning on the Azure Machine Learning studio platform

The result is an XGBoost model that i register without problem or waring in the workspace.

I need to deploy it to a batch endpoint, but with a custom scoring script:

def init():
global model

# AZUREML_MODEL_DIR is an environment variable created during deployment
# The path "model" is the name of the registered model's folder

model_path = os.environ["AZUREML_MODEL_DIR"]
model_file = glob.glob(f"{model_path}/*/*.pkl")[-1]

# load the model
with open(model_file, "rb") as file:
    model = pickle.load(file)

def run(mini_batch: List[str]) -> Union[List[Any], pd.DataFrame]:
results = []

probs = []
for file in mini_batch:
    rows = pd.read_csv(file)
    probs = [el[1] for el in model.predict_proba(rows)]

return pd.DataFrame(probs)

I tried these ways to load the model:

  • By mlflow
  • By pickle

The problem is always the same:

ModuleNotFoundError: No module named 'azureml.training' i tried to read the pkl file and the 'azureml.training' module is required by the model in the first row: [b'\x80\x04\x958\x05\x00\x00\x00\x00\x00\x00\x8c<azureml.training.tabular.models.forecasting_pipeline_wrapper\x94\x8c\x12RegressionPipeline\x94\x93\x94)\x81\x94}\x94 ...

I tried to install all the libraries suggested by documentation:

  • azureml-core
  • azureml-training-core
  • azureml-sdk[train]

Some hint?

  • How you are registering the model? Please give more details on that. Meanwhile try using `mlflow.pyfunc.load_model("")` – JayashankarGS Jun 16 '23 at 14:19
  • I tried with mlflow.pyfunc.load_model, but same problem. The model has been found by autmo ml, it is an xgboost. To register it I used the "register" option, with mlflow type. – Alberto Bertoncini Jun 17 '23 at 21:14

1 Answers1

0

Even I got the same error with these ways in my environment.

enter image description here

enter image description here

enter image description here

This is because, issue with the python version that model saved. So changed my python version to 3.8. Initially it was 3.10 and changed to 3.8.

enter image description here

Then model loaded successfully.

enter image description here

Output:

enter image description here

Maybe you need to give correct python environment while deploying.

While selecting environment to deploy, filter it for python 3.8 or required version for you as below and deploy.

enter image description here

JayashankarGS
  • 1,501
  • 2
  • 2
  • 6