Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Number of threads in KMeans should not be bigger than number of chunks #17210

Merged

Conversation

jeremiedbb
Copy link
Member

@jeremiedbb jeremiedbb commented May 13, 2020

related to #17208

When the number of chunks is smaller than the number of cores (i.e. very small datasets), KMeans launches as many threads as there are cores anyway. It should use n_chunks threads instead.

@adrinjalali
Copy link
Member

curious, how much of a gain is this? and should it go in 0.23.1?

@jnothman jnothman added this to the 0.23.1 milestone May 14, 2020
@glemaitre
Copy link
Member

curious, how much of a gain is this? and should it go in 0.23.1?

It is a regression in #17208. It seems x10 on very small dataset.

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then if you've tested and this is fixing the issue, I'm happy. I don't think we can easily write a test for it.

@jeremiedbb
Copy link
Member Author

It's an attempt to fix 17208, but it's still wip. I can reproduce the slowdown on my laptop and this pr fixes it but it seems to not work for the person who opened the issue. I need to investigate further with him

@rth
Copy link
Member

rth commented May 14, 2020

The fix sounds like a good improvement in any case. Though he has 4 cores, so I would have imagined spawning 8 threads shouldn't be too costly performance wise?

@jeremiedbb
Copy link
Member Author

jeremiedbb commented May 14, 2020

The fix sounds like a good improvement in any case

I agree

Though he has 4 cores, so I would have imagined spawning 8 threads shouldn't be too costly performance wise?

In the reproducible snippet, there are only 150 samples, which means there will only be one chunk. On my laptop with 4 cores, it spawns 4 threads and it makes a huge diff. The thing is that it only concerns very small datasets for which the whole fit time is ~ 0.005 sec. So I guess that the overhead of thread creation become non negligible.

@rth
Copy link
Member

rth commented May 14, 2020

Let's merge this as is? As if necessary you could create a new PR with more improvements? Please add a what's new entry.

BTW, can this affect other parts of the code that do parallel chunking where we could also apply this fix ?

@jeremiedbb
Copy link
Member Author

BTW, can this affect other parts of the code that do parallel chunking where we could also apply this fix ?

Not that I can think about.

@jeremiedbb
Copy link
Member Author

Let's merge this as is?

It can't hurt and It's still an improvement

@jeremiedbb
Copy link
Member Author

Some profiling showed that it's threadpoolctl that takes 90% of the time on these very small problems. It's called at each iteration. I'll make a pr to move it outside of the loop.

@adrinjalali
Copy link
Member

I guess @rth is also happy to have this merged. Merging, hopefully the other PR improving the threadpoolctl overhead would get in quickly too.

@adrinjalali adrinjalali merged commit 90d00da into scikit-learn:master May 15, 2020
gio8tisu pushed a commit to gio8tisu/scikit-learn that referenced this pull request May 15, 2020
…hunks (scikit-learn#17210)

* num threads not bigger than num chunks

* what's new
adrinjalali pushed a commit to adrinjalali/scikit-learn that referenced this pull request May 18, 2020
…hunks (scikit-learn#17210)

* num threads not bigger than num chunks

* what's new
adrinjalali pushed a commit that referenced this pull request May 19, 2020
…hunks (#17210)

* num threads not bigger than num chunks

* what's new
viclafargue pushed a commit to viclafargue/scikit-learn that referenced this pull request Jun 26, 2020
…hunks (scikit-learn#17210)

* num threads not bigger than num chunks

* what's new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants