pymc-devs / pymc

Bayesian Modeling and Probabilistic Programming in Python
https://docs.pymc.io/
Other
8.69k stars 2.01k forks source link

Only sample using a single thread when sampling multiple chains in parallel #5453

Open twiecki opened 2 years ago

twiecki commented 2 years ago

My prior of what cores=4 does when calling pm.sample() is that pymc would use 4 of my cores. However, because of multi-threading this might not be the case. Furthermore, multi-threading is causing problems when running multiple chains in parallel: https://github.com/pymc-devs/pymc/issues/3140

I thus think we should set os.environ['OMP_NUM_THREADS'] = '1' if we're sampling on > 1 core.

twiecki commented 2 years ago

One other approach would be to add a kwarg to sample(threads=1) that defaults to 1.