Ошибка компиляции с pymc3 и theano при запуске байесовской иерархической модели - PullRequest
0 голосов
/ 26 мая 2020

Я использую байесовскую иерархическую модель на pymc3 и theano. Когда я начинаю тренировать свою модель, я получаю эту ошибку:

 WARNING (theano.gof.compilelock): Overriding existing lock by dead process '16490' (I am process '7448')
/opt/anaconda3/lib/python3.7/site-packages/theano/tensor/subtensor.py:2197: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  rval = inputs[0].__getitem__(inputs[1:])
/opt/anaconda3/lib/python3.7/site-packages/theano/tensor/subtensor.py:2339: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  out[0][inputs[2:]] = inputs[1]

You can find the C code in this temporary file: /var/folders/dd/kb4xb1px7zxc5cwdk799b46c0000gn/T/theano_compilation_error_2qgug1um
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-3-67e4a92cfa79> in <module>
     29             mu=0, sd=1, shape=n_regs_in_net)
     30         mvg_regs = pm.MvNormal('MVG_%s_regs' % cur_netname,
---> 31             mu=mvg_mu, chol=chol, shape=n_regs_in_net)
     32
     33         # per region in the current network

/opt/anaconda3/lib/python3.7/site-packages/pymc3/distributions/distribution.py in __new__(cls, name, *args, **kwargs)
     45             total_size = kwargs.pop('total_size', None)
     46             dist = cls.dist(*args, **kwargs)
---> 47             return model.Var(name, dist, data, total_size)
     48         else:
     49             raise TypeError("Name needs to be a string but got: {}".format(name))

/opt/anaconda3/lib/python3.7/site-packages/pymc3/model.py in Var(self, name, dist, data, total_size)
    920                 with self:
    921                     var = FreeRV(name=name, distribution=dist,
--> 922                                  total_size=total_size, model=self)
    923                 self.free_RVs.append(var)
    924             else:

/opt/anaconda3/lib/python3.7/site-packages/pymc3/model.py in __init__(self, type, owner, index, name, distribution, total_size, model)
   1368             self.tag.test_value = np.ones(
   1369                 distribution.shape, distribution.dtype) * distribution.default()
-> 1370             self.logp_elemwiset = distribution.logp(self)
   1371             # The logp might need scaling in minibatches.
   1372             # This is done in `Factor`.

/opt/anaconda3/lib/python3.7/site-packages/pymc3/distributions/multivariate.py in logp(self, value)
    313         TensorVariable
    314         """
--> 315         quaddist, logdet, ok = self._quaddist(value)
    316         k = value.shape[-1].astype(theano.config.floatX)
    317         norm = - 0.5 * k * pm.floatX(np.log(2 * np.pi))

/opt/anaconda3/lib/python3.7/site-packages/pymc3/distributions/multivariate.py in _quaddist(self, value)
     91             onedim = False
     92
---> 93         delta = value - mu
     94
     95         if self._cov_type == 'cov':

/opt/anaconda3/lib/python3.7/site-packages/theano/tensor/var.py in __sub__(self, other)
    145         # and the return value in that case
    146         try:
--> 147             return theano.tensor.basic.sub(self, other)
    148         except (NotImplementedError, AsTensorError):
    149             return NotImplemented

/opt/anaconda3/lib/python3.7/site-packages/theano/gof/op.py in __call__(self, *inputs, **kwargs)
    668                 # compute output value once with test inputs to validate graph
    669                 thunk = node.op.make_thunk(node, storage_map, compute_map,
--> 670                                            no_recycling=[])
    671                 thunk.inputs = [storage_map[v] for v in node.inputs]
    672                 thunk.outputs = [storage_map[v] for v in node.outputs]

/opt/anaconda3/lib/python3.7/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.

/opt/anaconda3/lib/python3.7/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

/opt/anaconda3/lib/python3.7/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)

/opt/anaconda3/lib/python3.7/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,

/opt/anaconda3/lib/python3.7/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

/opt/anaconda3/lib/python3.7/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)

/opt/anaconda3/lib/python3.7/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),)

/opt/anaconda3/lib/python3.7/site-packages/theano/gof/cmodule.py in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
   2397             # difficult to read.
   2398             raise Exception('Compilation failed (return status=%s): %s' %
-> 2399                             (status, compile_stderr.replace('\n', '. ')))
   2400         elif config.cmodule.compilation_warning and compile_stderr:
   2401             # Print errors just below the command line.

Exception: ("Compilation failed (return status=1): /Users/emdim/.theano/compiledir_Darwin-18.7.0-x86_64-i386-64bit-i386-3.7.6-64/tmppq1_q56w/mod.cpp:544:27: error: non-constant-expression cannot be narrowed from type 'npy_intp' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing].     int init_totals[2] = {V1_n0, V3_n1};.                           ^~~~~. /Users/emdim/.theano/compiledir_Darwin-18.7.0-x86_64-i386-64bit-i386-3.7.6-64/tmppq1_q56w/mod.cpp:544:27: note: insert an explicit cast to silence this issue.     int init_totals[2] = {V1_n0, V3_n1};.                           ^~~~~.                           static_cast<int>( ). /Users/emdim/.theano/compiledir_Darwin-18.7.0-x86_64-i386-64bit-i386-3.7.6-64/tmppq1_q56w/mod.cpp:544:34: error: non-constant-expression cannot be narrowed from type 'npy_intp' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing].     int init_totals[2] = {V1_n0, V3_n1};.                                  ^~~~~. /Users/emdim/.theano/compiledir_Darwin-18.7.0-x86_64-i386-64bit-i386-3.7.6-64/tmppq1_q56w/mod.cpp:544:34: note: insert an explicit cast to silence this issue.     int init_totals[2] = {V1_n0, V3_n1};.                                  ^~~~~.                                  static_cast<int>( ). /Users/emdim/.theano/compiledir_Darwin-18.7.0-x86_64-i386-64bit-i386-3.7.6-64/tmppq1_q56w/mod.cpp:556:12: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing].         0, V3_stride1, .            ^~~~~~~~~~. /Users/emdim/.theano/compiledir_Darwin-18.7.0-x86_64-i386-64bit-i386-3.7.6-64/tmppq1_q56w/mod.cpp:556:12: note: insert an explicit cast to silence this issue.         0, V3_stride1, .            ^~~~~~~~~~.            static_cast<int>( ). /Users/emdim/.theano/compiledir_Darwin-18.7.0-x86_64-i386-64bit-i386-3.7.6-64/tmppq1_q56w/mod.cpp:557:4: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing]. 0, V5_stride1, .    ^~~~~~~~~~. /Users/emdim/.theano/compiledir_Darwin-18.7.0-x86_64-i386-64bit-i386-3.7.6-64/tmppq1_q56w/mod.cpp:557:4: note: insert an explicit cast to silence this issue. 0, V5_stride1, .    ^~~~~~~~~~.    static_cast<int>( ). /Users/emdim/.theano/compiledir_Darwin-18.7.0-x86_64-i386-64bit-i386-3.7.6-64/tmppq1_q56w/mod.cpp:558:1: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing]. V1_stride0, V1_stride1. ^~~~~~~~~~. /Users/emdim/.theano/compiledir_Darwin-18.7.0-x86_64-i386-64bit-i386-3.7.6-64/tmppq1_q56w/mod.cpp:558:1: note: insert an explicit cast to silence this issue. V1_stride0, V1_stride1. ^~~~~~~~~~. static_cast<int>( ). /Users/emdim/.theano/compiledir_Darwin-18.7.0-x86_64-i386-64bit-i386-3.7.6-64/tmppq1_q56w/mod.cpp:558:13: error: non-constant-expression cannot be narrowed from type 'ssize_t' (aka 'long') to 'int' in initializer list [-Wc++11-narrowing]. V1_stride0, V1_stride1.             ^~~~~~~~~~. /Users/emdim/.theano/compiledir_Darwin-18.7.0-x86_64-i386-64bit-i386-3.7.6-64/tmppq1_q56w/mod.cpp:558:13: note: insert an explicit cast to silence this issue. V1_stride0, V1_stride1.             ^~~~~~~~~~.             static_cast<int>( ). 6 errors generated.. ", '[Elemwise{sub,no_inplace}(<TensorType(float64, row)>, <TensorType(float64, row)>)]')

Может ли кто-нибудь помочь мне отладить это? Коллега попытался ie запустить его на своей машине, и он сработал, так что я предполагаю, что это связано с моей машиной или, возможно, с версией theano или pymc3.

Или, может быть, это связано с формой аргумент, но я снова skepti c, так как он работал на машине моего коллеги. Я также попытался запустить следующую команду, но я не уверен, что она делает, и боюсь, что она просто скрывала предупреждения и важные сообщения

theano.config.gcc.cxxflags = "-Wno-c++11-narrowing"

Наконец, для байесовских программистов (возможно, это может помочь) нецентрированная репараметризация Холецкого сработала и скомпилировала без ошибок. Пожалуйста, помогите мне

Спасибо

...