Skip to content

Fix PyroModule registration of frozen parameters - #3469

Open
tandede wants to merge 1 commit into
pyro-ppl:devfrom
tandede:fix/pyromodule-frozen-parameters
Open

Fix PyroModule registration of frozen parameters#3469
tandede wants to merge 1 commit into
pyro-ppl:devfrom
tandede:fix/pyromodule-frozen-parameters

Conversation

@tandede

@tandede tandede commented Aug 19, 2026

Copy link
Copy Markdown

Proposed changes

PyroModule currently emits a pyro.param statement whenever a regular torch.nn.Parameter is read during a module call. ParamStoreDict makes registered tensors trainable, so this silently changes parameters created with requires_grad=False to requires_grad=True and adds them to the parameter store.

This change:

  • skips parameter statements for frozen regular parameters, matching the registration contract of pyro.module();
  • applies the same rule when a regular parameter is assigned inside an active PyroModule context;
  • preserves the existing global and module-local behavior for trainable parameters.

The regression test covers both parameter-store modes, parameters created during initialization, and parameters assigned dynamically during forward().

Fixes #3438.

Tests

  • pytest -q tests/nn/test_module.py (69 passed, 1 xfailed)
  • pytest -q tests/params/test_module.py (7 passed)
  • pytest -q tests/infer/test_autoguide.py -k 'test_exact and not AutoGaussianFunsor' (29 passed)
  • pytest -q tests/distributions/test_spanning_tree.py (66 passed, 60 skipped, 6 xfailed)
  • ruff check .
  • black --check pyro/nn/module.py tests/nn/test_module.py
  • python scripts/update_headers.py --check
  • mypy --warn-unused-ignores pyro/nn/module.py tests/nn/test_module.py

@tandede

tandede commented Aug 30, 2026

Copy link
Copy Markdown
Author

Hi maintainers, I wanted to follow up on this PR in case it was overlooked. It fixes registration of frozen parameters in PyroModule and is ready for review. Please let me know if any changes or additional validation would be useful. Thank you!

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.

Pyro sets all Parameters to requires_grad=True, when using PyroModule

1 participant