Update export_model(): Add split_kind field - #698
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## mainline #698 +/- ##
============================================
- Coverage 84.39% 84.35% -0.04%
============================================
Files 75 75
Lines 6862 6867 +5
Branches 557 557
============================================
+ Hits 5791 5793 +2
- Misses 1071 1074 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
betatim
approved these changes
Sep 1, 2026
betatim
left a comment
Contributor
There was a problem hiding this comment.
Looks good to me.
One thing I'd add is a check that the fields in the imported node dtype match what treelite knows. Because the fields need filling treelite needs to know about them. I think right now it would maybe work but give wrong results silently.
Something like this at the top of exporter.py
# Fields of scikit-learn's private Node struct that this exporter knows how to
# handle. If scikit-learn grows a field outside this set we cannot populate it,
# and since we now allocate with scikit-learn's own NODE_DTYPE the dtype check in
# Tree.__setstate__ will no longer catch it -- the field would silently keep its
# zero value. `left_cat_bitset` is knowingly left zeroed: trees with categorical
# splits are rejected before we allocate.
_KNOWN_NODE_FIELDS = frozenset(
{
"left_child",
"right_child",
"feature",
"threshold",
"left_cat_bitset",
"impurity",
"n_node_samples",
"weighted_n_node_samples",
"missing_go_to_left",
"split_kind",
}
)and then a check like this in _export_tree:
unknown_fields = sorted(set(NODE_DTYPE.names) - _KNOWN_NODE_FIELDS)
if unknown_fields:
raise NotImplementedError(
f"scikit-learn {sklearn_version} stores tree node fields that this "
f"version of Treelite does not know how to populate: {unknown_fields}. "
"Exporting would produce a model that predicts incorrectly. "
"Please upgrade Treelite."
)
betatim
reviewed
Sep 1, 2026
betatim
reviewed
Sep 1, 2026
Co-authored-by: Tim Head <betatim@gmail.com>
chyunsu3
added a commit
that referenced
this pull request
Sep 2, 2026
rapids-bot Bot
pushed a commit
to NVIDIA/cuml
that referenced
this pull request
Sep 3, 2026
Fixes #8507 Fixes #8425 Fixes #8537 Fixes #8548 Requires conda-forge/treelite-feedstock#99 The new release of Treelite incoporates the following bug fixes: * Update sklearn exporter for scikit-learn 1.10+ (dmlc/treelite#675) * Fix import for DART in XGBoost 3.3 and 3.4 (dmlc/treelite#688) * Use new Node dtype in scikit-learn 1.10+ (dmlc/treelite#698) Authors: - Philip Hyunsu Cho (https://github.com/chyunsu3) - Tim Head (https://github.com/betatim) - James Lamb (https://github.com/jameslamb) Approvers: - James Lamb (https://github.com/jameslamb) - Simon Adorf (https://github.com/csadorf) URL: #8522
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #696
@betatim Can you review? I tested the change using the reproducer script from #696.