Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] "Unknown tree updater grow_gpu_hist" when loading a GPU trained model on a non-GPU machine #5291

Closed
tsp-kucbd opened this issue Feb 6, 2020 · 2 comments

Comments

@tsp-kucbd
Copy link

We train with GPU on our Linux machine (tree_method='gpu_hist') and pickle dump the model to a json file (xgboost version 1.0.0rc1). Loading the generated model file on a non-GPU machine (MacOS) causes following error:
xgboost.core.XGBoostError: [17:35:27] /tmp/pip-install-fjnd8mac/xgboost/xgboost/src/tree/tree_updater.cc:20: Unknown tree updater grow_gpu_hist

When training with CPU only then there is no error and we can load and use the model on e.g. MacOS, as we could before with xgboost version 0.90.
(also enable_experimental_json_serialization = True does not make any difference)

What seems to work is to manually change xgb.get_booster().set_param({'updater':''}) before saving the model file and then change it back to the original value. But I am not sure how this affects the model for sub-sequential runs.

Steps to reproduce:
On the GPU machine:

#!/usr/bin/env python

import xgboost as xgb
from sklearn.datasets import load_boston
import pandas as pd
from sklearn.model_selection import train_test_split
import pickle
import platform

boston = load_boston()
data = pd.DataFrame(boston.data)
data.columns = boston.feature_names
data['PRICE'] = boston.target

print("xgboost version %s on %s" % (xgb.__version__,  platform.uname()[0]))
X, y = data.iloc[:,:-1],data.iloc[:,-1]
data_dmatrix = xgb.DMatrix(data=X,label=y)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=123)
xg_reg = xgb.XGBRegressor(objective ='reg:squarederror',  n_estimators = 10, tree_method='gpu_hist',  enable_experimental_json_serialization = True)
xg_reg.fit(X_train,y_train)

outfile = "test.model.json." + platform.uname()[0]
print("Writing to", outfile)
with open(outfile, 'wb') as fd: pickle.dump(xg_reg, fd)

then transfer the test.model.json.Linux file to MacOS

#!/usr/bin/env python

import xgboost as xgb
import platform

import pickle
print("xgboost version %s on %s" % (xgb.__version__,  platform.uname()[0]))
model_file = 'test.model.json.Linux'
print("reading", model_file)
model = pickle.load(open(model_file, 'rb'))
print("Model", model)

@tsp-kucbd tsp-kucbd changed the title "Unknown tree updater grow_gpu_hist" when loading a GPU trained model on a non-GPU machine [Python] "Unknown tree updater grow_gpu_hist" when loading a GPU trained model on a non-GPU machine Feb 6, 2020
@trivialfis
Copy link
Member

@kucbd Right now my suggestion is wait for 1.0 release. It fixes all kind of configuration/model loading quirks. #5253

@trivialfis
Copy link
Member

trivialfis commented Feb 14, 2020

Both 1.0 release and master branch have the fix. Closing.

@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants