Repository navigation
Preserve single-element trees in diagonal normal helpers - #157
Merged
SamDuffield merged 2 commits intoNov 14, 2026
Merged
SamDuffield merged 2 commits into
SamDuffield merged 2 commits into
Conversation
Fixes normal-computing-oss#156. Signed-off-by: Keshav Tibrewal <keshav.tibrewal@iitgn.ac.in>
SamDuffield
approved these changes
Nov 13, 2026
SamDuffield
requested changes
Nov 13, 2026
Signed-off-by: Keshav Tibrewal <keshav.tibrewal@iitgn.ac.in>
keshtib07-ghost
commented
Nov 14, 2026
keshtib07-ghost
left a comment
Contributor
Author
There was a problem hiding this comment.
Thanks for the review! I've removed both redundant docstring comments in 94079f9. The latest CI run is green, including the tests and pre-commit checks.
Could you take another look when you get a chance?
SamDuffield
approved these changes
Nov 14, 2026
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.
Fixes #156.
The diagonal normal helpers use total tree size to decide whether a mean or scale is scalar. A dictionary holding one scalar tensor is then passed to
torch.tensor, which raisesRuntimeError: Could not infer dtype of dict. A singleton tuple can be converted, but that drops the parameter gradients. This also prevents diagonal VI from training a one-parameter dictionary model.Use the existing
is_scalarhelper for scalar broadcasting so single-element parameter trees keep their structure and gradients. The docstrings clarify the distinction.Validation on Python 3.12.14 and PyTorch 2.15.0+cpu:
pytest tests/test_utils.py tests/test_tree_utils.py -q: 57 passed with the fix.torch.distributions.Normal.n_samples=1and3, with each STL setting.git diff --checkpassed.The full sampling suite is not part of this completed validation.