You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: Parallel/Multicore implementation of t-SNE #10023
sklearn.metrics.pairwise to use the n_jobs parameter
This is likely to make the distance computation slower, see #8216 for more details.
The best thing to do is to profile the code and spot bottlenecks that can be improved. Maybe @ogrisel and @tomMoral have suggestions of the top of their head, since they worked on this code recently.
Just trying to think of ways to use this on larger datasets.
Maybe you can be more precise about what you mean by "larger datasets" and give some timings for the alternative implementations you listed above. A benchmark script to reproduce your numbers would be ideal.
What VizBin does is take in DNA sequences, counts the occurrence of overlapping words of window-size K (i.e. k-mers, in this case 5), normalize the counts, feeds count matrix into PCA to get the first 50 components, then pipes those eigenvectors into t-SNE for 1000 iterations.
That entire process for 26,583 sequences/data-points took 1:12 minutes. The actual t-SNE time measurements are below. The t-SNE calculation for this dataset, including the pairwise distances, is ~1:02 minutes. Apologies for the poor formatting! I am new-ish to GitHub but will try to be better about that.
Hope this helps
2017-10-27 10:03:11,561 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Read the 26583 x 50 data matrix successfully!
2017-10-27 10:03:11,561 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Running BH_TSNE with 8 threads and seed = 0
2017-10-27 10:03:11,561 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Using no_dims = 2, perplexity = 30.000000, theta = 0.500000
2017-10-27 10:03:11,561 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Computing input similarities...
2017-10-27 10:03:11,769 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Building tree...
2017-10-27 10:03:11,770 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: - point 0 of 26583
2017-10-27 10:03:13,992 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: - point 10000 of 26583
2017-10-27 10:03:16,249 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: - point 20000 of 26583
2017-10-27 10:03:18,600 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Done in 7.03 seconds (sparsity = 0.004990)!
2017-10-27 10:03:18,600 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Learning embedding...
2017-10-27 10:03:21,881 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 50: error is 107.542638 (50 iterations in 0.00 seconds)
2017-10-27 10:03:25,065 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 100: error is 107.244373 (50 iterations in 0.00 seconds)
2017-10-27 10:03:28,048 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 150: error is 89.224352 (50 iterations in 0.00 seconds)
2017-10-27 10:03:30,931 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 200: error is 83.744486 (50 iterations in 0.00 seconds)
2017-10-27 10:03:33,798 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 250: error is 4.306542 (50 iterations in 0.00 seconds)
2017-10-27 10:03:36,650 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 300: error is 3.546384 (50 iterations in 0.00 seconds)
2017-10-27 10:03:39,371 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 350: error is 3.200923 (50 iterations in 0.00 seconds)
2017-10-27 10:03:42,069 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 400: error is 2.984275 (50 iterations in 0.00 seconds)
2017-10-27 10:03:44,738 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 450: error is 2.832525 (50 iterations in 0.00 seconds)
2017-10-27 10:03:47,448 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 500: error is 2.718632 (50 iterations in 0.00 seconds)
2017-10-27 10:03:50,097 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 550: error is 2.629202 (50 iterations in 0.00 seconds)
2017-10-27 10:03:52,742 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 600: error is 2.556856 (50 iterations in 0.00 seconds)
2017-10-27 10:03:55,389 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 650: error is 2.497018 (50 iterations in 0.00 seconds)
2017-10-27 10:03:57,990 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 700: error is 2.446629 (50 iterations in 0.00 seconds)
2017-10-27 10:04:00,717 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 750: error is 2.404156 (50 iterations in 0.00 seconds)
2017-10-27 10:04:03,387 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 800: error is 2.368005 (50 iterations in 0.00 seconds)
2017-10-27 10:04:06,110 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 850: error is 2.336534 (50 iterations in 0.00 seconds)
2017-10-27 10:04:08,827 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 900: error is 2.308381 (50 iterations in 0.00 seconds)
2017-10-27 10:04:11,337 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 950: error is 2.283032 (50 iterations in 0.00 seconds)
2017-10-27 10:04:13,893 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Iteration 999: error is 2.260556 (50 iterations in 0.00 seconds)
2017-10-27 10:04:13,897 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Fitting performed in 0.00 seconds.
2017-10-27 10:04:13,916 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE: Wrote the 26583 x 2 data matrix successfully!
2017-10-27 10:04:13,916 DEBUG [TSNERunner] (DataSetUtils.java:303) - TSNE:
I believe parallelising the neighbour computation (be it via balltrees, or full distance computation) would be relatively straightforward. There are, of course, seriously diminishing returns on that for much more than 4 or 8 cores. Paralellising the gradient descent is rather harder, but I think there are even less gains to be had there. I would be willing to take a look at this at some point if people are still interested.
Reacted by Velisarios Miloulis, Brandon Roberts, Krishna Penukonda, Trent Hauck, Dylan Nielson, Adrian Viehweger, Sangram Gaikwad, René, mor krispil and ajflores1604
I believe parallelising the neighbour computation (be it via balltrees, or full distance computation) would be relatively straightforward. There are, of course, seriously diminishing returns on that for much more than 4 or 8 cores. Paralellising the gradient descent is rather harder, but I think there are even less gains to be had there. I would be willing to take a look at this at some point if people are still interested.
Note that I took a pass at parallelizing tSNE using prange for the gradient computations in #13264
The code seem to give about 30% speed-up when using 2 cores, which is encouraging.
We are waiting better control of openmp threadpools before moving forward with this parallelisation. See #13297 for details.
neighbors computation has been multithreaded in #15082 and the gradient computation has been parallelized in #13264.
Is this issue still relevant? Thanks.
Activity
lesteve commentedon Oct 27, 2017
This is likely to make the distance computation slower, see #8216 for more details.
The best thing to do is to profile the code and spot bottlenecks that can be improved. Maybe @ogrisel and @tomMoral have suggestions of the top of their head, since they worked on this code recently.
Maybe you can be more precise about what you mean by "larger datasets" and give some timings for the alternative implementations you listed above. A benchmark script to reproduce your numbers would be ideal.
lesteve commentedon Oct 27, 2017
While I am at it: you have better ways to link to code than saying file link + line number. See this for more details.
jolespin commentedon Oct 27, 2017
What VizBin does is take in DNA sequences, counts the occurrence of overlapping words of window-size K (i.e. k-mers, in this case 5), normalize the counts, feeds count matrix into PCA to get the first 50 components, then pipes those eigenvectors into t-SNE for 1000 iterations.
That entire process for
26,583 sequences/data-pointstook1:12 minutes. The actual t-SNE time measurements are below. The t-SNE calculation for this dataset, including the pairwise distances, is~1:02 minutes. Apologies for the poor formatting! I am new-ish to GitHub but will try to be better about that.Hope this helps
The resulting 2D projection looks like this:

sklearnimplementation:amueller commentedon Oct 27, 2017
This looks pretty bad:

amueller commentedon Oct 27, 2017
ah, that's 0.18.0
jolespin commentedon Oct 27, 2017
I'm hosting the data files in my Google Drive at the following location:
https://drive.google.com/drive/folders/0Bx2FlTJ8g3XRbFBGb0tlUmUtMms?usp=sharing
Here is the parallelization edit to the original code in this version (he also added a random seed):
https://github.com/claczny/VizBin/blob/master/src/backend/bh_tsne/ptsne.cpp
*** Note, I tried to follow the reference scheme in @lesteve comment but I don't have a pull request open.
lesteve commentedon Nov 3, 2017
Just for the record the numbers from #10023 (comment) are in https://github.com/DmitryUlyanov/Multicore-TSNE#benchmark.
lmcinnes commentedon Feb 28, 2018
I believe parallelising the neighbour computation (be it via balltrees, or full distance computation) would be relatively straightforward. There are, of course, seriously diminishing returns on that for much more than 4 or 8 cores. Paralellising the gradient descent is rather harder, but I think there are even less gains to be had there. I would be willing to take a look at this at some point if people are still interested.
orihomie commentedon Apr 29, 2019
Hi, @lmcinnes, any news about this?
tomMoral commentedon Apr 29, 2019
Note that I took a pass at parallelizing
tSNEusingprangefor the gradient computations in #13264The code seem to give about 30% speed-up when using 2 cores, which is encouraging.
We are waiting better control of
openmpthreadpools before moving forward with this parallelisation. See #13297 for details.rth commentedon Sep 26, 2019
PR proposed in #15082
cmarmo commentedon Jan 29, 2021
neighbors computation has been multithreaded in #15082 and the gradient computation has been parallelized in #13264.
Is this issue still relevant? Thanks.
dkobak commentedon Mar 9, 2021
@cmarmo @rth This can be closed, I think.
rth commentedon Mar 9, 2021
Thanks @dkobak and @cmarmo !