fit_dadvi fails with gradient_backend="jax"
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- numpy, python
- Domain
- machine-learning
Research direction
Start in pymc_extras/inference/dadvi/dadvi.py at fit_dadvi and the opt_var_params assignment before draws_from_laplace_approx. Reproduce the issue with gradient_backend="jax", then verify that posterior sampling completes without the numba TypingError and that the existing DADVI behavior remains intact.
Written by the indexing model from the issue text.
Description
Calling fit_dadvi(gradient_backend="jax") raises a numba.core.errors.TypingError during the posterior sampling step, even though the MAP optimization completes successfully.
Traceback (most recent call last):
File "...", in fit_dadvi
posterior, unconstrained_posterior = draws_from_laplace_approx(...)
File "...", in draws_from_laplace_approx
for out_draw in fn(mean, sigma):
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<function numba_funcify_RandomVariable.<locals>.random ...>) found for signature:
>>> random(readonly array(int64, 1d, C), NumPyRandomGeneratorType, readonly array(int64, 1d, C),
readonly buffer(float64, 1d, C), array(float64, 1d, C))
...
Rejected as the implementation raised a specific error:
TypingError: Vectorized inputs must be arrays.
The reason is that the result of type jaxlib.ArrayImpl is propagated and not handled correctly by numba.
This can be fixed by the following patch:
diff --git a/pymc_extras/inference/dadvi/dadvi.py b/pymc_extras/inference/dadvi/dadvi.py
index b519499..1d620c6 100644
--- a/pymc_extras/inference/dadvi/dadvi.py
+++ b/pymc_extras/inference/dadvi/dadvi.py
@@ -185,7 +185,7 @@ def fit_dadvi(
raveled_optimized = RaveledVars(result.x, dadvi_initial_point.point_map_info)
- opt_var_params = result.x
+ opt_var_params = np.array(result.x)
opt_means, opt_log_sds = np.split(opt_var_params, 2)
posterior, unconstrained_posterior = draws_from_laplace_approx(
Environment
Python 3.13.7 (main, Sep 2 2025, 14:21:46) [Clang 20.1.4 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> pymc.__version__
'6.0.1'
>>> pymc_extras.__version__
'0.12.2.dev7+g71c1706c8'
>>> jax.__version__
'0.10.1'
>>> numba.__version__
'0.65.1'
- Dominant language
- Jupyter Notebook
- Stars
- 143
- Forks
- 91
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 19
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pymc-devs/pymc-extras
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
pymc-devs/pymc-extras#751 ·
-
enhancements good first issue help wanted maintenance
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
pymc-devs/pymc-extras#472 · 7 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
pymc-devs/pymc-extras#764 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
pymc-devs/pymc-extras#758 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
pymc-devs/pymc-extras#755 ·
All issues in pymc-devs/pymc-extras
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
vllm-project/vllm#57974 · 4 comments ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
torchgeo/torchgeo-bench#400 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
open-compass/VLMEvalKit#1698 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100