Skip to content

Commit

Permalink
feat: Support float32 settings in pytensor
Browse files Browse the repository at this point in the history
  • Loading branch information
aseyboldt committed Jul 26, 2024
1 parent dc261a0 commit 4ed93b1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/nutpie/compile_pymc.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def _make_functions(model, *, mode, compute_grad, join_expanded):
variables = [joined[slice_val] for slice_val in zip(joined_slices)]

replacements = {
model.rvs_to_values[var]: value.reshape(shape) if len(shape) != 1 else value
model.rvs_to_values[var]: value.reshape(shape).astype(var.dtype)
for var, shape, value in zip(
model.free_RVs,
joined_shapes,
Expand Down
15 changes: 15 additions & 0 deletions tests/test_pymc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ def test_pymc_model(backend, gradient_backend):
trace.posterior.a # noqa: B018


@parameterize_backends
def test_pymc_model_float32(backend, gradient_backend):
import pytensor

with pytensor.config.change_flags(floatX="float32"):
with pm.Model() as model:
pm.Normal("a")

compiled = nutpie.compile_pymc_model(
model, backend=backend, gradient_backend=gradient_backend
)
trace = nutpie.sample(compiled, chains=1)
trace.posterior.a # noqa: B018


@parameterize_backends
def test_blocking(backend, gradient_backend):
with pm.Model() as model:
Expand Down

0 comments on commit 4ed93b1

Please sign in to comment.