Hi @jessegrabowski, thanks for taking the time to write a great reply! I learn a lot about aesara
from your answers.
Plugging the sparse matrices code that you provided into the model and fitting the model to a subset of data (e.g., 20 time sequences), everything works great! But when running for the model on the full data set (e.g., ~2000 time sequences), I get the following error message. Is it something to do with memory constraints? Have you seen something like this before?
CompileError Traceback (most recent call last)
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/vm.py:1245, in VMLinker.make_all(self, profiler, input_storage, output_storage, storage_map)
1241 # no-recycling is done at each VM.__call__ So there is
1242 # no need to cause duplicate c code by passing
1243 # no_recycling here.
1244 thunks.append(
-> 1245 node.op.make_thunk(node, storage_map, compute_map, [], impl=impl)
1246 )
1247 linker_make_thunk_time[node] = time.time() - thunk_start
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/op.py:131, in COp.make_thunk(self, node, storage_map, compute_map, no_recycling, impl)
130 try:
--> 131 return self.make_c_thunk(node, storage_map, compute_map, no_recycling)
132 except (NotImplementedError, MethodNotDefined):
133 # We requested the c code, so don't catch the error.
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/op.py:96, in COp.make_c_thunk(self, node, storage_map, compute_map, no_recycling)
95 raise NotImplementedError("float16")
---> 96 outputs = cl.make_thunk(
97 input_storage=node_input_storage, output_storage=node_output_storage
98 )
99 thunk, node_input_filters, node_output_filters = outputs
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/basic.py:1198, in CLinker.make_thunk(self, input_storage, output_storage, storage_map)
1197 init_tasks, tasks = self.get_init_tasks()
-> 1198 cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
1199 input_storage, output_storage, storage_map
1200 )
1202 res = _CThunk(cthunk, init_tasks, tasks, error_storage, module)
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/basic.py:1133, in CLinker.__compile__(self, input_storage, output_storage, storage_map)
1132 output_storage = tuple(output_storage)
-> 1133 thunk, module = self.cthunk_factory(
1134 error_storage,
1135 input_storage,
1136 output_storage,
1137 storage_map,
1138 )
1139 return (
1140 thunk,
1141 module,
(...)
1150 error_storage,
1151 )
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/basic.py:1629, in CLinker.cthunk_factory(self, error_storage, in_storage, out_storage, storage_map)
1628 node.op.prepare_node(node, storage_map, None, "c")
-> 1629 module = get_module_cache().module_from_key(key=key, lnk=self)
1631 vars = self.inputs + self.outputs + self.orphans
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/cmodule.py:1223, in ModuleCache.module_from_key(self, key, lnk)
1222 location = dlimport_workdir(self.dirname)
-> 1223 module = lnk.compile_cmodule(location)
1224 name = module.__file__
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/basic.py:1538, in CLinker.compile_cmodule(self, location)
1537 _logger.debug(f"LOCATION {location}")
-> 1538 module = c_compiler.compile_str(
1539 module_name=mod.code_hash,
1540 src_code=src_code,
1541 location=location,
1542 include_dirs=self.header_dirs(),
1543 lib_dirs=self.lib_dirs(),
1544 libs=libs,
1545 preargs=preargs,
1546 )
1547 except Exception as e:
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/cmodule.py:2636, in GCC_compiler.compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
2632 # We replace '\n' by '. ' in the error message because when Python
2633 # prints the exception, having '\n' in the text makes it more
2634 # difficult to read.
2635 # compile_stderr = compile_stderr.replace("\n", ". ")
-> 2636 raise CompileError(
2637 f"Compilation failed (return status={status}):\n{' '.join(cmd)}\n{compile_stderr}"
2638 )
2639 elif config.cmodule__compilation_warning and compile_stderr:
2640 # Print errors just below the command line.
CompileError: Compilation failed (return status=1):
/Users/conor/miniconda3/envs/pymc_non_dev/bin/clang++ -dynamiclib -g -O3 -fno-math-errno -Wno-unused-label -Wno-unused-variable -Wno-write-strings -Wno-c++11-narrowing -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -fPIC -undefined dynamic_lookup -I/Users/conor/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/numpy/core/include -I/Users/conor/miniconda3/envs/pymc_non_dev/include/python3.10 -I/Users/conor/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/c_code -L/Users/conor/miniconda3/envs/pymc_non_dev/lib -fvisibility=hidden -o /Users/conor/.aesara/compiledir_macOS-12.4-arm64-arm-64bit-arm-3.10.5-64/tmprd_gvep5/m5d0ee6bbad3216d425b6f97b97d8e0d98406727e7556194d542dc09b367c4d92.so /Users/conor/.aesara/compiledir_macOS-12.4-arm64-arm-64bit-arm-3.10.5-64/tmprd_gvep5/mod.cpp
/Users/conor/.aesara/compiledir_macOS-12.4-arm64-arm-64bit-arm-3.10.5-64/tmprd_gvep5/mod.cpp:53956:32: fatal error: bracket nesting level exceeded maximum of 256
if (!PyErr_Occurred()) {
^
/Users/conor/.aesara/compiledir_macOS-12.4-arm64-arm-64bit-arm-3.10.5-64/tmprd_gvep5/mod.cpp:53956:32: note: use -fbracket-depth=N to increase maximum nesting level
1 error generated.
During handling of the above exception, another exception occurred:
CompileError Traceback (most recent call last)
/Users/conor/Library/CloudStorage/OneDrive-QueenslandUniversityofTechnology/Documents/AustralianCancerAtlasPyMC/data-wrangling.ipynb Cell 27' in <cell line: 1>()
1 with spline_temporal_model:
----> 2 spline_fit = pm.fit(n=100000)
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/pymc/variational/inference.py:744, in fit(n, method, model, random_seed, start, inf_kwargs, **kwargs)
742 else:
743 raise TypeError(f"method should be one of {set(_select.keys())} or Inference instance")
--> 744 return inference.fit(n, **kwargs)
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/pymc/variational/inference.py:138, in Inference.fit(self, n, score, callbacks, progressbar, **kwargs)
136 callbacks = []
137 score = self._maybe_score(score)
--> 138 step_func = self.objective.step_function(score=score, **kwargs)
139 if progressbar:
140 progress = progress_bar(range(n), display=progressbar)
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/configparser.py:47, in _ChangeFlagsDecorator.__call__.<locals>.res(*args, **kwargs)
44 @wraps(f)
45 def res(*args, **kwargs):
46 with self:
---> 47 return f(*args, **kwargs)
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/pymc/variational/opvi.py:367, in ObjectiveFunction.step_function(self, obj_n_mc, tf_n_mc, obj_optimizer, test_optimizer, more_obj_params, more_tf_params, more_updates, more_replacements, total_grad_norm_constraint, score, fn_kwargs)
355 updates = self.updates(
356 obj_n_mc=obj_n_mc,
357 tf_n_mc=tf_n_mc,
(...)
364 total_grad_norm_constraint=total_grad_norm_constraint,
365 )
366 if score:
--> 367 step_fn = compile_pymc([], updates.loss, updates=updates, **fn_kwargs)
368 else:
369 step_fn = compile_pymc([], [], updates=updates, **fn_kwargs)
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/pymc/aesaraf.py:1034, in compile_pymc(inputs, outputs, random_seed, mode, **kwargs)
1032 opt_qry = mode.provided_optimizer.including("random_make_inplace", check_parameter_opt)
1033 mode = Mode(linker=mode.linker, optimizer=opt_qry)
-> 1034 aesara_function = aesara.function(
1035 inputs,
1036 outputs,
1037 updates={**rng_updates, **kwargs.pop("updates", {})},
1038 mode=mode,
1039 **kwargs,
1040 )
1041 return aesara_function
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/compile/function/__init__.py:317, in function(inputs, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input)
311 fn = orig_function(
312 inputs, outputs, mode=mode, accept_inplace=accept_inplace, name=name
313 )
314 else:
315 # note: pfunc will also call orig_function -- orig_function is
316 # a choke point that all compilation must pass through
--> 317 fn = pfunc(
318 params=inputs,
319 outputs=outputs,
320 mode=mode,
321 updates=updates,
322 givens=givens,
323 no_default_updates=no_default_updates,
324 accept_inplace=accept_inplace,
325 name=name,
326 rebuild_strict=rebuild_strict,
327 allow_input_downcast=allow_input_downcast,
328 on_unused_input=on_unused_input,
329 profile=profile,
330 output_keys=output_keys,
331 )
332 return fn
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/compile/function/pfunc.py:374, in pfunc(params, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys, fgraph)
360 profile = ProfileStats(message=profile)
362 inputs, cloned_outputs = construct_pfunc_ins_and_outs(
363 params,
364 outputs,
(...)
371 fgraph=fgraph,
372 )
--> 374 return orig_function(
375 inputs,
376 cloned_outputs,
377 mode,
378 accept_inplace=accept_inplace,
379 name=name,
380 profile=profile,
381 on_unused_input=on_unused_input,
382 output_keys=output_keys,
383 fgraph=fgraph,
384 )
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/compile/function/types.py:1763, in orig_function(inputs, outputs, mode, accept_inplace, name, profile, on_unused_input, output_keys, fgraph)
1751 m = Maker(
1752 inputs,
1753 outputs,
(...)
1760 fgraph=fgraph,
1761 )
1762 with config.change_flags(compute_test_value="off"):
-> 1763 fn = m.create(defaults)
1764 finally:
1765 t2 = time.time()
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/compile/function/types.py:1656, in FunctionMaker.create(self, input_storage, trustme, storage_map)
1653 start_import_time = aesara.link.c.cmodule.import_time
1655 with config.change_flags(traceback__limit=config.traceback__compile_limit):
-> 1656 _fn, _i, _o = self.linker.make_thunk(
1657 input_storage=input_storage_lists, storage_map=storage_map
1658 )
1660 end_linker = time.time()
1662 linker_time = end_linker - start_linker
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/basic.py:254, in LocalLinker.make_thunk(self, input_storage, output_storage, storage_map, **kwargs)
247 def make_thunk(
248 self,
249 input_storage: Optional["InputStorageType"] = None,
(...)
252 **kwargs,
253 ) -> Tuple["BasicThunkType", "InputStorageType", "OutputStorageType"]:
--> 254 return self.make_all(
255 input_storage=input_storage,
256 output_storage=output_storage,
257 storage_map=storage_map,
258 )[:3]
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/vm.py:1254, in VMLinker.make_all(self, profiler, input_storage, output_storage, storage_map)
1252 thunks[-1].lazy = False
1253 except Exception:
-> 1254 raise_with_op(fgraph, node)
1256 t1 = time.time()
1258 if self.profile:
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/utils.py:534, in raise_with_op(fgraph, node, thunk, exc_info, storage_map)
529 warnings.warn(
530 f"{exc_type} error does not allow us to add an extra error message"
531 )
532 # Some exception need extra parameter in inputs. So forget the
533 # extra long error message in that case.
--> 534 raise exc_value.with_traceback(exc_trace)
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/vm.py:1245, in VMLinker.make_all(self, profiler, input_storage, output_storage, storage_map)
1240 thunk_start = time.time()
1241 # no-recycling is done at each VM.__call__ So there is
1242 # no need to cause duplicate c code by passing
1243 # no_recycling here.
1244 thunks.append(
-> 1245 node.op.make_thunk(node, storage_map, compute_map, [], impl=impl)
1246 )
1247 linker_make_thunk_time[node] = time.time() - thunk_start
1248 if not hasattr(thunks[-1], "lazy"):
1249 # We don't want all ops maker to think about lazy Ops.
1250 # So if they didn't specify that its lazy or not, it isn't.
1251 # If this member isn't present, it will crash later.
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/op.py:131, in COp.make_thunk(self, node, storage_map, compute_map, no_recycling, impl)
127 self.prepare_node(
128 node, storage_map=storage_map, compute_map=compute_map, impl="c"
129 )
130 try:
--> 131 return self.make_c_thunk(node, storage_map, compute_map, no_recycling)
132 except (NotImplementedError, MethodNotDefined):
133 # We requested the c code, so don't catch the error.
134 if impl == "c":
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/op.py:96, in COp.make_c_thunk(self, node, storage_map, compute_map, no_recycling)
94 print(f"Disabling C code for {self} due to unsupported float16")
95 raise NotImplementedError("float16")
---> 96 outputs = cl.make_thunk(
97 input_storage=node_input_storage, output_storage=node_output_storage
98 )
99 thunk, node_input_filters, node_output_filters = outputs
101 @is_cthunk_wrapper_type
102 def rval():
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/basic.py:1198, in CLinker.make_thunk(self, input_storage, output_storage, storage_map)
1170 """
1171 Compiles this linker's fgraph and returns a function to perform the
1172 computations, as well as lists of storage cells for both the inputs
(...)
1195 first_output = ostor[0].data
1196 """
1197 init_tasks, tasks = self.get_init_tasks()
-> 1198 cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
1199 input_storage, output_storage, storage_map
1200 )
1202 res = _CThunk(cthunk, init_tasks, tasks, error_storage, module)
1203 res.nodes = self.node_order
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/basic.py:1133, in CLinker.__compile__(self, input_storage, output_storage, storage_map)
1131 input_storage = tuple(input_storage)
1132 output_storage = tuple(output_storage)
-> 1133 thunk, module = self.cthunk_factory(
1134 error_storage,
1135 input_storage,
1136 output_storage,
1137 storage_map,
1138 )
1139 return (
1140 thunk,
1141 module,
(...)
1150 error_storage,
1151 )
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/basic.py:1629, in CLinker.cthunk_factory(self, error_storage, in_storage, out_storage, storage_map)
1627 for node in self.node_order:
1628 node.op.prepare_node(node, storage_map, None, "c")
-> 1629 module = get_module_cache().module_from_key(key=key, lnk=self)
1631 vars = self.inputs + self.outputs + self.orphans
1632 # List of indices that should be ignored when passing the arguments
1633 # (basically, everything that the previous call to uniq eliminated)
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/cmodule.py:1223, in ModuleCache.module_from_key(self, key, lnk)
1221 try:
1222 location = dlimport_workdir(self.dirname)
-> 1223 module = lnk.compile_cmodule(location)
1224 name = module.__file__
1225 assert name.startswith(location)
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/basic.py:1538, in CLinker.compile_cmodule(self, location)
1536 try:
1537 _logger.debug(f"LOCATION {location}")
-> 1538 module = c_compiler.compile_str(
1539 module_name=mod.code_hash,
1540 src_code=src_code,
1541 location=location,
1542 include_dirs=self.header_dirs(),
1543 lib_dirs=self.lib_dirs(),
1544 libs=libs,
1545 preargs=preargs,
1546 )
1547 except Exception as e:
1548 e.args += (str(self.fgraph),)
File ~/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/cmodule.py:2636, in GCC_compiler.compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
2628 print(
2629 "Check if package python-dev or python-devel is installed."
2630 )
2632 # We replace '\n' by '. ' in the error message because when Python
2633 # prints the exception, having '\n' in the text makes it more
2634 # difficult to read.
2635 # compile_stderr = compile_stderr.replace("\n", ". ")
-> 2636 raise CompileError(
2637 f"Compilation failed (return status={status}):\n{' '.join(cmd)}\n{compile_stderr}"
2638 )
2639 elif config.cmodule__compilation_warning and compile_stderr:
2640 # Print errors just below the command line.
2641 print(compile_stderr)
CompileError: Compilation failed (return status=1):
/Users/conor/miniconda3/envs/pymc_non_dev/bin/clang++ -dynamiclib -g -O3 -fno-math-errno -Wno-unused-label -Wno-unused-variable -Wno-write-strings -Wno-c++11-narrowing -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -fPIC -undefined dynamic_lookup -I/Users/conor/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/numpy/core/include -I/Users/conor/miniconda3/envs/pymc_non_dev/include/python3.10 -I/Users/conor/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/link/c/c_code -L/Users/conor/miniconda3/envs/pymc_non_dev/lib -fvisibility=hidden -o /Users/conor/.aesara/compiledir_macOS-12.4-arm64-arm-64bit-arm-3.10.5-64/tmprd_gvep5/m5d0ee6bbad3216d425b6f97b97d8e0d98406727e7556194d542dc09b367c4d92.so /Users/conor/.aesara/compiledir_macOS-12.4-arm64-arm-64bit-arm-3.10.5-64/tmprd_gvep5/mod.cpp
/Users/conor/.aesara/compiledir_macOS-12.4-arm64-arm-64bit-arm-3.10.5-64/tmprd_gvep5/mod.cpp:53956:32: fatal error: bracket nesting level exceeded maximum of 256
if (!PyErr_Occurred()) {
^
/Users/conor/.aesara/compiledir_macOS-12.4-arm64-arm-64bit-arm-3.10.5-64/tmprd_gvep5/mod.cpp:53956:32: note: use -fbracket-depth=N to increase maximum nesting level
1 error generated.
Apply node that caused the error: Split{2148}(Elemwise{Mul}[(0, 0)].0, TensorConstant{0}, TensorConstant{(2148,) of 11})
Toposort index: 135
Inputs types: [TensorType(float64, (None, None)), TensorType(int8, ()), TensorType(int64, (2148,))]
Backtrace when the node is created (use Aesara flag traceback__limit=N to make it longer):
File "/Users/conor/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/gradient.py", line 1387, in access_grad_cache
term = access_term_cache(node)[idx]
File "/Users/conor/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/gradient.py", line 1058, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File "/Users/conor/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/gradient.py", line 1058, in <listcomp>
output_grads = [access_grad_cache(var) for var in node.outputs]
File "/Users/conor/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/gradient.py", line 1387, in access_grad_cache
term = access_term_cache(node)[idx]
File "/Users/conor/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/gradient.py", line 1058, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File "/Users/conor/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/gradient.py", line 1058, in <listcomp>
output_grads = [access_grad_cache(var) for var in node.outputs]
File "/Users/conor/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/gradient.py", line 1387, in access_grad_cache
term = access_term_cache(node)[idx]
File "/Users/conor/miniconda3/envs/pymc_non_dev/lib/python3.10/site-packages/aesara/gradient.py", line 1213, in access_term_cache
input_grads = node.op.L_op(inputs, node.outputs, new_output_grads)
HINT: Use a linker other than the C linker to print the inputs' shapes and strides.
HINT: Use the Aesara flag `exception_verbosity=high` for a debug print-out and storage map footprint of this Apply node.