Problem with the "Getting started with PyMC3" tutorial

Hi, I’m new to PyMC3, while following the “Getting started with PyMC3” I got stuck at the "drawing 500 posterior samples part " with the following error:

with basic_model:
    # draw 500 posterior samples
    trace = pm.sample(500)

OUTPUT:

Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sigma, beta, alpha]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-17-782c941fbda8> in <module>()
      1 with basic_model:
      2     # draw 500 posterior samples
----> 3     trace = pm.sample(500)

~\AppData\Local\conda\conda\envs\deeplearning\lib\site-packages\pymc3\sampling.py in sample(draws, step, init, n_init, start, trace, chain_idx, chains, cores, tune, nuts_kwargs, step_kwargs, progressbar, model, random_seed, live_plot, discard_tuned_samples, live_plot_kwargs, compute_convergence_checks, use_mmap, **kwargs)
    447             _print_step_hierarchy(step)
    448             try:
--> 449                 trace = _mp_sample(**sample_args)
    450             except pickle.PickleError:
    451                 _log.warning("Could not pickle model, sampling singlethreaded.")

~\AppData\Local\conda\conda\envs\deeplearning\lib\site-packages\pymc3\sampling.py in _mp_sample(draws, tune, step, chains, cores, chain, random_seed, start, progressbar, trace, model, use_mmap, **kwargs)
    994         sampler = ps.ParallelSampler(
    995             draws, tune, chains, cores, random_seed, start, step,
--> 996             chain, progressbar)
    997         try:
    998             with sampler:

~\AppData\Local\conda\conda\envs\deeplearning\lib\site-packages\pymc3\parallel_sampling.py in __init__(self, draws, tune, chains, cores, seeds, start_points, step_method, start_chain_num, progressbar)
    273             ProcessAdapter(draws, tune, step_method,
    274                            chain + start_chain_num, seed, start)
--> 275             for chain, seed, start in zip(range(chains), seeds, start_points)
    276         ]
    277 

~\AppData\Local\conda\conda\envs\deeplearning\lib\site-packages\pymc3\parallel_sampling.py in <listcomp>(.0)
    273             ProcessAdapter(draws, tune, step_method,
    274                            chain + start_chain_num, seed, start)
--> 275             for chain, seed, start in zip(range(chains), seeds, start_points)
    276         ]
    277 

~\AppData\Local\conda\conda\envs\deeplearning\lib\site-packages\pymc3\parallel_sampling.py in __init__(self, draws, tune, step_method, chain, seed, start)
    180             draws, tune, seed)
    181         # We fork right away, so that the main process can start tqdm threads
--> 182         self._process.start()
    183 
    184     @property

~\AppData\Local\conda\conda\envs\deeplearning\lib\multiprocessing\process.py in start(self)
    103                'daemonic processes are not allowed to have children'
    104         _cleanup()
--> 105         self._popen = self._Popen(self)
    106         self._sentinel = self._popen.sentinel
    107         # Avoid a refcycle if the target function holds an indirect

~\AppData\Local\conda\conda\envs\deeplearning\lib\multiprocessing\context.py in _Popen(process_obj)
    210     @staticmethod
    211     def _Popen(process_obj):
--> 212         return _default_context.get_context().Process._Popen(process_obj)
    213 
    214 class DefaultContext(BaseContext):

~\AppData\Local\conda\conda\envs\deeplearning\lib\multiprocessing\context.py in _Popen(process_obj)
    311         def _Popen(process_obj):
    312             from .popen_spawn_win32 import Popen
--> 313             return Popen(process_obj)
    314 
    315     class SpawnContext(BaseContext):

~\AppData\Local\conda\conda\envs\deeplearning\lib\multiprocessing\popen_spawn_win32.py in __init__(self, process_obj)
     64             try:
     65                 reduction.dump(prep_data, to_child)
---> 66                 reduction.dump(process_obj, to_child)
     67             finally:
     68                 context.set_spawning_popen(None)

~\AppData\Local\conda\conda\envs\deeplearning\lib\multiprocessing\reduction.py in dump(obj, file, protocol)
     57 def dump(obj, file, protocol=None):
     58     '''Replacement for pickle.dump() using ForkingPickler.'''
---> 59     ForkingPickler(file, protocol).dump(obj)
     60 
     61 #

ValueError: must use protocol 4 or greater to copy this object; since __getnewargs_ex__ returned keyword arguments.

If anyone can help point me in the right direction, it’ll be greatly appreciated.
Thanks.

Does it work for you if you do:

with basic_model:
    # draw 500 posterior samples
    trace = pm.sample(500, cores=1)

?

2 Likes

Hey @junpenglao it worked!:grinning:

with basic_model:
# draw 500 posterior samples
trace = pm.sample(500, cores=1)

OUTPUT:

Auto-assigning NUTS sampler... Initializing NUTS using jitter+adapt_diag... Sequential sampling (2 chains in 1 job) NUTS: [sigma, beta, alpha] 100%|██████████████████████████████████████████████████████████████████████████████| 1000/1000 [05:57&lt;00:00, 4.05it/s] 100%|██████████████████████████████████████████████████████████████████████████████| 1000/1000 [05:27&lt;00:00, 3.05it/s]

If I understand this correctly, it means that the code isn’t fully utilizing the processor. Any idea how I can remedy this?

Either way thanks a lot. :ok_hand:

If I am reading your path correctly, you are using windows - we have been having multi-process issue under winOS for a while now…

2 Likes

Oh ok. I guess I’ll shift to linux for more demanding tasks. Thanks!

1 Like