Repository navigation
Closed
Description
Describe the bug
The performance of TSNE transformation reduces when using n_jobs as 25 for the newer version w.r.t. 1.3.1.
version 1.3.1
df = np.random.rand(30000, 3)
tsne = TSNE(n_components=2, random_state=42, n_jobs=25, verbose=10, n_iter=1500)
1.5.1
df = np.random.rand(30000,3)
tsne = TSNE(n_components=2, random_state=42, n_jobs=25, verbose=10,max_iter=1500)
Time 1.3.1 vs 1.5.1 :: 59 vs 223
Is this a intended behavior?
Steps/Code to Reproduce
df = np.random.rand(30000, 3)
tsne = TSNE(n_components=2, random_state=42, n_jobs=25, verbose=10, n_iter=1500)
1.5.1
df = np.random.rand(30000,3)
tsne = TSNE(n_components=2, random_state=42, n_jobs=25, verbose=10,max_iter=1500)
Expected Results
Minimal time discrepancy
Actual Results
Similar time
Versions
1.5.1
System:
python: 3.12.3 (main, Jul 31 2024, 17:43:48) [GCC 13.2.0]
executable: /home/gagan/PycharmProjects/scikit_tsne_test/.venv/bin/python
machine: Linux-6.8.0-40-generic-x86_64-with-glibc2.39
Python dependencies:
sklearn: 1.5.1
pip: 23.2.1
setuptools: 72.2.0
numpy: 1.26.4
scipy: 1.14.0
Cython: None
pandas: None
matplotlib: None
joblib: 1.4.2
threadpoolctl: 3.5.0
Built with OpenMP: True
threadpoolctl info:
user_api: blas
internal_api: openblas
num_threads: 28
prefix: libscipy_openblas
filepath: /home/gagan/PycharmProjects/scikit_tsne_test/.venv/lib/python3.12/site-packages/scipy.libs/libscipy_openblas-c128ec02.so
version: 0.3.27.dev
threading_layer: pthreads
architecture: Haswell
1.3.1
System:
python: 3.12.3 (main, Jul 31 2024, 17:43:48) [GCC 13.2.0]
executable: /home/gagan/PycharmProjects/scikit_tsne_test/.venv/bin/python
machine: Linux-6.8.0-40-generic-x86_64-with-glibc2.39
Python dependencies:
sklearn: 1.3.1
pip: 23.2.1
setuptools: 72.2.0
numpy: 1.26.4
scipy: 1.14.0
Cython: None
pandas: None
matplotlib: None
joblib: 1.4.2
threadpoolctl: 3.5.0
Built with OpenMP: True
threadpoolctl info:
user_api: blas
internal_api: openblas
num_threads: 28
prefix: libopenblas
filepath: /home/gagan/PycharmProjects/scikit_tsne_test/.venv/lib/python3.12/site-packages/numpy.libs/libopenblas64_p-r0-0cf96a72.3.23.dev.so
version: 0.3.23.dev
threading_layer: pthreads
architecture: Prescott
user_api: openmp
internal_api: openmp
num_threads: 28
prefix: libgomp
filepath: /home/gagan/PycharmProjects/scikit_tsne_test/.venv/lib/python3.12/site-packages/scikit_learn.libs/libgomp-a34b3233.so.1.0.0
version: None
user_api: blas
internal_api: openblas
num_threads: 28
prefix: libscipy_openblas
filepath: /home/gagan/PycharmProjects/scikit_tsne_test/.venv/lib/python3.12/site-packages/scipy.libs/libscipy_openblas-c128ec02.so
version: 0.3.27.dev
threading_layer: pthreads
architecture: Haswell
Activity
adrinjalali commentedon Aug 14, 2024
Thanks for the report, I confirm that I can reproduce with:
On 1.3.1:
while on
main:Sample run on 1.3.1:
Sample run on
main:This requires more investigation to figure out where the performance hit is coming from.
adrinjalali commentedon Aug 14, 2024
Looking at the
git blameand our related PRs, I'm struggling to find the relevant change causing this regression.cc @scikit-learn/core-devs for help.
jjerphan commentedon Aug 14, 2024
I would recommend using
git-bisect.adrinjalali commentedon Aug 14, 2024
Something did NOT go well down that
git bisectpath 😆I'll try again
EDIT: pretty sure it's because I didn't handle meson/setuptools switch well while bisecting.
jjerphan commentedon Aug 14, 2024
Might it be due to the used of meson for the build system with flags being now different? We have seen this in the past in another issue.
adrinjalali commentedon Aug 14, 2024
Yep. Compiling the 1.5.1 tag with
python setup.py developrunsTSNEfast (11-12s), while the same tag with meson takes about 20s.cc @lesteve
lesteve commentedon Aug 19, 2024
After looking at this a bit, it seems like this is maybe linked to OpenMP, it seems like we need to add the
openmp_depto all the extensions that need it, for example for TSNE, this seems to improve the situation (need to look a bit more at it to be 100% sure this fixes the issue):My guess right now, is that the setuptools OpenMP flags were added everywhere globally, whereas for meson they need to be added explictly to extension modules that need it.
lesteve commentedon Aug 20, 2024
I have opened #29694 which I think fixes this issue.
[-]TSNE efficiency 1.3.1 vs 1.5.1 when using n_jobs[/-][+]TSNE performance regression in 1.5[/+]