Skip to content
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

Thresh_as_int parameter added #42

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

Conversation

dbart-utw
Copy link

Added functionality to be able to interpret the thresholds as integers, using an optional parameter.
This increases the performance up to 30%, without loss of accuracy.

The implementation is based on the following paper:
https://ieeexplore.ieee.org/abstract/document/10546851

@khchenTW khchenTW self-assigned this Feb 13, 2025
@khchenTW khchenTW requested a review from hcho3 February 13, 2025 14:24
@@ -33,7 +33,7 @@ class ASTBuilder {
ASTBuilder() : main_node_(nullptr) {}

/* \brief Initially build AST from model */
void BuildAST(treelite::Model const& model);
void BuildAST(treelite::Model const& model, bool thresh_as_int);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding the new option thresh_as_int is fine for now. But if we were to add more options to BuildAST, we should consider passing around the CompilerParam struct instead, to avoid having too many function arguments.

Comment on lines +70 to +71
return "(*( (("+new_dtype+"*)(data)) + "+std::to_string(node->split_index_)+" )"
+negatstring+")"+op+"(("+new_dtype+")("+split_val_bin+"))";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use fmt::format to format strings for the sake of legibility. It works like f-strings in Python.

Suggested change
return "(*( (("+new_dtype+"*)(data)) + "+std::to_string(node->split_index_)+" )"
+negatstring+")"+op+"(("+new_dtype+")("+split_val_bin+"))";
return fmt::format("(*( (({new_dtype}*)(data)) + {split_index} ) {negatstring} ) {op} (( {new_dtype} )( {split_val_bin} ))",
"new_dtype"_a = new_dtype, "split_index"_a = node->split_index_,
"negatstring"_a = negatstring, "op"_a = op,
"new_dtype"_a = new_dtype, "split_val_bin"_a = split_val_bin);

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