stan-dev / stan-dev/pystan

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

Open
#349 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

wontfix
Dominant language
Python
Stars
366
Forks
61
PR merge metrics
No merged PRs in 30d

Description

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!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PyStan sampling API and the earlier issue #136, then investigate how PyStan and Stan determine parallel hardware threads and whether STAN_THREADS is relevant. Done would require a decided, documented approach for exposing a maximum thread or core limit, with its behavior during sampling clarified.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.