You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These are still present even though the linked issues are already closed.
Interesting these problems only occur when using metropolis and not when using NUTS (see examples below).
Only200samplesinchain.
Multiprocesssampling (2chainsin2jobs)
CompoundStep>Metropolis: [dummy]
>Metropolis: [p]
>Metropolis: [N]
pymc3.parallel_sampling.RemoteTraceback: -----------------------------------------------------------|0.00% [0/60000:00<00:00Sampling2chains, 0divergences]
"""Traceback (most recent call last): File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/theano/link/vm.py", line 313, in __call__ thunk() File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/theano/graph/op.py", line 476, in rval r = p(n, [x[0] for x in i], o) File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/theano/tensor/elemwise.py", line 776, in perform raise ValueError(base_exc_str)ValueError: Dimension mismatch; shapes are (5, 13), (1, 13)During handling of the above exception, another exception occurred:Traceback (most recent call last): File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/parallel_sampling.py", line 137, in run self._start_loop() File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/parallel_sampling.py", line 191, in _start_loop point, stats = self._compute_point() File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/parallel_sampling.py", line 216, in _compute_point point, stats = self._step_method.step(self._point) File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/step_methods/compound.py", line 42, in step point, state = method.step(point) File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/step_methods/arraystep.py", line 196, in step apoint, stats = self.astep(self.bij.map(point)) File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/step_methods/metropolis.py", line 217, in astep accept = self.delta_logp(q, q0) File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/theano/compile/function/types.py", line 975, in __call__ if output_subset is None File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/theano/link/vm.py", line 317, in __call__ raise_with_op(self.fgraph, node, thunk) File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/theano/link/utils.py", line 508, in raise_with_op raise exc_value.with_traceback(exc_trace) File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/theano/link/vm.py", line 313, in __call__ thunk() File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/theano/graph/op.py", line 476, in rval r = p(n, [x[0] for x in i], o) File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/theano/tensor/elemwise.py", line 776, in perform raise ValueError(base_exc_str)ValueError: Dimension mismatch; shapes are (5, 13), (1, 13)Apply node that caused the error: Elemwise{sub,no_inplace}(Reshape{2}.0, Elemwise{add,no_inplace}.0)Toposort index: 17Inputs types: [TensorType(float64, matrix), TensorType(float64, matrix)]Inputs shapes: [(5, 13), (1, 13)]Inputs strides: [(104, 8), (104, 8)]Inputs values: ['not shown', 'not shown']Inputs type_num: [12, 12]Outputs clients: [[Elemwise{pow,no_inplace}(Elemwise{sub,no_inplace}.0, TensorConstant{(1, 1) of 2})]]Backtrace when the node is created(use Theano flag traceback__limit=N to make it longer): File "test.py", line 22, in <module> main() File "test.py", line 17, in main step = pm.Metropolis() File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/step_methods/arraystep.py", line 86, in __new__ step.__init__([var], *args, **kwargs) File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/step_methods/metropolis.py", line 187, in __init__ self.delta_logp = delta_logp(model.logpt, vars, shared) File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/step_methods/metropolis.py", line 883, in delta_logp [logp0], inarray0 = pm.join_nonshared_inputs([logp], vars, shared) File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/theanof.py", line 278, in join_nonshared_inputs xs_special = [theano.clone(x, replace, strict=False) for x in xs] File "/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/theanof.py", line 278, in <listcomp> xs_special = [theano.clone(x, replace, strict=False) for x in xs]Debugprint of the apply node:Elemwise{sub,no_inplace} [id A] <TensorType(float64, matrix)> '' |Reshape{2} [id B] <TensorType(float64, matrix)> '' | |Subtensor{int64:int64:} [id C] <TensorType(float64, vector)> '' | | |inarray [id D] <TensorType(float64, vector)> | | |Constant{0} [id E] <int64> | | |Constant{65} [id F] <int64> | |TensorConstant{[ 5 13]} [id G] <TensorType(int64, vector)> |Elemwise{add,no_inplace} [id H] <TensorType(float64, matrix)> '' |Elemwise{mul,no_inplace} [id I] <TensorType(float64, matrix)> '' | |sigmoid [id J] <TensorType(float64, matrix)> '' | | |N_interval___shared [id K] <TensorType(float64, matrix)> | |TensorConstant{(1, 1) of 100000.0} [id L] <TensorType(float64, (True, True))> |Elemwise{mul,no_inplace} [id M] <TensorType(float64, matrix)> '' |Elemwise{sub,no_inplace} [id N] <TensorType(float64, matrix)> '' | |TensorConstant{(1, 1) of 1} [id O] <TensorType(int8, (True, True))> | |sigmoid [id J] <TensorType(float64, matrix)> '' |TensorConstant{(1, 1) of 0.0} [id P] <TensorType(float64, (True, True))>HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node."""Theaboveexceptionwasthedirectcauseofthefollowingexception:
ValueError: Dimensionmismatch; shapesare (5, 13), (1, 13)
Applynodethatcausedtheerror: Elemwise{sub,no_inplace}(Reshape{2}.0, Elemwise{add,no_inplace}.0)
Toposortindex: 17Inputstypes: [TensorType(float64, matrix), TensorType(float64, matrix)]
Inputsshapes: [(5, 13), (1, 13)]
Inputsstrides: [(104, 8), (104, 8)]
Inputsvalues: ['not shown', 'not shown']
Inputstype_num: [12, 12]
Outputsclients: [[Elemwise{pow,no_inplace}(Elemwise{sub,no_inplace}.0, TensorConstant{(1, 1) of2})]]
Backtracewhenthenodeiscreated(useTheanoflagtraceback__limit=Ntomakeitlonger):
File"test.py", line22, in<module>main()
File"test.py", line17, inmainstep=pm.Metropolis()
File"/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/step_methods/arraystep.py", line86, in__new__step.__init__([var], *args, **kwargs)
File"/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/step_methods/metropolis.py", line187, in__init__self.delta_logp=delta_logp(model.logpt, vars, shared)
File"/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/step_methods/metropolis.py", line883, indelta_logp
[logp0], inarray0=pm.join_nonshared_inputs([logp], vars, shared)
File"/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/theanof.py", line278, injoin_nonshared_inputsxs_special= [theano.clone(x, replace, strict=False) forxinxs]
File"/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/theanof.py", line278, in<listcomp>xs_special= [theano.clone(x, replace, strict=False) forxinxs]
Debugprintoftheapplynode:
Elemwise{sub,no_inplace} [idA] <TensorType(float64, matrix)>''|Reshape{2} [idB] <TensorType(float64, matrix)>''||Subtensor{int64:int64:} [idC] <TensorType(float64, vector)>''|||inarray [idD] <TensorType(float64, vector)>|||Constant{0} [idE] <int64>|||Constant{65} [idF] <int64>||TensorConstant{[ 513]} [idG] <TensorType(int64, vector)>|Elemwise{add,no_inplace} [idH] <TensorType(float64, matrix)>''|Elemwise{mul,no_inplace} [idI] <TensorType(float64, matrix)>''||sigmoid [idJ] <TensorType(float64, matrix)>''|||N_interval___shared [idK] <TensorType(float64, matrix)>||TensorConstant{(1, 1) of100000.0} [idL] <TensorType(float64, (True, True))>|Elemwise{mul,no_inplace} [idM] <TensorType(float64, matrix)>''|Elemwise{sub,no_inplace} [idN] <TensorType(float64, matrix)>''||TensorConstant{(1, 1) of1} [idO] <TensorType(int8, (True, True))>||sigmoid [idJ] <TensorType(float64, matrix)>''|TensorConstant{(1, 1) of0.0} [idP] <TensorType(float64, (True, True))>HINT: UsetheTheanoflag'exception_verbosity=high'foradebugprintandstoragemapfootprintofthisapplynode.
Theaboveexceptionwasthedirectcauseofthefollowingexception:
Traceback (mostrecentcalllast):
File"test.py", line22, in<module>main()
File"test.py", line18, inmainidata=pm.sample(200, step=step, tune=100, return_inferencedata=True)
File"/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/sampling.py", line558, insampletrace=_mp_sample(**sample_args, **parallel_args)
File"/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/sampling.py", line1476, in_mp_samplefordrawinsampler:
File"/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/parallel_sampling.py", line479, in__iter__draw=ProcessAdapter.recv_draw(self._active)
File"/Users/hornm/Library/Caches/pypoetry/virtualenvs/grass-collaboration-i2H8sdro-py3.7/lib/python3.7/site-packages/pymc3/parallel_sampling.py", line359, inrecv_drawraiseerrorfromold_errorRuntimeError: Chain0failed.
Potential fix
As was indicated in #3337, this might well be due to loss of broadcasting information when calling make_shared_replacements. Theanos error message and traceback then indicate that the source of the problem is in pm.join_nonshared_inputs, which is slightly misleading. The error occurs here as this is the location where the original variable ist replaced with the shared version of itself where broadcasting information is missing.
I will open a pull request to fix this, I do not anticipate any negative consequences for other parts of pymc3.
Versions and main components
PyMC3 Version: 3.11.1
Theano Version: 1.1.2
Python Version: 3.7.9
Operating system: MacOS Catalina 10.15.7
How did you install PyMC3: pip (to be exact via poetry)
The text was updated successfully, but these errors were encountered:
Using broadcasting together with the Metropolis sampler often leads to problems as indicated in these previous issues:
These are still present even though the linked issues are already closed.
Interesting these problems only occur when using metropolis and not when using NUTS (see examples below).
Minimal examples
Successful with NUTS sampler:
Failure with metropolis:
Traceback.
Potential fix
As was indicated in #3337, this might well be due to loss of broadcasting information when calling
make_shared_replacements
. Theanos error message and traceback then indicate that the source of the problem is inpm.join_nonshared_inputs
, which is slightly misleading. The error occurs here as this is the location where the original variable ist replaced with the shared version of itself where broadcasting information is missing.I will open a pull request to fix this, I do not anticipate any negative consequences for other parts of pymc3.
Versions and main components
The text was updated successfully, but these errors were encountered: