amazon-sagemaker-examples icon indicating copy to clipboard operation
amazon-sagemaker-examples copied to clipboard

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

Open jruokola opened this issue 2 years ago • 1 comments

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

jruokola avatar Sep 27 '21 05:09 jruokola

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")

athewsey avatar Mar 21 '22 11:03 athewsey