Skip to content
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

Blackjax sampler fix for breaking change / enable progress bar under parallel chain_method #7453

Merged
merged 7 commits into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions pymc/sampling/jax.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,10 @@ def _one_step(state, xs):
return state, (position, stats)

progress_bar = adaptation_kwargs.pop("progress_bar", False)
if progress_bar:
from blackjax.progress_bar import progress_bar_scan

one_step = jax.jit(progress_bar_scan(draws)(_one_step))
else:
one_step = jax.jit(_one_step)

keys = jax.random.split(seed, draws)
_, (samples, stats) = jax.lax.scan(one_step, last_state, (jnp.arange(draws), keys))
scan_fn = blackjax.progress_bar.gen_scan_fn(draws, progress_bar)
_, (samples, stats) = scan_fn(_one_step, last_state, (jnp.arange(draws), keys))

return samples, stats

Expand Down Expand Up @@ -365,14 +360,6 @@ def _sample_blackjax_nuts(
# Adapted from numpyro
if chain_method == "parallel":
map_fn = jax.pmap
if progressbar:
import warnings

warnings.warn(
"BlackJax currently only display progress bar correctly under "
"`chain_method == 'vectorized'`. Setting `progressbar=False`."
)
progressbar = False
elif chain_method == "vectorized":
map_fn = jax.vmap
else:
Expand Down
Loading