Skip to content

Fix initialization of same_node_ in TreeEnsemble #24654

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

xadupre
Copy link
Member

@xadupre xadupre commented May 6, 2025

Description

For TreeEnsemble, onnxruntime tries to fuse multiple nodes BRANCH_EQ into one node BRANCH_MEMBER. When a tree only contains BRANCH_EQ nodes, the final tree could be a mix between BRANCH_EQ and BRANCH_MEMBER. To be more efficient, onnxruntime detects that all the nodes use the same rule and avoids checking that value for every node while getting the final leaf. This detection happened before the fusion into BRANCH_MEMBER. This PR detects that this check must be done again. This extra cost only happens when a tree only contains nodes BRANCH_EQ and should not be much. It only happens during the initialization.

Motivation and Context

Fixes issue #24636.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

Copy link
Contributor

@cbourjau cbourjau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! Thanks for looking into this so quickly!

xadupre and others added 3 commits May 6, 2025 18:14
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@yuslepukhin yuslepukhin self-requested a review May 6, 2025 17:51
@yuslepukhin
Copy link
Member

T operator*(double val) { return has_score ? score * static_cast(val) : 0; }

Potentially important nit: these two operators must be const.


Refers to: onnxruntime/core/providers/cpu/ml/tree_ensemble_aggregator.h:53 in 9ef3585. [](commit_id = 9ef3585, deletion_comment = False)

@yuslepukhin
Copy link
Member

size_t limit;

Suggest both i and fpos to be size_t, that would reduce the number of casts


Refers to: onnxruntime/core/providers/cpu/ml/tree_ensemble_common.h:149 in 9ef3585. [](commit_id = 9ef3585, deletion_comment = False)

yuslepukhin
yuslepukhin previously approved these changes May 6, 2025
Copy link
Member

@yuslepukhin yuslepukhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

yuslepukhin
yuslepukhin previously approved these changes May 7, 2025
Copy link
Member

@yuslepukhin yuslepukhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@xadupre
Copy link
Member Author

xadupre commented May 8, 2025

/azp run build_x64_release

Copy link

No pipelines are associated with this pull request.

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

Successfully merging this pull request may close these issues.

3 participants