aws / amazon-sagemaker-examples

Example 📓 Jupyter notebooks that demonstrate how to build, train, and deploy machine learning models using 🧠 Amazon SageMaker.
https://sagemaker-examples.readthedocs.io
Apache License 2.0
10.02k stars 6.75k forks source link

[Bug Report] Can't load xgboost models created with Sagemaker Estimator #2952

Open jruokola opened 3 years ago

jruokola commented 3 years ago

Stumbled upon this while trying to evaluate my xgboost model ` model = pickle.load(open("./data/xgboost-model", "rb"))

UnpicklingError: unpickling stack underflow`

I get this same error while doing evaluation with a script processor on SageMaker Pipelines or trying to run it locally.

I'm running the abalone example evaluation script

athewsey commented 2 years ago

Just ran in to this issue too when experimenting with upgrading a Pipelines example from XGBoost v1.0-1 to 1.3-1. As discussed here on StackOverflow, it seems that in v1.3+ XGBoost changed the default model save format and therefore the way you'll need to load the artifact.

In particular, this answer using load_model instead of pickle seemed to work well for me:

import xgboost

model_path = "/opt/ml/processing/model/model.tar.gz"
with tarfile.open(model_path) as tar:
    tar.extractall(path="..")

model = xgboost.Booster()
model.load_model("xgboost-model")