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

[python-package] avoid data_has_header check in predict() #5970

Merged
merged 2 commits into from
Jul 12, 2023

Conversation

jameslamb
Copy link
Collaborator

In the Python package, you can generate predictions on data stored in a delimited text file by passing a filepath to Booster.predict().

That calls LGBM_BoosterPredictForFile() in the C API, which takes a boolean argument indicating whether or not the file's first row is a header with feature names.

That argument, data_has_header, is a boolean in Booster.predict()'s interface but an int in LGBM_BoosterPredictForFile(), leading to this conversion:

int_data_has_header = 1 if data_has_header else 0

This PR proposes moving that conversion down into the if-else block corresponding to "data is a file", so it's cost is avoided on all other prediction paths.

I'm sure the cost of that one check is very very very very very small, but Booster.predict() is a latency-sensitive part of the API since it's used in model serving.

Copy link
Collaborator

@jmoralez jmoralez left a comment

Choose a reason for hiding this comment

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

Just a small suggestion in case you want to go for it.

@jameslamb jameslamb merged commit 84c657e into master Jul 12, 2023
39 checks passed
@jameslamb jameslamb deleted the header-check branch July 12, 2023 14:38
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants