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

convert_xgboost - AssertionError: Missing required property "tree_info". #601

Open
ShuningL opened this issue Jan 4, 2023 · 8 comments
Open

Comments

@ShuningL
Copy link

ShuningL commented Jan 4, 2023

I was trying to run the sample code of convert_xgboost(onnxmltools/docs/examples/plot_convert_xgboost.py), and I got an error ["AssertionError: Missing required property "tree_info".] which is only for Dmatrix ( for sklearn model, it's ok).
Looking forward to your responses.

------------------------- The Output is as follow ----------------------------

XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,
colsample_bynode=1, colsample_bytree=1, gamma=0, gpu_id=-1,
importance_type='gain', interaction_constraints='',
learning_rate=0.300000012, max_delta_step=0, max_depth=6,
min_child_weight=1, missing=nan, monotone_constraints='()',
n_estimators=100, n_jobs=0, num_parallel_tree=1,
objective='multi:softprob', random_state=0, reg_alpha=0,
reg_lambda=1, scale_pos_weight=None, subsample=1,
tree_method='exact', validate_parameters=1, verbosity=None)
[1 2 2 0 2 0 0 1 0 1 1 2 2 1 2 2 2 2 2 2 0 1 2 0 2 1 1 0 2 2 2 1 2 0 0 2 2
2]

AssertionError Traceback (most recent call last)
Input In [10], in <cell line: 71>()
68 bst = train_xgb(param, dtrain, 10)
70 initial_type = [('float_input', FloatTensorType([None, 4]))]
---> 71 onx = convert_xgboost(bst, initial_types=initial_type)
73 sess = rt.InferenceSession(onx.SerializeToString())
74 input_name = sess.get_inputs()[0].name

File ~/miniconda3/envs/mlflow/lib/python3.8/site-packages/onnxmltools/convert/main.py:177, in convert_xgboost(*args, **kwargs)
174 raise RuntimeError('xgboost is not installed. Please install xgboost to use this feature.')
176 from .xgboost.convert import convert
--> 177 return convert(*args, **kwargs)

File ~/miniconda3/envs/mlflow/lib/python3.8/site-packages/onnxmltools/convert/xgboost/convert.py:39, in convert(model, name, initial_types, doc_string, target_opset, targeted_onnx, custom_conversion_functions, custom_shape_calculators)
36 name = str(uuid4().hex)
38 if isinstance(model, xgboost.Booster):
---> 39 model = WrappedBooster(model)
40 target_opset = target_opset if target_opset else get_maximum_opset_supported()
41 topology = parse_xgboost(model, initial_types, target_opset, custom_conversion_functions, custom_shape_calculators)

File ~/miniconda3/envs/mlflow/lib/python3.8/site-packages/onnxmltools/convert/xgboost/parse.py:85, in WrappedBooster.init(self, booster)
83 def init(self, booster):
84 self.booster
= booster
---> 85 self.kwargs = get_attributes(booster)
87 if self.kwargs['num_class'] > 0:
88 self.classes
= self._generate_classes(self.kwargs)

File ~/miniconda3/envs/mlflow/lib/python3.8/site-packages/onnxmltools/convert/xgboost/_parse.py:35, in _get_attributes(booster)
33 reg = re.compile(b'("tree_info":\[[0-9,]*\])')
34 objs = list(set(reg.findall(bstate)))
---> 35 assert len(objs) == 1, 'Missing required property "tree_info".'
36 tree_info = json.loads("{{{}}}".format(objs[0].decode('ascii')))['tree_info']
37 num_class = len(set(tree_info))

AssertionError: Missing required property "tree_info".

---------------------------------------------------------------

@xadupre
Copy link
Collaborator

xadupre commented Jan 16, 2023

I cannot replicate this issue with the latest development version. This should be fixed with the next release.

@xiaohk
Copy link

xiaohk commented Jan 30, 2023

I am having the same issue with v1.11.1 (on an M1 mac).

@StephaneFaure
Copy link

I am having the same issue with1.11.1 processing XGBoost core 1.6.2 model (not sklearn).

@hardikrj
Copy link

hardikrj commented Mar 6, 2023

@xadupre I am facing this with the latest v1.11.2 as well. These are the version I have on my system.

onnx==1.13.0
onnxconverter-common==1.13.0
onnxmltools==1.11.2
onnxruntime==1.14.0
onnxruntime-extensions==0.4.2
skl2onnx==1.13
xgboost==1.6.2

@RhysU
Copy link

RhysU commented Mar 10, 2023

This bug was reported on v1.11.1, @xadupre indicated it was fixed on the development branch, and some folks are now seeing it on the subsequently released v1.11.2. My hunch is it's worth checking:

  1. Does this work on the development branch?
  2. Does the same thing work on 1.11.2?
  3. Did the same thing work on 1.11.1?

There may be something missing in terms of the recreate. It's odd to see works-for-me not make it into a subsequent cut.

@hardikrj
Copy link

Hi @xadupre , can you please confirm the version in which this issue is fixed?

@xadupre
Copy link
Collaborator

xadupre commented Mar 15, 2023

I checked in PR #597 the example works. It is working with xgboost 1.7.4. If it is not working in your case, is it possible to share an example which fails or point me to one?

@hardikrj
Copy link

@xadupre Thanks. Seems like an issue with the xgboost version. Worked fine with 1.7.4

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

6 participants