onnxruntime: TreeEnsemble dies due to memory/segmentation errors with large membership values
Describe the issue
I have been having issues with implementing XGBoost conversion with proper categorical feature support. Even with reasonably-sized models, if the membership_values is somewhat large (>50000), the runtime session does not even start, and get killed with kernel-level errors. In my modest 500 KB model with 80000 membership_values, I get:
low swap: killing largest compressed process with pid 32049 (python3.12) and size 151948 MB
Although I cannot share this model, I created below a simple example that can reproduce a segmentation fault for 40000 membership_values, based on the example in the documentation page: https://onnx.ai/onnx/operators/onnx_aionnxml_TreeEnsemble.html
Note that when I implement membership check using many EQ’s and a TreeEnsembleRegressor, it works flawlessly until version 1.20.1, but crashes with the same error in 1.21.0.
To reproduce
import numpy as np
import onnx
import onnxruntime as ort
node = onnx.helper.make_node(
"TreeEnsemble",
["X"],
["Y"],
domain="ai.onnx.ml",
n_targets=4,
aggregate_function=1,
membership_values=onnx.helper.make_tensor(
"membership_values",
onnx.TensorProto.FLOAT,
(40004,),
[1.2, 3.7, 8, 9] * 10000 + [np.nan] + [12, 7] + [np.nan],
),
nodes_missing_value_tracks_true=None,
nodes_hitrates=None,
post_transform=0,
tree_roots=[0],
nodes_modes=onnx.helper.make_tensor(
"nodes_modes",
onnx.TensorProto.UINT8,
(3,),
np.array([0, 6, 6], dtype=np.uint8),
),
nodes_featureids=[0, 0, 0],
nodes_splits=onnx.helper.make_tensor(
"nodes_splits",
onnx.TensorProto.FLOAT,
(3,),
np.array([11, 232344.0, np.nan], dtype=np.float32),
),
nodes_trueleafs=[0, 1, 1],
nodes_truenodeids=[1, 0, 1],
nodes_falseleafs=[1, 0, 1],
nodes_falsenodeids=[2, 2, 3],
leaf_targetids=[0, 1, 2, 3],
leaf_weights=onnx.helper.make_tensor(
"leaf_weights", onnx.TensorProto.FLOAT, (4,), [1, 10, 1000, 100]
),
)
model = onnx.helper.make_model(
onnx.helper.make_graph(
[node],
"test_model",
[onnx.helper.make_tensor_value_info("X", onnx.TensorProto.FLOAT, [None, 4])],
[onnx.helper.make_tensor_value_info("Y", onnx.TensorProto.FLOAT, [None, 4])],
),
producer_name="onnx-example",
ir_version=10,
opset_imports=[onnx.helper.make_opsetid("ai.onnx.ml", 5)],
domain="ai.onnx.ml",
)
providers = ['CPUExecutionProvider']
session = ort.InferenceSession(model.SerializeToString(), providers=providers)
Urgency
Very urgent. I believe if we cannot resolve this in a couple weeks, we will have to stop using ONNX.
Platform
Mac
OS Version
Sonoma 14.7.2
ONNX Runtime Installation
Released Package
ONNX Runtime Version or Commit ID
1.22.0
ONNX Runtime API
Python
Architecture
ARM64
Execution Provider
Default CPU
Execution Provider Library Version
No response
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 19 (10 by maintainers)
I finished my PR. I used unorderst_set (bitset needs to know the number of bits to use in advance). We can optimize the code later. I left the existing code if the set of categories can be masked and introduced a new node rule (BRANCH_MEMBER_BIGSET). It is working fine on the example in this issue. I let you confirm that fits your needs.
I’m working on it right now. I hope to submit a PR by the end of the day.
One function is recursive and the recursivity depth is equal to the number of values in the set of values. The crash comes from a very long call stack.
Thanks for reporting this issue, I’ll have a look tomorrow.