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

Possible performance improvements for kd-tree or ball-tree with multi-threading at fit time #25812

Open
ogrisel opened this issue Mar 10, 2023 · 0 comments

Comments

@ogrisel
Copy link
Member

ogrisel commented Mar 10, 2023

As reported here: https://skops.readthedocs.io/en/latest/auto_examples/plot_intelex.html

For small n_features, KNeighborsClassifier uses either BallTree of KD-tree algorithms. At this time, scikit-learn builds this tree sequentially.

We could recursively build the branches in parallel using a ThreadPoolExecutor instance and call submit for each children of a given node. Note that each node splitting operation (starting from the root) is one Cython function call that releases the GIL, so using thread-based parallelism should be efficient.

The second speed-up reported in plot_intelex.html above (at inference time) is mostly linked to the fact that scikit-learn KNeighborsClassifier does not enable parallel neighbors queries with the default value of n_jobs when using the kd-tree or ball-tree algorithms.

From a user's point of view, this is not ideal either: when using the brute-force algorithm, we rely on OpenMP and automatically use as many threads as CPUs available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant