Skip to content

Parallel sampling for smc causes attribute error #4324

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

Closed
jjruby09 opened this issue Dec 11, 2020 · 2 comments
Closed

Parallel sampling for smc causes attribute error #4324

jjruby09 opened this issue Dec 11, 2020 · 2 comments
Assignees
Labels
bug SMC Sequential Monte Carlo

Comments

@jjruby09
Copy link

When running sample_smc(parellel=True) on any models AttributeError: 'ValidatingScratchpad' object has no attribute 'test_value' is thrown

Please provide a minimal, self-contained, and reproducible example.

import pymc3 as pm
import numpy as np

data = np.random.randn(500)
with pm.Model() as model:
    mu = pm.Normal("mu", mu=0, sigma=1)
    sd = pm.HalfNormal("sd", sigma=1)
    obs = pm.Normal("obs", mu=mu, sigma=sd, observed=data)

    trace= pm.sample_smc(parallel=True)

Please provide the full traceback.

---------------------------------------------------------------------------
RemoteTraceback                           Traceback (most recent call last)
RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/Users/jruby/anaconda3/envs/pymc3_10_test/lib/python3.8/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/Users/jruby/anaconda3/envs/pymc3_10_test/lib/python3.8/multiprocessing/pool.py", line 51, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
  File "/Users/jruby/anaconda3/envs/pymc3_10_test/lib/python3.8/site-packages/pymc3/smc/sample_smc.py", line 262, in sample_smc_int
    smc.setup_kernel()
  File "/Users/jruby/anaconda3/envs/pymc3_10_test/lib/python3.8/site-packages/pymc3/smc/smc.py", line 129, in setup_kernel
    self.prior_logp_func = logp_forw([self.model.varlogpt], self.variables, shared)
  File "/Users/jruby/anaconda3/envs/pymc3_10_test/lib/python3.8/site-packages/pymc3/smc/smc.py", line 278, in logp_forw
    out_list, inarray0 = join_nonshared_inputs(out_vars, vars, shared)
  File "/Users/jruby/anaconda3/envs/pymc3_10_test/lib/python3.8/site-packages/pymc3/theanof.py", line 269, in join_nonshared_inputs
    inarray.tag.test_value = joined.tag.test_value
AttributeError: 'ValidatingScratchpad' object has no attribute 'test_value'
"""

The above exception was the direct cause of the following exception:

AttributeError                            Traceback (most recent call last)
<ipython-input-51-d9c09c21d627> in <module>
      8     obs = pm.Normal("obs", mu=mu, sigma=sd, observed=data)
      9 
---> 10     trace= pm.sample_smc(parallel=True)

~/anaconda3/envs/pymc3_10_test/lib/python3.8/site-packages/pymc3/smc/sample_smc.py in sample_smc(draws, kernel, n_steps, start, tune_steps, p_acc_rate, threshold, save_sim_data, save_log_pseudolikelihood, model, random_seed, parallel, chains, cores)
    189         loggers = [_log] + [None] * (chains - 1)
    190         pool = mp.Pool(cores)
--> 191         results = pool.starmap(
    192             sample_smc_int, [(*params, random_seed[i], i, loggers[i]) for i in range(chains)]
    193         )

~/anaconda3/envs/pymc3_10_test/lib/python3.8/multiprocessing/pool.py in starmap(self, func, iterable, chunksize)
    370         `func` and (a, b) becomes func(a, b).
    371         '''
--> 372         return self._map_async(func, iterable, starmapstar, chunksize).get()
    373 
    374     def starmap_async(self, func, iterable, chunksize=None, callback=None,

~/anaconda3/envs/pymc3_10_test/lib/python3.8/multiprocessing/pool.py in get(self, timeout)
    769             return self._value
    770         else:
--> 771             raise self._value
    772 
    773     def _set(self, i, obj):

AttributeError: 'ValidatingScratchpad' object has no attribute 'test_value'

sample() and sample_smc(parallel=False) successfully execute with proper results. I have tried to messing with theano.config.compute_test_value = X according to #562 but have not found a workable solution. All other functionality I have tried has been succesful thus far including saving and loading Arviz inference objects and testing a number of Arviz plots (using the other sampling techniques).

Versions and main components

  • PyMC3 Version: 3.10.0
  • Theano Version: (Theano-PYMC) 1.0.11
  • Python Version: 3.8
  • Operating system: OSX 10.14.6
  • How did you install PyMC3: pip within anaconda (conda installs were unsuccessful)
@gracebato
Copy link

Hi,

I have the same problem when using smc sampling. Any fix on running parallel=True ?
Thank you.

@ricardoV94 ricardoV94 added the SMC Sequential Monte Carlo label Jun 27, 2021
@ricardoV94
Copy link
Member

This should be fixed in V4.0.0. Closing for the time being

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug SMC Sequential Monte Carlo
Projects
None yet
Development

No branches or pull requests

5 participants