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

Query: threading and threadpoolctl with main branch #26318

Closed
tylerjereddy opened this issue Apr 19, 2024 · 4 comments
Closed

Query: threading and threadpoolctl with main branch #26318

tylerjereddy opened this issue Apr 19, 2024 · 4 comments
Labels
33 - Question Question about NumPy usage or development

Comments

@tylerjereddy
Copy link
Contributor

I'm helping a downstream project adapt to NumPy changes, and noticed this:

from threadpoolctl import threadpool_info, threadpool_limits
import numpy as np

for entry in threadpool_info():
    print(entry["num_threads"])
    # 2.1.0.dev0 built from source locally on x86_64 Linux prints: 1 
    # 2.0.0rc1 from PyPI doesn't print anything
    # 1.26.4 from PyPI prints: 32

with threadpool_limits(2):
    for entry in threadpool_info():
        print(entry["num_threads"])
        # 2 with NumPy 1.26.4 on PyPI
        # 2.0.0rc1 from PyPI doesn't print anything
        # 2.1.0.dev0 built from source locally on x86_64 Linux prints: 1 

I think what is happening is that the downstream library is using the latest stable release of threadpoolctl and assuming that threadpool_limits(2) (or similar) will genuinely provide threading control at the level of the provided integer number of threads, which I might naively guess would be reasonable. Is this something still being worked on related to nogil/free-threading business, or some simpler explanation of what is going on here?

Should the advice be not to rely on that integer value of the threadpool limit being hard-enforced moving forward?

@ngoldbaum
Copy link
Member

I’m not aware of any recent numpy changes that would cause this. The nogil work is all ifdef’d behind build-time flags so I don’t think it’s related.

@seberg
Copy link
Member

seberg commented Apr 20, 2024

Seems that this is the discussion in #26240, so I guess it'll be resolved (not sure if by us or by threadpoolctl).

@rgommers
Copy link
Member

joblib/threadpoolctl#175 will resolve this.

Should the advice be not to rely on that integer value of the threadpool limit being hard-enforced moving forward?

It should be made reliably, that's the whole point of threadpoolctl. And the PR linked above is already approved, so it should be ready before the final numpy 2.0 release.

It looks like this is under control. If it turns out to be necessary, we should add some info that is more reliable to query. In the end this is a practical problem for numpy users, and our official response is "use threadpoolctl for this".

@rgommers
Copy link
Member

I'll add threadpoolctl to the 2.0 ecosystem tracking issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
33 - Question Question about NumPy usage or development
Projects
None yet
Development

No branches or pull requests

4 participants