Skip to content

Feature request: Parallel/Multicore implementation of t-SNE #10023

Closed

Description

@jolespin

Has there been any discussion on implementing a multicore version of t-SNE in sklearn?

The fastest version that I have seen/used is https://github.com/claczny/VizBin/tree/master/src/backend/bh_tsne .

I think a few simple addition would be to change:

line 160 of https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/manifold/t_sne.py from:

pdist(X_embedded, "sqeuclidean")
to the following:
sklearn.metrics.pairwise to use the n_jobs parameter

In regards to the actual algorithm, https://github.com/DmitryUlyanov/Multicore-TSNE has implemented this in a different programming language so I cannot see what has been done. I believe his method only works for 2D embeddings (which could be fine if noted) and is very fast.

I also had very basic (and potentially naive) ideas in using bayesian optimization to speed up the algorithm as well if anyone has any insight: https://www.reddit.com/r/MachineLearning/comments/78i9rh/discussion_bayesian_optimization_of_tsne/ but this may not be the right place for that.

Just trying to think of ways to use this on larger datasets.

Activity

  1. lesteve commented on Oct 27, 2017

    @lesteve
    Member

    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.

  2. lesteve commented on Oct 27, 2017

    @lesteve
    Member

    While I am at it: you have better ways to link to code than saying file link + line number. See this for more details.

  3. jolespin commented on Oct 27, 2017

    @jolespin
    Author

    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:

    The resulting 2D projection looks like this:
    image

    sklearn implementation:

    import sklearn
    sklearn.__version__
    #'0.19.1'
    df_pca = pd.read_table("./sklearn.input.pca.tsv.gz", sep="\t", index_col=0)
    # New IPython Cell
    %%time
    tsne = manifold.TSNE(random_state=0)
    embeddings = tsne.fit_transform(df_pca)
    # CPU times: user 17min 14s, sys: 58.4 s, total: 18min 13s
    # Wall time: 12min 43s
    
  4. amueller commented on Oct 27, 2017

    @amueller
    Member

    This looks pretty bad:
    image

  5. amueller commented on Oct 27, 2017

    @amueller
    Member

    ah, that's 0.18.0

  6. jolespin commented on Oct 27, 2017

    @jolespin
    Author

    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

    image

    *** Note, I tried to follow the reference scheme in @lesteve comment but I don't have a pull request open.

    image

  7. lmcinnes commented on Feb 28, 2018

    @lmcinnes
    Contributor

    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.

  8. orihomie commented on Apr 29, 2019

    @orihomie

    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.

    Hi, @lmcinnes, any news about this?

  9. tomMoral commented on Apr 29, 2019

    @tomMoral
    Contributor

    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.

  10. rth commented on Sep 26, 2019

    @rth
    Member

    I believe parallelising the neighbour computation (be it via balltrees, or full distance computation) would be relatively straightforward.

    PR proposed in #15082

  11. cmarmo commented on Jan 29, 2021

    @cmarmo
    Contributor

    neighbors computation has been multithreaded in #15082 and the gradient computation has been parallelized in #13264.
    Is this issue still relevant? Thanks.

  12. dkobak commented on Mar 9, 2021

    @dkobak
    Contributor

    @cmarmo @rth This can be closed, I think.

  13. rth commented on Mar 9, 2021

    @rth
    Member

    Thanks @dkobak and @cmarmo !

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions