-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Issue compiling pytensor functions in multiple processes #6818
Comments
|
Is this caused by the parallelization? Does it work otherwise? |
Otherwise it works, so most likely has to do with the parallelisation. Actually, I've got roughly 750 combinations and it collapses typically around 600. By the way, for the record, funnily enough, I just run the code from VS Code in interactive mode and it worked... |
Can you report the whole traceback? |
Indeed. It's a little bit messy; my feeling is that this is because, as I'm parallelising, when the code collapses there're several ERROR (pytensor.graph.rewriting.basic): Rewrite failure due to: constant_folding ERROR (pytensor.graph.rewriting.basic): node: Mul([-1.], likelihood{[ 77. 14. ... 25. 52.]}, [1.]) ERROR (pytensor.graph.rewriting.basic): TRACEBACK: Sampling 2 chains for 1_000 tune and 2_000 draw iterations (2_000 + 4_000 draws total) took 672 seconds. NUTS: [alpha, theta] We recommend running at least 4 chains for robust computation of convergence diagnostics ERROR (pytensor.graph.rewriting.basic): Rewrite failure due to: constant_folding Auto-assigning NUTS sampler... The above exception was the direct cause of the following exception: Traceback (most recent call last): |
Looks like a timeout due to the locking mechanism of the c compilation in PyTensor. Pinging @ferrine @lucianopaz to see if they have any advice. I think this is a known limitation of PyTensor. Taking a step back, what are you trying to achieve exactly? Run the same model on different datasets? |
Indeed, this is what I'm doing. |
This is a known limitation (compile/cache lock), I suggest to use https://github.com/pymc-devs/nutpie, specifically |
Thank you very much, @ferrine. I'll take a look at this solution. |
@PL-EduardoSanchez, Did you find the solution to this issue? I am getting the same error when running the model on different datasets in parallel. I also tried increasing the compile_timeout of the PyTensor mentioned here, but it didn't work. |
Hi @kshhhv. I tried with "nutpie", with |
@PL-EduardoSanchez @kshhhv , I came across the same issue upon using Pymc in multiple processes. |
Thank you very much, @isilber. Currently I'm not actively working on the project where I used "pymc", but I'll give it a try in the future. |
Thanks, @philpatton.
|
Any ideas on how you would apply this solution when you are applying the multiprocessing in python rather than bash? I have some pre-fitting data in python dictionary format that is identical for all runs to the point where running them each separately on bash doesn't make sense. The relevant multiprocessing code is below:
|
@Hope2925 you could write a python script that loads the dictionary then samples, then call that in bash. This is roughly how I run things, except I need to use SLURM on our cluster. But all the python code goes in a python script that's called in a bash script. (You need to write the trace to a file in the python script.) There's probably a way to set environment variables in multiprocessing, but I'm not familiar with it. Maybe the function you pass to the worker could use 'os.environ' to set the environment variables. Basically you want to set the values from PYT_FLAG as environment variables. |
Describe the issue:
Given a table with three columns X1, X2, and Y, I am trying to get independent Bayesian models for the variable Y for each value of X1 and X2. This is why I'm trying to parallelise the MCMC sampling with Parallel+delayed from joblib (see code below). In principle the workflow runs smoothly, but at some point, in principle at random, the code collapses (see the error message below).
For the record, I am running the process as a python script from my terminal like this:
conda activate my-conda-env python my_script.py # see the code below
If you need more details, please, let me know.
Thanks in advance!
Best,
Eduardo
Reproduceable code example:
Error message:
PyMC version information:
pymc: 5.5.0
pytensor: 2.12.3
python: 3.11.4
OS: Windows 10
Installation: With conda (see code below)
conda create -c conda-forge -n optiwaste-hierarchical-models "pymc>=5"
Context for the issue:
I think it would be very convenient to be able to run in parallel a bunch of different Bayesian models to save some computation time.
The text was updated successfully, but these errors were encountered: