I have a basic linear regression on the iris dataset and I’m getting a seg fault from theano when I try to sample. This code was working perfectly last night and I haven’t updated any packages meanwhile.
def model_factory(x_in, y_in):
with pm.Model() as model:
# data
x = pm.Data('x', x_in)
y = pm.Data('y', y_in)
# priors on parameters
α = pm.Normal('α', 0, 1)
β = pm.Normal('β', 0, 1)
σ = pm.HalfNormal('σ', 1)
# model
μ = pm.Deterministic('μ', β * x + α)
y_hat = pm.Normal('y_hat', mu=μ, sigma=σ, observed=y)
return model
model = model_factory(iris['sepal_length_z'], iris['petal_width_z'])
with model:
prior = pm.sample_prior_predictive()
This is my setup (windows)
Python implementation: CPython
Python version : 3.7.9
IPython version : 7.19.0
matplotlib: 3.1.2
pymc3 : 3.9.3
numpy : 1.15.4
arviz : 0.10.0
seaborn : 0.11.0
sklearn : 0.23.2
pandas : 1.1.0
theano : 1.0.5
The full traceback
INFO (theano.gof.compilelock): Refreshing lock C:\Users\ruote\AppData\Local\Theano\compiledir_Windows-10-10.0.19041-SP0-Intel64_Family_6_Model_142_Stepping_10_GenuineIntel-3.7.9-64\lock_dir\lock
You can find the C code in this temporary file: C:\Users\ruote\AppData\Local\Temp\theano_compilation_error_o56kkn10
Exception Traceback (most recent call last)
in
1 with model:
2 # Prior sampling, trace definition and posterior sampling
----> 3 prior = pm.sample_prior_predictive()
4 posterior = pm.sample()
5 posterior_pred = pm.sample_posterior_predictive(posterior)
~\Anaconda3\lib\site-packages\pymc3\sampling.py in sample_prior_predictive(samples, model, vars, var_names, random_seed)
1955 names = get_default_varnames(vars_, include_transformed=False)
1956 # draw_values fails with auto-transformed variables. transform them later!
→ 1957 values = draw_values([model[name] for name in names], size=samples)
1958
1959 data = {k: v for k, v in zip(names, values)}
~\Anaconda3\lib\site-packages\pymc3\distributions\distribution.py in draw_values(params, point, size)
652 point=point,
653 givens=temp_givens,
→ 654 size=size)
655 givens[next_.name] = (next_, value)
656 drawn[(next_, size)] = value
~\Anaconda3\lib\site-packages\pymc3\distributions\distribution.py in _draw_value(param, point, givens, size)
833 dist_tmp.shape = distshape
834 try:
→ 835 return dist_tmp.random(point=point, size=size)
836 except (ValueError, TypeError):
837 # reset shape to account for shape changes
~\Anaconda3\lib\site-packages\pymc3\distributions\continuous.py in random(self, point, size)
512 “”"
513 mu, tau, _ = draw_values([self.mu, self.tau, self.sigma],
→ 514 point=point, size=size)
515 return generate_samples(stats.norm.rvs, loc=mu, scale=tau**-0.5,
516 dist_shape=self.shape,
~\Anaconda3\lib\site-packages\pymc3\distributions\distribution.py in draw_values(params, point, size)
696 point=point,
697 givens=givens.values(),
→ 698 size=size)
699 evaluated[param_idx] = drawn[(param, size)] = value
700 givens[param.name] = (param, value)
~\Anaconda3\lib\site-packages\pymc3\distributions\distribution.py in _draw_value(param, point, givens, size)
873 input_vars =
874 input_vals =
→ 875 func = _compile_theano_function(param, input_vars)
876 output = func(*input_vals)
877 return output
~\Anaconda3\lib\site-packages\pymc3\memoize.py in memoizer(*args, **kwargs)
43 cache = getattr(args[0], ‘_cache’)[obj.name]
44 if key not in cache:
—> 45 cache[key] = obj(*args, **kwargs)
46
47 return cache[key]
~\Anaconda3\lib\site-packages\pymc3\distributions\distribution.py in _compile_theano_function(param, vars, givens)
730 rebuild_strict=True,
731 on_unused_input=“ignore”,
→ 732 allow_input_downcast=True,
733 )
734 return vectorize_theano_function(f, inputs=vars, output=param)
~\Anaconda3\lib\site-packages\theano\compile\function.py in function(inputs, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input)
315 on_unused_input=on_unused_input,
316 profile=profile,
→ 317 output_keys=output_keys)
318 return fn
~\Anaconda3\lib\site-packages\theano\compile\pfunc.py in pfunc(params, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys)
484 accept_inplace=accept_inplace, name=name,
485 profile=profile, on_unused_input=on_unused_input,
→ 486 output_keys=output_keys)
487
488
~\Anaconda3\lib\site-packages\theano\compile\function_module.py in orig_function(inputs, outputs, mode, accept_inplace, name, profile, on_unused_input, output_keys)
1839 name=name)
1840 with theano.change_flags(compute_test_value=“off”):
→ 1841 fn = m.create(defaults)
1842 finally:
1843 t2 = time.time()
~\Anaconda3\lib\site-packages\theano\compile\function_module.py in create(self, input_storage, trustme, storage_map)
1713 theano.config.traceback.limit = theano.config.traceback.compile_limit
1714 _fn, _i, _o = self.linker.make_thunk(
→ 1715 input_storage=input_storage_lists, storage_map=storage_map)
1716 finally:
1717 theano.config.traceback.limit = limit_orig
~\Anaconda3\lib\site-packages\theano\gof\link.py in make_thunk(self, input_storage, output_storage, storage_map)
697 return self.make_all(input_storage=input_storage,
698 output_storage=output_storage,
→ 699 storage_map=storage_map)[:3]
700
701 def make_all(self, input_storage, output_storage):
~\Anaconda3\lib\site-packages\theano\gof\vm.py in make_all(self, profiler, input_storage, output_storage, storage_map)
1089 compute_map,
1090 ,
→ 1091 impl=impl))
1092 linker_make_thunk_time[node] = time.time() - thunk_start
1093 if not hasattr(thunks[-1], ‘lazy’):
~\Anaconda3\lib\site-packages\theano\gof\op.py in make_thunk(self, node, storage_map, compute_map, no_recycling, impl)
953 try:
954 return self.make_c_thunk(node, storage_map, compute_map,
→ 955 no_recycling)
956 except (NotImplementedError, utils.MethodNotDefined):
957 # We requested the c code, so don’t catch the error.
~\Anaconda3\lib\site-packages\theano\gof\op.py in make_c_thunk(self, node, storage_map, compute_map, no_recycling)
856 _logger.debug(‘Trying CLinker.make_thunk’)
857 outputs = cl.make_thunk(input_storage=node_input_storage,
→ 858 output_storage=node_output_storage)
859 thunk, node_input_filters, node_output_filters = outputs
860
~\Anaconda3\lib\site-packages\theano\gof\cc.py in make_thunk(self, input_storage, output_storage, storage_map, keep_lock)
1215 cthunk, module, in_storage, out_storage, error_storage = self.compile(
1216 input_storage, output_storage, storage_map,
→ 1217 keep_lock=keep_lock)
1218
1219 res = _CThunk(cthunk, init_tasks, tasks, error_storage, module)
~\Anaconda3\lib\site-packages\theano\gof\cc.py in compile(self, input_storage, output_storage, storage_map, keep_lock)
1155 output_storage,
1156 storage_map,
→ 1157 keep_lock=keep_lock)
1158 return (thunk,
1159 module,
~\Anaconda3\lib\site-packages\theano\gof\cc.py in cthunk_factory(self, error_storage, in_storage, out_storage, storage_map, keep_lock)
1622 node.op.prepare_node(node, storage_map, None, ‘c’)
1623 module = get_module_cache().module_from_key(
→ 1624 key=key, lnk=self, keep_lock=keep_lock)
1625
1626 vars = self.inputs + self.outputs + self.orphans
~\Anaconda3\lib\site-packages\theano\gof\cmodule.py in module_from_key(self, key, lnk, keep_lock)
1187 try:
1188 location = dlimport_workdir(self.dirname)
→ 1189 module = lnk.compile_cmodule(location)
1190 name = module.file
1191 assert name.startswith(location)
~\Anaconda3\lib\site-packages\theano\gof\cc.py in compile_cmodule(self, location)
1525 lib_dirs=self.lib_dirs(),
1526 libs=libs,
→ 1527 preargs=preargs)
1528 except Exception as e:
1529 e.args += (str(self.fgraph),)
~\Anaconda3\lib\site-packages\theano\gof\cmodule.py in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
2409 # difficult to read.
2410 raise Exception(‘Compilation failed (return status=%s): %s’ %
→ 2411 (status, compile_stderr.replace(‘\n’, '. ')))
2412 elif config.cmodule.compilation_warning and compile_stderr:
2413 # Print errors just below the command line.
Exception: (‘The following error happened while compiling the node’, Elemwise{Composite{inv(sqr(i0))}}(σ), ‘\n’, 'Compilation failed (return status=1): C:\Users\ruote\AppData\Local\Theano\compiledir_Windows-10-10.0.19041-SP0-Intel64_Family_6_Model_142_Stepping_10_GenuineIntel-3.7.9-64\tmpif91__7p\mod.cpp:315:1: internal compiler error: Segmentation fault\r. V1_i = 1.0 / V5_tmp1;\r. ^\r. libbacktrace could not find executable to open\r. Please submit a full bug report,\r. with preprocessed source if appropriate.\r. See https://sourceforge.net/projects/msys2 for instructions.\r. ', ‘[Elemwise{Composite{inv(sqr(i0))}}(σ)]’)