Repository navigation
Validate TreeEnsemble category set indices - #33825
Akshay Sonawane (apsonawane) wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new tests do not detect removal of integer-ID validation, leaving fractional-ID truncation and other invalid category-set IDs untested with a nonempty collection.
1 open issue
What changed in this PR
This PR strengthens category-set index validation in ONNX Runtime’s shared CPU TreeEnsemble implementation, rejecting invalid IDs before category-set access.
Changes:
- Require category-set IDs to be finite, non-negative integers within bounds.
- Validate
BRANCH_MEMBER_BIGSETIDs during initialization and category-set lookup. - Add classifier and regressor regression tests for ID 0 with an empty category-set collection.
| File | Description |
|---|---|
onnxruntime/test/providers/cpu/ml/treeregressor_test.cc |
Adds a float-threshold regressor rejection test. |
onnxruntime/test/providers/cpu/ml/tree_ensembler_classifier_test.cc |
Adds a double-threshold classifier rejection test. |
onnxruntime/core/providers/cpu/ml/tree_ensemble_common.h |
Adds shared ID validation during initialization and lookup. |
Review effort: Balanced
Ti-Tai Wang (titaiwangms)
left a comment
There was a problem hiding this comment.
No blocking issues found in a bounded static review of the diff, surrounding initialization/category-set access, and added tests. The validation precedes category-set indexing. One non-blocking test-coverage suggestion is inline.
Validation scope: static inspection only; I did not build or run the tests or sanitizers.
Tianlei Wu (tianleiwu)
left a comment
There was a problem hiding this comment.
Reviewed current head 47a803c4cbdb31b11a595c47b182bf6ae22014d6. No blocking code findings. The ID checks run before node construction, guard the floating-point-to-size_t conversion, and compare against the original integer set count. The inference lookup remains unchanged. The earlier feedback on float-count rounding, hot-loop overhead, diagnostics, and exception-disabled tests is addressed.
One nonblocking description correction: the PR body still says GetCategorySet was updated to use validation. In the final implementation, validation happens during Init and GetCategorySet retains its direct lookup. Please update that bullet to match the code.
Validation performed:
- Compiled all three modified test translation units with GCC, both normally and with
ORT_NO_EXCEPTIONS,ONNX_NO_EXCEPTIONS, and-fno-exceptions. - Built a focused C++ harness against this head's header, linking existing local ORT CPU dependency archives: 78 checks passed. These exercised float/double IDs, invalid/nonfinite/fractional values, empty and nonempty sets, the
size_tboundary, the 16,777,217-set float-count boundary, and initialization plus membership traversal using both threshold storage paths. - This was focused validation; I did not run a clean full build or the full provider-test suite.
The remaining CI failures appear outside this diff: Web CI reports detached ArrayBuffer errors in browser tests; WebGPU plugin tests report DXGI_ERROR_DEVICE_REMOVED; GPU documentation validation reports generated-document differences.



This pull request improves input validation for category set IDs in the TreeEnsemble operators and adds corresponding unit tests to ensure invalid category set IDs are properly rejected. The key changes include stricter runtime validation and new tests for both classifier and regressor variants.
Input validation improvements:
ValidateCategorySetIdintree_ensemble_common.hto ensure category set IDs are finite, non-negative integers within bounds, and updatedGetCategorySetto use this validation.BRANCH_MEMBER_BIGSETare now validated for correctness.Testing enhancements:
TreeEnsembleClassifierRejectsInvalidCategorySetIdto verify that the classifier operator fails when given an invalid category set ID.TreeEnsembleRegressorRejectsInvalidCategorySetIdto verify that the regressor operator fails when given an invalid category set ID.Other:
<cmath>header to support new validation logic.