Skip to content

numpyro.contrib.module: only collect mutables in nnx_module() when th… - #2061

Merged
fehiepsi merged 2 commits into
pyro-ppl:masterfrom
esennesh:bugfix/nnx_module_mutables
Aug 9, 2025
Merged

numpyro.contrib.module: only collect mutables in nnx_module() when th…#2061
fehiepsi merged 2 commits into
pyro-ppl:masterfrom
esennesh:bugfix/nnx_module_mutables

Conversation

@esennesh

@esennesh esennesh commented Aug 6, 2025

Copy link
Copy Markdown
Contributor

…ey exist

Testing Done: avoided registration of empty mutables in nnx ConvNet

…ey exist

Testing Done: avoided registration of empty mutables in nnx ConvNet

Signed-off-by: Eli Sennesh <eli.sennesh@vanderbilt.edu>
@juanitorduz

Copy link
Copy Markdown
Collaborator

Thanks! I think it would be great if you could add a small test :)

Comment thread numpyro/contrib/module.py
mutable_holder = None
if eager_other_state_dict:
mutable_holder = numpyro_mutable(name + "$state")
if mutable_holder is None:

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.

I guess it is better to move this if inside the above if?

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.

My patch deletes the lower if since by construction, mutable_holder is None is always true here. We don't want to create an empty mutable-state no matter what, since there are inference algorithms and other things that depend upon the nonexistence of mutables (which is how I found this in the first place).

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.

That makes sense. Thanks for clarifying! Could you adjust the failing test to cover the change? I think without batchnorm, we no longer have mutable state in that test.

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.

All right! Changed the test and in the no-batchnorm, no-dropout case, we no longer expect to see any 'nn$state' in the keys found.

@esennesh

esennesh commented Aug 8, 2025 via email

Copy link
Copy Markdown
Contributor Author

…out active

Signed-off-by: Eli Sennesh <eli.sennesh@vanderbilt.edu>

@fehiepsi fehiepsi left a comment

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.

Thanks @esennesh!

@fehiepsi
fehiepsi merged commit ddbd0b8 into pyro-ppl:master Aug 9, 2025
10 checks passed
@esennesh
esennesh deleted the bugfix/nnx_module_mutables branch November 1, 2025 17:58
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