Skip to content

fix(numba): non-contiguous shared variable #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025

Conversation

aseyboldt
Copy link
Member

See https://discourse.pymc.io/t/nutpie-panel-data-events-moving/17046/5 for more details

Shared variables (ie pm.Data) that were non-contiguous could lead to incorrect results in the pymc numba
backend.
We now ensure that they are always c-contiguous by copying if they are not.

@aseyboldt aseyboldt force-pushed the fix-numba-fortran-order branch from 4a731c0 to 27d69da Compare May 28, 2025 12:42
Shared variables (ie pm.Data) that were non-contiguous
could lead to incorrect results in the pymc numba
backend.
We now ensure that they are always c-contiguous by
copying if they are not.
@aseyboldt aseyboldt force-pushed the fix-numba-fortran-order branch from 27d69da to 18e5a07 Compare May 28, 2025 12:57
@aseyboldt aseyboldt merged commit bb5a866 into pymc-devs:main May 28, 2025
8 checks passed
@@ -256,7 +256,7 @@ def _compile_pymc_model_numba(
for val in [*logp_fn_pt.get_shared(), *expand_fn_pt.get_shared()]:
if val.name in shared_data and val not in seen:
raise ValueError(f"Shared variables must have unique names: {val.name}")
shared_data[val.name] = val.get_value()
shared_data[val.name] = np.array(val.get_value(), order="C", copy=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're copying anyway you can do get_value(borrow=True) to avoid doing 2 copies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants