with_data fails with a list on the jax backend
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
Research direction
Read CompiledPyMCModel.with_data and compare its conversion of new values with the JAX backend's PyFuncModel.with_data, which currently stores values as given. Reproduce the failure with the supplied model and list input, then check that sampling works after the value is handled consistently with the existing NumPy array input. An open linked pull request (#373) already addresses this issue.
Written by the indexing model from the issue text.
Description
On a model compiled with backend="jax" (and freeze_model=False), passing a list to with_data makes sampling fail. The numba backend accepts the same call, and the PyMC usage guide shows compiled.with_data(x=[4, 5, 6]).
CompiledPyMCModel.with_data (numba) converts each new value with np.array(new_val, dtype=old_val.dtype). The jax backend returns a PyFuncModel, whose with_data stores the value as given, so the list reaches the jax logp function unchanged.
Reproduction
import numpy as np
import pymc as pm
import nutpie
with pm.Model() as model:
x = pm.Data("x", np.array([1.0, 2.0, 3.0]))
beta = pm.Normal("beta")
pm.Normal("y", mu=beta * x, sigma=0.1, observed=np.array([4.0, 5.0, 6.0]))
compiled = nutpie.compile_pymc_model(model, backend="jax", freeze_model=False)
nutpie.sample(compiled.with_data(x=[4, 5, 6]), chains=1)
RuntimeError: All initialization points failed
Caused by:
Logp function returned error: ... TypeError("multiply requires ndarray or scalar arguments, got <class 'list'> at position 1.")
The same error occurs with gradient_backend="jax". Passing np.array([4, 5, 6]) works.
- Dominant language
- Python
- Stars
- 214
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
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/nutpie
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
-
normalizing-flows
Difficulty 3/5 1-2 days Newbie friendliness 58/100
All issues in pymc-devs/nutpie
Similar issues
-
triage
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
kornia/kornia-rs#1416 · 1 comment ·
Maintainers usually reply within 2 days
-
ui
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
PolicyEngine/ai-inequality#64 ·
Maintainers usually reply within 1 day
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over timePossibly taken @PabloRoque claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
pymc-devs/pymc-extras#839 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day