I am attempting to solve a similar problem…
I have a vehicle model as of now with 5 states and 5 parameters (including the data noise that I sample). The vehicle model can be found here. The vehicle model implemented using JAX and similar to OP, I want to implement a custom likelihood function in pymc V4. Given here is my first attempt at this. However, my chains fail and this is the error I get -
WARNING:absl:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)% [0/6000 00:00<00:00 Sampling 4 chains, 0 divergences]
WARNING:absl:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
WARNING:absl:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
WARNING:absl:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
pymc.parallel_sampling.RemoteTraceback:
"""
Traceback (most recent call last):
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/compile/function/types.py", line 964, in __call__
self.fn()
ValueError: Expected 1 dimensions input
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/pymc/parallel_sampling.py", line 125, in run
self._start_loop()
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/pymc/parallel_sampling.py", line 178, in _start_loop
point, stats = self._compute_point()
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/pymc/parallel_sampling.py", line 203, in _compute_point
point, stats = self._step_method.step(self._point)
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/pymc/step_methods/arraystep.py", line 286, in step
return super().step(point)
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/pymc/step_methods/arraystep.py", line 208, in step
step_res = self.astep(q)
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/pymc/step_methods/hmc/base_hmc.py", line 156, in astep
start = self.integrator.compute_state(q0, p0)
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/pymc/step_methods/hmc/integration.py", line 47, in compute_state
logp, dlogp = self._logp_dlogp_func(q)
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/pymc/model.py", line 408, in __call__
cost, *grads = self._aesara_function(*grad_vars)
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/compile/function/types.py", line 977, in __call__
raise_with_op(
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/link/utils.py", line 538, in raise_with_op
raise exc_value.with_traceback(exc_trace)
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/compile/function/types.py", line 964, in __call__
self.fn()
ValueError: Expected 1 dimensions input
Apply node that caused the error: Subtensor{int64}(LoglikeGrad.0, ScalarConstant{4})
Toposort index: 22
Inputs types: [TensorType(float64, (None,)), Scalar(int64)]
Inputs shapes: [(5,), ()]
Inputs strides: ['No strides', ()]
Inputs values: [DeviceArray([ 1.71861555e-02, 1.10738053e+00, -2.40910899e+00,
1.57400068e+06, 7.75898922e+03], dtype=float64), 4]
Outputs clients: [[Elemwise{Composite{(Switch(i0, (i1 * i2 * i2), i3) + i4 + (i5 * i2))}}(Elemwise{ge,no_inplace}.0, TensorConstant{-1111.1111111111113}, sigmaLat_acc_log___log, TensorConstant{0}, (d__logp/dsigmaVy_log___logprob){1.0}, Subtensor{int64}.0)]]
Backtrace when the node is created (use Aesara flag traceback__limit=N to make it longer):
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1387, in access_grad_cache
term = access_term_cache(node)[idx]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1059, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1059, in <listcomp>
output_grads = [access_grad_cache(var) for var in node.outputs]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1387, in access_grad_cache
term = access_term_cache(node)[idx]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1059, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1059, in <listcomp>
output_grads = [access_grad_cache(var) for var in node.outputs]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1387, in access_grad_cache
term = access_term_cache(node)[idx]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1214, in access_term_cache
input_grads = node.op.L_op(inputs, node.outputs, new_output_grads)
HINT: Use the Aesara flag `exception_verbosity=high` for a debug print-out and storage map footprint of this Apply node.
"""
The above exception was the direct cause of the following exception:
ValueError: Expected 1 dimensions input
Apply node that caused the error: Subtensor{int64}(LoglikeGrad.0, ScalarConstant{4})
Toposort index: 22
Inputs types: [TensorType(float64, (None,)), Scalar(int64)]
Inputs shapes: [(5,), ()]
Inputs strides: ['No strides', ()]
Inputs values: [DeviceArray([ 1.71861555e-02, 1.10738053e+00, -2.40910899e+00,
1.57400068e+06, 7.75898922e+03], dtype=float64), 4]
Outputs clients: [[Elemwise{Composite{(Switch(i0, (i1 * i2 * i2), i3) + i4 + (i5 * i2))}}(Elemwise{ge,no_inplace}.0, TensorConstant{-1111.1111111111113}, sigmaLat_acc_log___log, TensorConstant{0}, (d__logp/dsigmaVy_log___logprob){1.0}, Subtensor{int64}.0)]]
Backtrace when the node is created (use Aesara flag traceback__limit=N to make it longer):
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1387, in access_grad_cache
term = access_term_cache(node)[idx]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1059, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1059, in <listcomp>
output_grads = [access_grad_cache(var) for var in node.outputs]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1387, in access_grad_cache
term = access_term_cache(node)[idx]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1059, in access_term_cache
output_grads = [access_grad_cache(var) for var in node.outputs]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1059, in <listcomp>
output_grads = [access_grad_cache(var) for var in node.outputs]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1387, in access_grad_cache
term = access_term_cache(node)[idx]
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/aesara/gradient.py", line 1214, in access_term_cache
input_grads = node.op.L_op(inputs, node.outputs, new_output_grads)
HINT: Use the Aesara flag `exception_verbosity=high` for a debug print-out and storage map footprint of this Apply node.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/hussainmustafa/Desktop/research/tutorials/vd_bi_aes.py", line 168, in <module>
main()
File "/Users/hussainmustafa/Desktop/research/tutorials/vd_bi_aes.py", line 156, in main
idata = pm.sample(ndraws ,tune=nburn,discard_tuned_samples=True,return_inferencedata=True,target_accept = 0.9, cores=4)
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/pymc/sampling.py", line 543, in sample
mtrace = _mp_sample(**sample_args, **parallel_args)
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/pymc/sampling.py", line 1470, in _mp_sample
for draw in sampler:
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/pymc/parallel_sampling.py", line 460, in __iter__
draw = ProcessAdapter.recv_draw(self._active)
File "/Users/hussainmustafa/opt/anaconda3/envs/pymc-dev-py39/lib/python3.9/site-packages/pymc/parallel_sampling.py", line 349, in recv_draw
raise error from old_error
RuntimeError: Chain 2 failed.
I don’t understand aesera very well to understand what is going on here and am lost as to how to fix this. I think I have to create a JAX op to wrap the JAX function as shown here but I am not sure…