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
I am a bit busy with my semester end examinations. Not any significant progress on this issue. Will be free after 21st. @siftikha may work on it if possible before 21.
I can confirm some issues. I benchmarked all the python t-SNE implementations I could find on the MNIST dataset. Most implementations are based off the original code by Laurens van der Maaten, but there were some interesting differences anyway. You can see the results here.
There is, of course, quite a bit of noise in timing based on random seeds etc., but there are some clear winners and losers here.
MulticoreTSNE has superior NN computation (note surprising as it does approx NN via annoy I believe), coming in at 799s to complete the NN search. Interestingly the tsne implementation (which is largely a wrapper around Van der Maaten's code as I understand) is far worse at NN, taking 1104s, but makes up for it via faster gradient descent (306s vs the 654s of MulticoreTSNE). That's not just a sooner finish; in general it performs twice as fast for each batch of 50 iterations (according to the logging).
Both bhtsne and Van der Maaten's original bh_tsne fare less well at the NN phase (taking 3833s for bhtsne's NN for example), but reproduce similar gradient descent times as MulticoreTSNE.
Finally the bad news is the sklearn version, which fares badly in NN computation (5270s; probably due to kd-trees vs. vp-trees and some lack of tuning), and equally badly on gradient descent, averaging around 3-4 times slower than most of the other implementations (per batch of 50 iterations, and globally). This is a little disconcerting. I am pretty confident I have seen sklearn's t-SNE run much faster than this on MNIST (I seem to recall running it and getting similar timings to bh_tsne), but I certainly can't reproduce that now. Perhaps there has been a performance regression lately?
With regard to bottlenecks -- I did some profiling and it seems like _kl_divergence_bh is taking the time (as it should), but is apparently slower than it needs to be. To get deeper requires digging in and setting debug flags on the cython, which I haven't done yet.
I do believe the NN performance could be improved. I suspect taking advantage of a dual-tree approach would help with this much data that is this high dimensional. A breadth-first search strategy may also help. I'll look into that and try to get back to you with more details on timings.
Reacted by Matthew Dunn, guoxiaolu, Steven Du, Liqimai, Marek Čermák, Tony Lin, LD, Orkhan, Fei-Tzin Lee, Roman Yurchak and 4 more
thanks for the analysis!
The version of bhtsne in scikit-learn before 0.19 had a number of
substantial bugs, so if that's the version you remember being faster, it's
a pity if we now run slower, but better to be correct.
Don't worry too much about NN. We will, at a minimum, try to have a way for
users to provide their own NN in #10482.
No the pre-0.19 version (with the issues) was quite slow -- there was a noticeable performance boost moving on from that. If performance has degraded it is between 0.19.0 and 0.19.1, but I'm not sure anything has changed.
I haven't actually verified that -- I'm just remembering older runs, but many thing have changed since then (including OS upgrades to deal with meltdown) which could have impacted performance. I'm not actually sure there is any difference.
Update: verified that 0.19.0 on my current machine gives similar performance to 0.19.1. It may simply be that my recollection is poor :-(
Finally the bad news is the sklearn version, which fares badly in NN computation [...], and equally badly on gradient descent, averaging around 3-4 times slower than most of the other implementations.
Note that two speed improvements on the TSNE gradient descent have been merged in Feb 2018, (-40%) #10593, and (-25%) #10610 (total speed up -55%).
It seems like the merged PRs @TomDLT mentions, in combination with #10482, should significantly narrow the gap. It is probably worth benchmarking again to see how things look now. Of course OpenTSNE should probably be a point of comparison as well. I'll try to do this if I get some time, but other are certainly welcome to try as well.
I did not run it single-threaded yet because it takes annoyingly long.
In terms of gradient descent speed, all Barnes-Hut implementations are similar. openTSNE is the fastest, then MulticoreTSNe, then sklearn.
But BY FAR the largest difference in performance is due to kNN search. MulticoreTSNE uses Vantage Point trees. I think those are not available in sklearn, so this cannot really be addressed. openTSNE uses Ball Trees from sklearn. SklearnTSNE uses brute-force search (because that's what algorithm='auto' does). Brute-force is quite a bit slower than ball trees! Not sure why brute force used by default. It was implemented here #17148.
@dkobak Are you sure you have installed the latest version of scikit-learn? What is your OS?
With scikit-learn 0.24.1 on a Linux desktop restricting calculation to 6 CPU* (with n_jobs=6 and export OMP_NUM_THREADS=6),
MulticoreTSNE(n_jobs=6): 8min 32s
SklearnTSNE(n_jobs=6): 4min 18s (kNN: 100s)
So the scikit-learn implementation is currently faster than MulticoreTSNE for me.
SklearnTSNE uses brute-force search (because that's what algorithm='auto' does). Brute-force is quite a bit slower than ball trees! Not sure why brute force used by default. It was implemented here #17148.
In depends on the data dimensionality. For n_features=784 brute-force is likely to be faster than ball trees, and so it is correctly used there.
*more CPUs could potentially be used as a result of multi-processing creating threads, but it any case that wouldn't account for a 10x difference in performance you reported.
Edit: also for scikit-learn implementation could you please report the full output of %%time? I get,
CPU times: user 15min 14s, sys: 1min 23s, total: 16min 37s
Wall time: 4min 18s
No it shouldn't depend too much on hardware. It sounds like an issue of CPU oversubscription or BLAS that was fixed (or something about pre-computed sparse distance matrices calculation).
Could you please provide the output of
I'm not fully sure which commit is responsible for the difference in performance you saw, but in any case it does look like the performance of v0.24.1 is good when compared to other TSNE implementations.
So I'm going to close this issue, but don't hesitate to comment if you see other things.
Activity
jnothman commentedon Oct 30, 2017
@ogrisel does this match your earlier benchmarks?
thechargedneutron commentedon Oct 31, 2017
I want to take this issue. Will look into the issue and will ask in case of doubt.
jnothman commentedon Oct 31, 2017
siftikha commentedon Nov 17, 2017
This still of interest to you all?
amueller commentedon Nov 17, 2017
for sure! Maybe talk to @thechargedneutron to see if they came up with something.
thechargedneutron commentedon Nov 17, 2017
I am a bit busy with my semester end examinations. Not any significant progress on this issue. Will be free after 21st. @siftikha may work on it if possible before 21.
rmitsch commentedon Jan 29, 2018
@thechargedneutron @siftikha Did you make any progress?
lmcinnes commentedon Jan 30, 2018
I can confirm some issues. I benchmarked all the python t-SNE implementations I could find on the MNIST dataset. Most implementations are based off the original code by Laurens van der Maaten, but there were some interesting differences anyway. You can see the results here.
Summary:
There is, of course, quite a bit of noise in timing based on random seeds etc., but there are some clear winners and losers here.
MulticoreTSNE has superior NN computation (note surprising as it does approx NN via annoy I believe), coming in at 799s to complete the NN search. Interestingly the tsne implementation (which is largely a wrapper around Van der Maaten's code as I understand) is far worse at NN, taking 1104s, but makes up for it via faster gradient descent (306s vs the 654s of MulticoreTSNE). That's not just a sooner finish; in general it performs twice as fast for each batch of 50 iterations (according to the logging).
Both bhtsne and Van der Maaten's original bh_tsne fare less well at the NN phase (taking 3833s for bhtsne's NN for example), but reproduce similar gradient descent times as MulticoreTSNE.
Finally the bad news is the sklearn version, which fares badly in NN computation (5270s; probably due to kd-trees vs. vp-trees and some lack of tuning), and equally badly on gradient descent, averaging around 3-4 times slower than most of the other implementations (per batch of 50 iterations, and globally). This is a little disconcerting. I am pretty confident I have seen sklearn's t-SNE run much faster than this on MNIST (I seem to recall running it and getting similar timings to bh_tsne), but I certainly can't reproduce that now. Perhaps there has been a performance regression lately?
With regard to bottlenecks -- I did some profiling and it seems like
_kl_divergence_bhis taking the time (as it should), but is apparently slower than it needs to be. To get deeper requires digging in and setting debug flags on the cython, which I haven't done yet.I do believe the NN performance could be improved. I suspect taking advantage of a dual-tree approach would help with this much data that is this high dimensional. A breadth-first search strategy may also help. I'll look into that and try to get back to you with more details on timings.
jnothman commentedon Jan 30, 2018
jnothman commentedon Jan 30, 2018
Does @tomMoral have any ideas?
lmcinnes commentedon Jan 30, 2018
No the pre-0.19 version (with the issues) was quite slow -- there was a noticeable performance boost moving on from that. If performance has degraded it is between 0.19.0 and 0.19.1, but I'm not sure anything has changed.
jnothman commentedon Jan 30, 2018
lmcinnes commentedon Jan 30, 2018
I haven't actually verified that -- I'm just remembering older runs, but many thing have changed since then (including OS upgrades to deal with meltdown) which could have impacted performance. I'm not actually sure there is any difference.
Update: verified that 0.19.0 on my current machine gives similar performance to 0.19.1. It may simply be that my recollection is poor :-(
6 remaining items
TomDLT commentedon Sep 25, 2019
Note that two speed improvements on the TSNE gradient descent have been merged in Feb 2018, (-40%) #10593, and (-25%) #10610 (total speed up -55%).
lmcinnes commentedon Sep 25, 2019
It seems like the merged PRs @TomDLT mentions, in combination with #10482, should significantly narrow the gap. It is probably worth benchmarking again to see how things look now. Of course OpenTSNE should probably be a point of comparison as well. I'll try to do this if I get some time, but other are certainly welcome to try as well.
dkobak commentedon Mar 9, 2021
Given
#17148
#15082
#13264
#10593
#10610
I believe this could be closed now?
cmarmo commentedon Mar 9, 2021
Thanks @dkobak , do you think you would be able to quickly benchmarking the current version using scripts referenced in this issue?
dkobak commentedon Mar 9, 2021
@cmarmo Hmm. Embedding full MNIST without PCA pre-processing (n=70000, d=784) as @lmcinnes did above, on my 8-core laptop:
I did not run it single-threaded yet because it takes annoyingly long.
In terms of gradient descent speed, all Barnes-Hut implementations are similar. openTSNE is the fastest, then MulticoreTSNe, then sklearn.
But BY FAR the largest difference in performance is due to kNN search. MulticoreTSNE uses Vantage Point trees. I think those are not available in sklearn, so this cannot really be addressed. openTSNE uses Ball Trees from sklearn. SklearnTSNE uses brute-force search (because that's what
algorithm='auto'does). Brute-force is quite a bit slower than ball trees! Not sure why brute force used by default. It was implemented here #17148.rth commentedon Mar 9, 2021
@dkobak Are you sure you have installed the latest version of scikit-learn? What is your OS?
With scikit-learn 0.24.1 on a Linux desktop restricting calculation to 6 CPU* (with
n_jobs=6andexport OMP_NUM_THREADS=6),So the scikit-learn implementation is currently faster than MulticoreTSNE for me.
In depends on the data dimensionality. For n_features=784 brute-force is likely to be faster than ball trees, and so it is correctly used there.
*more CPUs could potentially be used as a result of multi-processing creating threads, but it any case that wouldn't account for a 10x difference in performance you reported.
Edit: also for scikit-learn implementation could you please report the full output of
%%time? I get,dkobak commentedon Mar 9, 2021
@rth Hmm
I have sklearn 0.23.2 on Ubuntu.
Well, it's not what I observe:
gives
Can it be hardware-dependent?? It seems my CPU is several times slower than your CPU.
dkobak commentedon Mar 9, 2021
@rth Wow, I installed 0.24.1 and look:
What has changed in 0.24?? It's amazing.
rth commentedon Mar 9, 2021
No it shouldn't depend too much on hardware. It sounds like an issue of CPU oversubscription or BLAS that was fixed (or something about pre-computed sparse distance matrices calculation).
Could you please provide the output of
sklearn.show_versions()python -m threadpoolctl -i numpy scipy.linalg?
rth commentedon Mar 9, 2021
I'm not fully sure which commit is responsible for the difference in performance you saw, but in any case it does look like the performance of v0.24.1 is good when compared to other TSNE implementations.
So I'm going to close this issue, but don't hesitate to comment if you see other things.
dkobak commentedon Mar 9, 2021
@rth Very cool. I just re-ran t-SNE benchmark, and I got 10min 54s with sklearn which is indeed faster than MulticoreTSNE.
I'll let @pavlinpolicar know that we should switch openTSNE's exact kNN search to
algorithm='auto'.TomDLT commentedon Mar 9, 2021
It is most likely #17148
dkobak commentedon Mar 9, 2021
@TomDLT Ah, so in 0.23 "auto" was not running brute-force but something else? Makes sense.