-
Notifications
You must be signed in to change notification settings - Fork 20
Closed
pymc-devs/pytensor
#255Description
I'm trying to use nutpie to speed up an ICM GP model. I've run the model through pymc without errors but once I call the command nutpie.compile_pymc_model(icm) I get the following error message:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function numba_funcify_Elemwise.<locals>.elemwise at 0x18dfcdea0>) found for signature:
>>> elemwise(readonly array(float64, 0d, C), readonly array(float64, 0d, C), float64, array(float64, 0d, C))
For completeness here is full output
TypingError Traceback (most recent call last)
File <timed exec>:2
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/nutpie/compile_pymc.py:121, in compile_pymc_model(model, **kwargs)
116 user_data = make_user_data(logp_fn_pt, shared_data)
118 logp_numba_raw, c_sig = _make_c_logp_func(
119 n_dim, logp_fn, user_data, shared_logp, shared_data
120 )
--> 121 logp_numba = numba.cfunc(c_sig, **kwargs)(logp_numba_raw)
123 def expand_draw(x, seed, chain, draw, *, shared_data):
124 return expand_fn(x, **{name: shared_data[name] for name in shared_expand})[0]
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/decorators.py:282, in cfunc.<locals>.wrapper(func)
280 if cache:
281 res.enable_caching()
--> 282 res.compile()
283 return res
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/compiler_lock.py:35, in _CompilerLock.__call__.<locals>._acquire_compile_lock(*args, **kwargs)
32 @functools.wraps(func)
33 def _acquire_compile_lock(*args, **kwargs):
34 with self:
---> 35 return func(*args, **kwargs)
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/ccallback.py:67, in CFunc.compile(self)
64 cres = self._cache.load_overload(self._sig,
65 self._targetdescr.target_context)
66 if cres is None:
---> 67 cres = self._compile_uncached()
68 self._cache.save_overload(self._sig, cres)
69 else:
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/ccallback.py:81, in CFunc._compile_uncached(self)
78 sig = self._sig
80 # Compile native function as well as cfunc wrapper
---> 81 return self._compiler.compile(sig.args, sig.return_type)
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/dispatcher.py:129, in _FunctionCompiler.compile(self, args, return_type)
127 return retval
128 else:
--> 129 raise retval
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/dispatcher.py:139, in _FunctionCompiler._compile_cached(self, args, return_type)
136 pass
138 try:
--> 139 retval = self._compile_core(args, return_type)
140 except errors.TypingError as e:
141 self._failed_cache[key] = e
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/dispatcher.py:152, in _FunctionCompiler._compile_core(self, args, return_type)
149 flags = self._customize_flags(flags)
151 impl = self._get_implementation(args, {})
--> 152 cres = compiler.compile_extra(self.targetdescr.typing_context,
153 self.targetdescr.target_context,
154 impl,
155 args=args, return_type=return_type,
156 flags=flags, locals=self.locals,
157 pipeline_class=self.pipeline_class)
158 # Check typing error if object mode is used
159 if cres.typing_error is not None and not flags.enable_pyobject:
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/compiler.py:716, in compile_extra(typingctx, targetctx, func, args, return_type, flags, locals, library, pipeline_class)
692 """Compiler entry point
693
694 Parameter
(...)
712 compiler pipeline
713 """
714 pipeline = pipeline_class(typingctx, targetctx, library,
715 args, return_type, flags, locals)
--> 716 return pipeline.compile_extra(func)
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/compiler.py:452, in CompilerBase.compile_extra(self, func)
450 self.state.lifted = ()
451 self.state.lifted_from = None
--> 452 return self._compile_bytecode()
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/compiler.py:520, in CompilerBase._compile_bytecode(self)
516 """
517 Populate and run pipeline for bytecode input
518 """
519 assert self.state.func_ir is None
--> 520 return self._compile_core()
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/compiler.py:499, in CompilerBase._compile_core(self)
497 self.state.status.fail_reason = e
498 if is_final_pipeline:
--> 499 raise e
500 else:
501 raise CompilerError("All available pipelines exhausted")
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/compiler.py:486, in CompilerBase._compile_core(self)
484 res = None
485 try:
--> 486 pm.run(self.state)
487 if self.state.cr is not None:
488 break
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/compiler_machinery.py:368, in PassManager.run(self, state)
365 msg = "Failed in %s mode pipeline (step: %s)" % \
366 (self.pipeline_name, pass_desc)
367 patched_exception = self._patch_error(msg, e)
--> 368 raise patched_exception
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/compiler_machinery.py:356, in PassManager.run(self, state)
354 pass_inst = _pass_registry.get(pss).pass_inst
355 if isinstance(pass_inst, CompilerPass):
--> 356 self._runPass(idx, pass_inst, state)
357 else:
358 raise BaseException("Legacy pass in use")
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/compiler_lock.py:35, in _CompilerLock.__call__.<locals>._acquire_compile_lock(*args, **kwargs)
32 @functools.wraps(func)
33 def _acquire_compile_lock(*args, **kwargs):
34 with self:
---> 35 return func(*args, **kwargs)
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/compiler_machinery.py:311, in PassManager._runPass(self, index, pss, internal_state)
309 mutated |= check(pss.run_initialization, internal_state)
310 with SimpleTimer() as pass_time:
--> 311 mutated |= check(pss.run_pass, internal_state)
312 with SimpleTimer() as finalize_time:
313 mutated |= check(pss.run_finalizer, internal_state)
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/compiler_machinery.py:273, in PassManager._runPass.<locals>.check(func, compiler_state)
272 def check(func, compiler_state):
--> 273 mangled = func(compiler_state)
274 if mangled not in (True, False):
275 msg = ("CompilerPass implementations should return True/False. "
276 "CompilerPass with name '%s' did not.")
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/typed_passes.py:105, in BaseTypeInference.run_pass(self, state)
99 """
100 Type inference and legalization
101 """
102 with fallback_context(state, 'Function "%s" failed type inference'
103 % (state.func_id.func_name,)):
104 # Type inference
--> 105 typemap, return_type, calltypes, errs = type_inference_stage(
106 state.typingctx,
107 state.targetctx,
108 state.func_ir,
109 state.args,
110 state.return_type,
111 state.locals,
112 raise_errors=self._raise_errors)
113 state.typemap = typemap
114 # save errors in case of partial typing
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/typed_passes.py:83, in type_inference_stage(typingctx, targetctx, interp, args, return_type, locals, raise_errors)
81 infer.build_constraint()
82 # return errors in case of partial typing
---> 83 errs = infer.propagate(raise_errors=raise_errors)
84 typemap, restype, calltypes = infer.unify(raise_errors=raise_errors)
86 # Output all Numba warnings
File ~/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/typeinfer.py:1086, in TypeInferer.propagate(self, raise_errors)
1083 force_lit_args = [e for e in errors
1084 if isinstance(e, ForceLiteralArg)]
1085 if not force_lit_args:
-> 1086 raise errors[0]
1087 else:
1088 raise reduce(operator.or_, force_lit_args)
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function numba_funcify_Elemwise.<locals>.elemwise at 0x18dfcdea0>) found for signature:
>>> elemwise(readonly array(float64, 0d, C), readonly array(float64, 0d, C), float64, array(float64, 0d, C))
There are 2 candidate implementations:
- Of which 2 did not match due to:
Overload in function 'numba_funcify_Elemwise.<locals>.ov_elemwise': File: pytensor/link/numba/dispatch/elemwise.py: Line 687.
With argument(s): '(readonly array(float64, 0d, C), readonly array(float64, 0d, C), float64, array(float64, 0d, C))':
Rejected as the implementation raised a specific error:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<intrinsic _vectorized>) found for signature:
>>> _vectorized(type(CPUDispatcher(<function numba_funcified_fgraph at 0x18dfcfbe0>)), Literal[str](gASVCAAAAAAAAAAoKSkpKXSULg==
), Literal[str](gASVBAAAAAAAAAAphZQu
), Literal[str](gASVDQAAAAAAAACMB2Zsb2F0NjSUhZQu
), Literal[str](gASVCQAAAAAAAABLAEsChpSFlC4=
), StarArgTuple(readonly array(float64, 0d, C), readonly array(float64, 0d, C), float64, array(float64, 0d, C)))
There are 2 candidate implementations:
- Of which 1 did not match due to:
Intrinsic in function '_vectorized': File: pytensor/link/numba/dispatch/elemwise.py: Line 466.
With argument(s): '(type(CPUDispatcher(<function numba_funcified_fgraph at 0x18dfcfbe0>)), unicode_type, unicode_type, unicode_type, unicode_type, StarArgTuple(readonly array(float64, 0d, C), readonly array(float64, 0d, C), float64, array(float64, 0d, C)))':
Rejected as the implementation raised a specific error:
TypingError: input_bc_patterns must be literal.
raised from /Users/bpajusco/opt/anaconda3/envs/fast/lib/python3.10/site-packages/pytensor/link/numba/dispatch/elemwise.py:486
- Of which 1 did not match due to:
Intrinsic in function '_vectorized': File: pytensor/link/numba/dispatch/elemwise.py: Line 466.
With argument(s): '(type(CPUDispatcher(<function numba_funcified_fgraph at 0x18dfcfbe0>)), Literal[str](gASVCAAAAAAAAAAoKSkpKXSULg==
), Literal[str](gASVBAAAAAAAAAAphZQu
), Literal[str](gASVDQAAAAAAAACMB2Zsb2F0NjSUhZQu
), Literal[str](gASVCQAAAAAAAABLAEsChpSFlC4=
), StarArgTuple(readonly array(float64, 0d, C), readonly array(float64, 0d, C), float64, array(float64, 0d, C)))':
Rejected as the implementation raised a specific error:
TypingError: Inputs to elemwise must be arrays.
raised from /Users/bpajusco/opt/anaconda3/envs/fast/lib/python3.10/site-packages/pytensor/link/numba/dispatch/elemwise.py:514
During: resolving callee type: Function(<intrinsic _vectorized>)
During: typing of call at /Users/bpajusco/opt/anaconda3/envs/fast/lib/python3.10/site-packages/pytensor/link/numba/dispatch/elemwise.py (648)
File "../../../../opt/anaconda3/envs/fast/lib/python3.10/site-packages/pytensor/link/numba/dispatch/elemwise.py", line 648:
def elemwise_wrapper(*inputs):
return _vectorized(
^
raised from /Users/bpajusco/opt/anaconda3/envs/fast/lib/python3.10/site-packages/numba/core/typeinfer.py:1086
During: resolving callee type: Function(<function numba_funcify_Elemwise.<locals>.elemwise at 0x18dfcdea0>)
During: typing of call at /var/folders/z8/q5v42wdj6j1fxt991j966lqm0000gn/T/tmp0kknc9dd (155)
File "../../../../../../var/folders/z8/q5v42wdj6j1fxt991j966lqm0000gn/T/tmp0kknc9dd", line 155:
def numba_funcified_fgraph(_joined_variables):
<source elided>
# Elemwise{Composite{((i0 - (i1 * i2)) - i3)}}[(0, 2)](TensorConstant{-234.32932596719152}, TensorConstant{0.5}, InplaceDimShuffle{}.0, Sum{acc_dtype=float64}.0)
tensor_variable_63 = elemwise_28(tensor_constant_27, tensor_constant_28, tensor_variable_60, tensor_variable_42)
^
During: resolving callee type: type(CPUDispatcher(<function numba_funcified_fgraph at 0x18df54820>))
During: typing of call at /Users/bpajusco/opt/anaconda3/envs/fast/lib/python3.10/site-packages/nutpie/compile_pymc.py (265)
During: resolving callee type: type(CPUDispatcher(<function numba_funcified_fgraph at 0x18df54820>))
During: typing of call at /Users/bpajusco/opt/anaconda3/envs/fast/lib/python3.10/site-packages/nutpie/compile_pymc.py (265)
File "../../../../opt/anaconda3/envs/fast/lib/python3.10/site-packages/nutpie/compile_pymc.py", line 265:
def extract_shared(x, user_data_):
return inner(x)
^
And also pymc model as a reference:
with pm.Model() as icm:
# Priors
λ = pm.Gamma("λ", alpha=2, beta=0.5)
kernel = pm.gp.cov.ExpQuad(input_dim=2, ls=λ, active_dims=[0])
σ = pm.HalfNormal("σ", sigma=3)
# Get ICM kernel
W = pm.Normal("W", mu=0, sigma=3, shape=(n_outputs,2), initval=np.random.randn(n_outputs,2))
κ = pm.Gamma("κ", alpha=1.5, beta=1, shape=n_outputs)
B = pm.Deterministic('B', at.dot(W, W.T) + at.diag(κ))
cov_icm = get_icm(input_dim=2, kernel=kernel, B=B, active_dims=[1])
gp = pm.gp.Marginal(cov_func=cov_icm)
y_ = gp.marginal_likelihood("f", X, Y, sigma=σ)
Metadata
Metadata
Assignees
Labels
No labels