Repository navigation
Multithreaded kneighbors_graph in TSNE - #15082
Conversation
|
In the end using the Though, this PR is still relevant, as for less high dimensional data kd_tree or ball_tree could be the right choice. |
|
We could also present an example of how to use annoy?
|
You mean with precomputed distance sparse distance matrices? #10482 added The point of this PR is however that we can be significantly faster than what we are now for TSNE even without using external dependencies. |
| The number of parallel jobs to run for neighbors search. | ||
| ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. | ||
| ``-1`` means using all processors. See :term:`Glossary <n_jobs>` | ||
| for more details. |
There was a problem hiding this comment.
Worth noting that it's unused if metric is precomputed?
| distances = pairwise_distances(X, metric=self.metric, | ||
| squared=True) | ||
| squared=True, | ||
| n_jobs=self.n_jobs) |
There was a problem hiding this comment.
for euclidean metric, having n_jobs > 1 unless blas num threads has been limited.
Could you rerun your benchmark with this n_jobs removed ?
There was a problem hiding this comment.
Yes, of course you are right, somehow I missed that in this branch the metric is always euclidean. Reverted the change here. The n_jobs is only useful in pairwise_distances for other computationally expensive metrics. In fact I think we should raise a warning when pairwise_distances is used with an euclidean metric and n_jobs>1.
The benchmarks I have done above are only for method="barnes_hut" (default). I have added the n_jobs for pairwise_distances in method="exact" on general grounds as there are probably some metrics where it's helpful.
There was a problem hiding this comment.
The benchmarks I have done above are only for method="barnes_hut" (default). I have added the n_jobs for pairwise_distances in method="exact" on general grounds as there are probably some metrics where it's helpful.
My point is that this has no impact on benchmarks above.
|
OK, clarified the docstring, added a basic test, and a what's new. |
|
Should be good to merge unless there are other comments? |
|
Thanks |
Partially addresses #10044
Partially addresses #10023
Computing the
kneighbors_graphis one of the bottlenecks in TSNE. Actually we computing it in parallel, including for kd_tree and ball_tree has been supported for a while. This adds then_jobsparameter to TSNE, which will pass it toNearestNeighbours.On the first 20k samples of MNIST
Details
we can get up to a 2.5x run time speedup when running with
n_jobs=8,n_jobsThe strong scaling limit seem to be around 10 CPU cores in this example.
For the full MNIST (60k samples), k-neighbours search takes proportionally even longer, and therefore multi-core scalability is better, with a x3.0 speed up at
n_jobs=8(and x3.7 atn_jobs=12) ,n_jobs#10044 (comment) proposed smarter improvements that are still worth investigating, but in any case NN search is a bottleneck and we can't use
annoyor similar unlike other TSNE libraries.Not sure if this needs additional tests given that
n_jobsinNearesNeigboursis already extensively tested.