Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Do not include rvs in symbolic normalizing constant#7787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@ricardoV94
Copy link
Member

@ricardoV94ricardoV94 commentedMay 17, 2025
edited
Loading

This is a more proper fix for the problem highlighted in#7778

The normalizing constant for MinibatchRVs included the graph of the shape of the RVs.

Even though the shape of the MinibatchRV can be derived without evaluating the draws, passing any graph with RVs topytensorf.compile will automatically integrate the updates which requires evaluating the RV anyway. This PR makes sure we don't include the RVs only to get the symbolic normalizing constant.


📚 Documentation preview 📚:https://pymc--7787.org.readthedocs.build/en/7787/

@ricardoV94ricardoV94 added maintenance VIVariational Inference labelsMay 17, 2025
Copy link

CopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that random variables (RVs) are not included in the symbolic normalizing constant graph by folding shapes to constants, adds shape inference for minibatch RVs, includes a test for the new behavior, and fixes a small typo.

  • Useconstant_fold to derive batch shapes instead of carrying RVs intosymbolic_normalizing_constant
  • Implementinfer_shape onMinibatchRandomVariable so shape propagation works correctly
  • Add a dedicated test (assert_no_rvs) to confirm no RVs appear in the symbolic normalizing constant
  • Correct a typo in theconstant_fold comment

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

FileDescription
tests/variational/test_opvi.pyAddedtest_symbolic_normalizing_constant_no_rvs withassert_no_rvs
pymc/variational/opvi.pySwapped direct.shape usage forconstant_fold([...].shape) in scaling
pymc/variational/minibatch_rv.pyAddedinfer_shape method to propagate shapes without evaluation
pymc/pytensorf.pyFixed typo in comment (constand_foldingconstant_folding)
Comments suppressed due to low confidence (3)

tests/variational/test_opvi.py:284

  • [nitpick] The test verifies no RVs are in the graph but doesn't assert that the symbolic normalizing constant still produces the expected scalar or tensor shape. Consider adding an assertion on the returned value or shape to guard against regressions.
def test_symbolic_normalizing_constant_no_rvs():

pymc/variational/opvi.py:1109

  • Callingconstant_fold inside the list comprehension for each RV will repeatedly clone and rewrite the graph, which may be costly. Consider computing all shapes once (e.g., collect inputs, callconstant_fold outside the loop) or caching results before the comprehension.
get_scaling(

pymc/variational/opvi.py:1279

  • This mirrored use ofconstant_fold in another list comprehension also risks redundant graph rewriting. Extract a helper or hoist the folding step to improve efficiency and reduce duplicated logic.
get_scaling(

@codecov
Copy link

codecovbot commentedMay 17, 2025
edited
Loading

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.84%. Comparing base (3a718f2) to head (0867cde).
⚠️ Report is 57 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@##             main    #7787   +/-   ##=======================================  Coverage   92.84%   92.84%           =======================================  Files         107      107             Lines       18378    18380    +2     =======================================+ Hits        17063    17065    +2  Misses       1315     1315
Files with missing linesCoverage Δ
pymc/pytensorf.py89.76% <ø> (ø)
pymc/variational/minibatch_rv.py100.00% <100.00%> (ø)
pymc/variational/opvi.py86.75% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ricardoV94ricardoV94force-pushed theno_rvs_symbolic_normalizing_constant branch from2551adf to0867cdeCompareMay 18, 2025 13:30
@ricardoV94ricardoV94 merged commit618634b intopymc-devs:mainMay 18, 2025
3 of 4 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@jessegrabowskijessegrabowskijessegrabowski approved these changes

Assignees

No one assigned

Labels

maintenanceVIVariational Inference

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@ricardoV94@jessegrabowski

[8]ページ先頭

©2009-2025 Movatter.jp