Skip to content

Miscellaneous bugfixes#2215

Open
esennesh wants to merge 12 commits into
pyro-ppl:masterfrom
esennesh:develop
Open

Miscellaneous bugfixes#2215
esennesh wants to merge 12 commits into
pyro-ppl:masterfrom
esennesh:develop

Conversation

@esennesh

@esennesh esennesh commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
  • Nicer handling of empty mutables and nnx-modules in SVI (34fa2a1)
  • Allow for init_value to be something other than init-to-mean (75bebfc)
  • Fix import error (1f122aa)
  • Handle the TODO on using sampling with intermediates in expanded and Independent distributions (5f7066a)
  • Include some type annotations and formatting in the init_value fix (22aff3f)

@juanitorduz

Copy link
Copy Markdown
Collaborator

Hi! Please sync with master as we fixed the CI failure #2218 :)

@esennesh

esennesh commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Hi! Please sync with master as we fixed the CI failure #2218 :)

All checks now pass 👍 . Let me know how you'd like to conduct the remainder of the review process!

@juanitorduz juanitorduz requested a review from fehiepsi July 10, 2026 08:53
@juanitorduz

Copy link
Copy Markdown
Collaborator

Thanks @esennesh . Most of it makes a lot of sense.

Still, I wanna ask @fehiepsi for a review on the specific change

Handle the TODO on using sampling with intermediates in expanded and Independent distributions

As I could be missing something.

Maybe @esennesh, it's worth adding tests that show how this is supposed to work for each of the two if branches?

@esennesh

Copy link
Copy Markdown
Contributor Author

Maybe @esennesh, it's worth adding tests that show how this is supposed to work for each of the two if branches?

Hmmm... I thought I had something on one of my other branches for submission that was gonna exercise this, but since I'm having a hard time finding that, I very much should add a test for exercising both branches.

esennesh and others added 2 commits July 13, 2026 13:09
…dependent

TransformedDistribution.sample_with_intermediates caches the pre-transform
base sample so that log_prob(value, intermediates) can reuse it instead of
recomputing transform.inv(value). That optimization was silently lost when the
transformed distribution was wrapped:

- Independent inherited the base no-op sample_with_intermediates (returning an
  empty []), so the cached value never reached the trace, and its log_prob did
  not accept intermediates.
- ExpandedDistribution.log_prob ignored the intermediates it was passed (it
  carried a "TODO: utilize intermediates").

Both remain backward compatible (intermediates defaults to None).

For a TransformedDistribution wrapped by to_event()/expand(), this lets log_prob
reuse the sampled base value rather than inverting the transform, a potential
speedup in certain cases.  Include a test to make sure this actually works.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Eli Sennesh <elisennesh@astera.org>
Signed-off-by: Eli Sennesh <elisennesh@astera.org>
@esennesh

Copy link
Copy Markdown
Contributor Author

Thanks @esennesh . Most of it makes a lot of sense.

Still, I wanna ask @fehiepsi for a review on the specific change

Handle the TODO on using sampling with intermediates in expanded and Independent distributions

As I could be missing something.

Maybe @esennesh, it's worth adding tests that show how this is supposed to work for each of the two if branches?

Got a test in there now for the if-yes branch, while the if-no branch is the default codepath exercised by most, though not quite all (hence the patch), existing code.

@esennesh

Copy link
Copy Markdown
Contributor Author

Is there a way to convert the PR to pull from the master branch on my fork, so I can merge things into develop while the PR is under review?

Comment thread numpyro/primitives.py

def fn(init_fn: Callable, *args, **kwargs) -> ArrayLike:
return init_fn(prng_key())
def fn(*args, init_value: Callable = init_value, **kwargs) -> ArrayLike:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like we dont need init_value here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It seems like we don't, but IME we actually do. Python behaves very nastily with closures and Jax behaves even worse. Generally IME the best way to actually close over something is like this: make the closed-over value the default for a pseudo-"argument", to make sure it becomes part of the function, gets passed by value, and survives closure conversion in the correct form.

If there was a way to demonstrate we don't need it, we could get rid of it, but again IME nasty bugs tend to show up after I mistake Python for Haskell in a case like this.

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.

3 participants