pymc-devs / pymc-devs/pymc

BUG: `pm.sample(nuts_sampler="blackjax")` fails during warmup with every blackjax >= 1.6

Open
#8,367 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug jax samplers
Dominant language
Python
Stars
9.8k
Forks
2.3k
Avg merge
21h 39m
Merged PRs (30d)
5

Description

Describe the issue:

pm.sample(nuts_sampler="blackjax") fails during warmup with every blackjax >= 1.6, in all configurations, on all pymc versions (verified on 5.27.1 and 6.1.0).

Root cause: blackjax 1.6 removed the progress_bar parameter from blackjax.window_adaptation (progress bars moved to a context manager, with blackjax.progress_bar(): warmup.run(...)), and window_adaptation now forwards unknown **extra_parameters into the NUTS kernel. pymc unconditionally injects progress_bar into the sampler kwargs (nuts_kwargs["progress_bar"] = progressbar, pymc/sampling/jax.py:359 in 6.1.0) and _blackjax_inference_loop only pops it after blackjax.window_adaptation(**adaptation_kwargs) has already been called (pymc/sampling/jax.py:277 vs the window_adaptation call above it). The stale kwarg therefore reaches the blackjax NUTS kernel and raises during the first adaptation step.

A fix would be to pop progress_bar from adaptation_kwargs before calling window_adaptation and, for blackjax >= 1.6, use the new context-manager API (or drop the flag).

Reproduceable code example:
# pip install "pymc==6.1.0" "blackjax==1.6"  (also fails with pymc 5.27.1 + blackjax 1.6)
import numpy as np
import pymc as pm

with pm.Model():
    x = pm.Normal("x", 0.0, 1.0)
    pm.Normal("obs", x, 1.0, observed=np.array([0.3, -0.1, 0.5]))
    idata = pm.sample(
        draws=50, tune=50, chains=1,
        nuts_sampler="blackjax",
        progressbar=False,
    )
Error message:
TypeError: build_kernel.<locals>.kernel() got an unexpected keyword argument 'progress_bar'


(raised from `blackjax/adaptation/window_adaptation.py` during `adapt.run`, wrapped by JAX tracing frames)
PyMC version information:

pymc 5.27.1 and 6.1.0, blackjax 1.6, jax 0.10.x, Python 3.12, macOS (arm64) and Linux. Works with blackjax <= 1.5 (whose window_adaptation still accepted progress_bar).

Context for the issue:

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pymc/sampling/jax.py, especially _blackjax_inference_loop and the nuts_kwargs construction around the lines mentioned in the report. Reproduce the example with blackjax 1.6, then verify that blackjax-based sampling completes during warmup with progressbar disabled and that compatibility with blackjax 1.5 is preserved.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.