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

XGBoost conversion error: Model is empty #457

Closed
shadimari opened this issue Apr 8, 2021 · 5 comments
Closed

XGBoost conversion error: Model is empty #457

shadimari opened this issue Apr 8, 2021 · 5 comments

Comments

@shadimari
Copy link

I get an error when using the latest version deployed from source code 1.8.0 to convert an XGBoost model trained using early stopping. The error does not occur on v1.7.0, however the old version has a prediction mismatch which was fixed in the latest version (due to best_ntree_limit handling). XGBoost version = 1.3.3

238 if len(attr_pairs['class_treeids']) == 0: --> 239 raise RuntimeError("XGBoost model is empty.")

Model:
XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1, colsample_bynode=1, colsample_bytree=0.75, eval_metric='logloss', gamma=10, gpu_id=-1, importance_type='gain', interaction_constraints='', learning_rate=0.05, max_delta_step=0, max_depth=7, min_child_weight=50, missing=nan, monotone_constraints='()', n_estimators=1000, n_jobs=32, num_parallel_tree=1, random_state=42, reg_alpha=0, reg_lambda=0.005, scale_pos_weight=150, subsample=0.75, tree_method='hist', use_label_encoder=False, validate_parameters=1, verbosity=1)

@shadimari
Copy link
Author

seems support for onnxmltools is no longer active.

@shadimari
Copy link
Author

@xadupre your thoughts are appreciated, am aware you did the fix for v1.7

@xadupre
Copy link
Collaborator

xadupre commented Apr 13, 2021

I assume the traning ended up producing an empty tree. I need to see how XGBoost handles that case, is the tree ignored at inference time, a quick fix is possible then, or does it happen when the problem is binary and then avoids storing class information. Can you tell if it is a binary classification?

@shadimari
Copy link
Author

shadimari commented Apr 13, 2021

yes it is binary classification problem. I dont think the training ended up into an empty tree, because the same trained model is shared across two versions.

Attached is a model dump.
model.txt

@shadimari
Copy link
Author

shadimari commented Apr 14, 2021

@xadupre Here's a code snippet along with a small data file to reproduce the issue. The issue does not occur if the best_ntree_limits ended up equal to n_estimators

import pickle
from xgboost import XGBRegressor, XGBClassifier
from sklearn.model_selection import train_test_split
from onnxmltools.convert import convert_xgboost
from onnxmltools.convert.common.data_types import FloatTensorType

with open('X.sav','rb') as f:
X = pickle.load(f)

with open('y.sav','rb') as f:
y = pickle.load(f)

X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=10)

clr = XGBClassifier(
max_delta_step= 0,
tree_method='hist',
n_estimators = 100,
booster='gbtree',
objective='binary:logistic',
eval_metric='logloss',
learning_rate= 0.1,
gamma=10,
max_depth=7,
min_child_weight=50,
subsample=0.75,
colsample_bytree=0.75,
random_state=42,
verbosity=1)

clr.fit(X_train, y_train, eval_set=[(X_test, y_test)], early_stopping_rounds=40)
initial_type = [('float_input', FloatTensorType([None, 797]))]
onx = convert_xgboost(clr, initial_types=initial_type)

data.zip

xadupre pushed a commit to xadupre/onnxmltools that referenced this issue Apr 15, 2021
Signed-off-by: xavier dupré <xavier.dupre@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants