Raise on unrecognized sample() kwargs for external NUTS samplers - #8406
Open
sangaraju1988 wants to merge 1 commit into
Open
Raise on unrecognized sample() kwargs for external NUTS samplers#8406sangaraju1988 wants to merge 1 commit into
sangaraju1988 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
#8352 asked for a way to turn off init jitter when using an external NUTS sampler. Half of that got fixed already, as a side effect of #8369 —
nuts={"jitter": False}works fine onmainright now.The part still broken is the calling style from before that refactor.
pm.sample(nuts_sampler="numpyro", jitter=False)— jitter passed at the top level instead of nested innuts={}— does nothing. No error, no warning. It just samples with jitter on anyway.Reason:
_sample_external_nuts()takes**kwargsas a catch-all, and nothing in the function ever reads it. Whatever lands there just evaporates. So this fixes the catch-all itself, not just the jitter case — it now raises aTypeErrornaming whatever unexpected keys showed up, telling you to usenuts={...}instead.Added two tests.
test_external_nuts_sampler_rejects_stray_top_level_kwargsis the one that actually covers this change — confirmed it fails withDID NOT RAISEon unpatchedmainand passes with the fix.test_jax_sampler_jitter_kwarg_routingcovers thenuts={"jitter": False}path, which already worked before this PR (that's #8369's doing) — including it since it wasn't tested anywhere before now.Ran
test_jax.py,test_mcmc_external.py, andtest_mcmc.pylocally. Full pass on the first two.test_mcmc_external.pyhas some pre-existing flakiness unrelated to this — a couple of blackjax tests occasionally hit apmap/jax version issue, andtest_step_argshas a statistical assertion that isn't always stable. Both reproduce identically on unpatchedmain, so not from this change.Related Issue
Checklist
Type of change