-
Notifications
You must be signed in to change notification settings - Fork 278
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 onnx backend inference not working with a single example #676
Comments
I can reproduce this bug and am running into it myself as well. I ran the following code (just changing the input array to import numpy
from xgboost.sklearn import XGBClassifier
from hummingbird.ml import convert
x, y = numpy.random.randn(1000, 10), numpy.random.randint(0, 2, 1000)
clf = XGBClassifier(n_estimators=20)
clf.fit(x, y)
extra_config = {
"tree_implementation": "gemm",
"onnx_target_opset": 14,
}
extra_config["n_features"] = x.shape[1]
onnx_model = convert(
clf,
backend="onnx",
test_input=x[:20],
extra_config=extra_config,
) Notably, looking at this
When running predict, you should also see a warning:
I believe that this issue is related to #656 -- the output of the model is assumed to be a single output, instead of labels and predictions. Adding some debug logic around hummingbird/hummingbird/ml/_topology.py Line 260 in 36ebab4
So we see that |
hm, hacking a fix into the outputs setup, such that
still yields the same error as in OP. This error also presents in For reference, the mentioned bad Transpose node in the graph
backend torch works correctly torch_model = convert(
clf,
backend="torch",
test_input=x[:20],
extra_config=extra_config,
)
torch_model.predict_proba(x[:2])
torch_model.predict_proba(x[:1]) so my sense is that this is a bug in the torch -> onnx export path, since torch is the intermediate representation for the ONNX conversion anyways narrowing further, if you use |
It is not the first time we are having troubles with GEMM and ONNX. @jfrery can you please change the tree implementation from |
Actually we need the Gemm implementation. Maybe we can reopen and we will try to fix this? |
It looks that this is more a problem with the onnx export in pytorch since the torch converter works. Can you open an issue with them showing that torch work, while onnx export fails? We can then use this issue to track the downstream one. |
Here is the code to reproduce:
And here is the error thrown by onnxruntime.
Looking at the onnx graph, it seems that there is a squeeze operation with
axis=None
. With a single example, the input data shape would be (n_trees, 1, n_examples). Without theaxis
being specified, for a single example, the last 2 dimensions are removed which then doesn't match the transpose operation.The text was updated successfully, but these errors were encountered: