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

Switch mp to joblib in asPointwise #23

Merged
merged 1 commit into from
Mar 11, 2024

Conversation

JesseCresswell
Copy link
Contributor

This PR addresses issue #19
I used this test code to demonstrate the issue and benchmark the solution:

import numpy as np
import skdim
import time

np.random.seed(0)
X = np.random.random((20000, 10))

estimator = skdim.id.ESS() # LocalEstimator
n_jobs = 1

t0 = time.time()
lid = skdim.asPointwise(X, estimator, n_neighbors=10, n_jobs=n_jobs)
t1 = time.time()

print(lid.mean())
print(t1-t0)

On master, commit b9e8845, by only changing n_jobs I observe the following using a computer with 40 cpu. Note that the timing includes knn computation which is affected by n_jobs, but for these settings knn takes only a couple seconds for n_jobs=1.

n_jobs Time (s) Mean LID Notes
1 222.62 8.745108 About 50% of cpu being used at 100% (others at 0%)
2 - - Does not complete. Makes no progress. 100% of cpus at 0% usage

After the PR changes I observe

n_jobs Time (s) Mean LID Notes
1 219.36 8.745108 About 50% of cpu being used at 90%
2 208.17 8.745108 About 100% of cpu being used at 90%
20 28.47 8.745108 About 100% of cpu being used at 100%
40 16.95 8.745108 About 100% of cpu being used at 100%

Conclusions:
Multiprocessing is now working properly and there is a significant speedup from increasing n_jobs (including both knn computation, and estimator computation). The computed LID values are unchanged.
The ESS estimator code apparently uses more than one cpu even when n_jobs=1 , although it is not doing so efficiently. I have not tried to isolate which step is trying to use multiple cpus.

@j-bac j-bac merged commit a1a13da into scikit-learn-contrib:master Mar 11, 2024
@j-bac
Copy link
Collaborator

j-bac commented Mar 11, 2024

thanks! Looks good. Just a remark that ESS().fit already applies the estimator pointwise since it is a LocalEstimator so this example should not be used in practice

@JesseCresswell
Copy link
Contributor Author

Yes fair point for anyone else reading this. The built-in method ESS.fit() appears to be more efficient than using asPointwise. My example was just for benchmarking.

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.

None yet

2 participants