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

Setting a maximum number of hardware threads regardless of the number of chains #349

Open
jpmvferreira opened this issue May 2, 2022 · 2 comments
Labels

Comments

@jpmvferreira
Copy link

Hi there,

After skimming through the PyStan documentation, I just realized that there is no easy way to set a maximum number of cores within PyStan itself.
I saw a closed issue from 2 years ago, #136, which claimed that this feature doesn't have a clean fix from the Python side of things.

As such I would like to ask you if:

  1. Has the implementation changed such that this feature can be easily added as e.g. a keyword argument when running the sampling?
  2. Which hacks are there available to limit the number of hardware threads?

I'm asking this because running more chains than available hardware threads makes Stan run as much chains in parallel and, once one chain is complete, other will take its place executing, as intended.
However, setting an artificial upper bound might induce context switching between chains, because PyStan, or Stan, will probably think that there are more hardware threads available to it.
Is this something which is possible to happen?

Also, from #136, the name STAN_THREADS suggest it is an environmental variable, however changing it in the same terminal where I'm running the Python script doesn't seem to work, as 4 threads are still used when sampling the model.

This is not something very critical, as I could just run the program with nice, but it is a feature I would like to see added nonetheless, for additional convenience.

Also, when creating a new Github issue, three options show up:

  • Bug report
  • Documentation improvement
  • Question regarding PyStan and/or Stan
  • Blanck issue

In this case, this is a feature request, which I believe should be here rather than in the Stan forums.
Please do correct me if I'm wrong.

Thank you!

@jpmvferreira
Copy link
Author

I've been digging in the CmdStanPy documentation and found out that STAN_THREADS seems to be a compilation flag which is toggled on or off - link.
Not quite sure if it helps or not. but for CmdStanPy users it seems to allow to set a number of threads per chain (didn't even know Stan was this parallel!) and the number of chains running in parallel.

@stale
Copy link

stale bot commented Sep 21, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant