-
Notifications
You must be signed in to change notification settings - Fork 178
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
[ENH] Distance module n_jobs support #2545
base: main
Are you sure you want to change the base?
Conversation
Thank you for contributing to
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! The only thing that would be missing from the PR to fix the issue is to include n_jobs
in the distance params in our KNeighborsTimeSeriesClassifier
and we would be good to go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to benchmark and see if this actually speeds it up.
aeon/distances/_sbd.py
Outdated
@@ -188,6 +196,17 @@ def sbd_pairwise_distance( | |||
[0.36754447, 0. , 0.29289322], | |||
[0.5527864 , 0.29289322, 0. ]]) | |||
""" | |||
n_jobs = check_n_jobs(n_jobs) | |||
set_num_threads(n_jobs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this should set it back to the original value after?
Maybe its possible to use a decorator in these cases similar to https://github.com/aeon-toolkit/aeon/blob/v1.0.0/aeon/testing/utils/output_suppression.py
Can confirm that this does indeed provide some speed ups : import numpy as np
from aeon.distances import euclidean_pairwise_distance
X = np.random.rand(1000, 1000)
Y = np.random.rand(1000, 1000)
euclidean_pairwise_distance(X, Y)
%timeit euclidean_pairwise_distance(X, Y)
%timeit euclidean_pairwise_distance(X, Y, n_jobs=-1)
Seconds Matthew's comment to revert the number of threads back to previously setted value (using get_num_threads). |
With distance measures like Euclidean I found unless you have a huge number of very long time series threading is almost never going to be faster just due to the cost of spawning a thread. This is why I added the warning as I can't really see a scenario where running pairwise euclidean distance thread will ever achieve a meaningful speed up. However, for something like DTW I get huge speed ups:
|
I also decided to add the threading with a custom distance function. |
I followed your suggestion @MatthewMiddlehurst and defined a decorator to handle setting and resetting threading. |
Reference Issues/PRs
#1886 #1797
What does this implement/fix? Explain your changes.
This PR adds parallelism to the distance module. Specifically to pairwise distance computations.
To do this the n_job parameter can now be specified to any pairwise distance (aside mpdist which was excluded due to complexity) and it will use that many threads.
This PR just updates the distance module. In a follow up PR I will update all our models that use pairwise_distance and n_jobs to make use of this.
Does your contribution introduce a new dependency? If yes, which one?
Any other comments?
PR checklist
For all contributions
For new estimators and functions
__maintainer__
at the top of relevant files and want to be contacted regarding its maintenance. Unmaintained files may be removed. This is for the full file, and you should not add yourself if you are just making minor changes or do not want to help maintain its contents.For developers with write access