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:
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:
Some hint?
Even I got the same error with these ways in my environment.
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.
Then model loaded successfully.
Output:
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.