Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with multiple minibatch variables #7408

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Jul 9, 2024

Description

Reported in https://discourse.pymc.io/t/verifying-that-minibatch-is-actually-randomly-sampling/14308

The bug occurred due to separate calls to model.logp (from model.datalogp and model.varlogp) that create distinct clones of the RandomIntegersRV underlying minibatch slicing. compile_pymc would not set any updates in this case

Related Issue

  • Closes #
  • Related to #

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

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

@ricardoV94 ricardoV94 added bug VI Variational Inference labels Jul 9, 2024
@ricardoV94 ricardoV94 requested a review from ferrine July 9, 2024 19:12
Fixes bug in VI with multiple Minibatch variables, which occurred due to separate calls to model.logp (from model.datalogp and model.varlogp) that create distinct clones of the RandomIntegersRV underlying minibatch slicing. `compile_pymc` would not set any updates in this case
Copy link

codecov bot commented Jul 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.18%. Comparing base (f0631b4) to head (10f3aef).
Report is 10 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7408      +/-   ##
==========================================
- Coverage   92.19%   92.18%   -0.02%     
==========================================
  Files         103      103              
  Lines       17212    17261      +49     
==========================================
+ Hits        15869    15912      +43     
- Misses       1343     1349       +6     
Files Coverage Δ
pymc/pytensorf.py 90.51% <100.00%> (+0.06%) ⬆️

... and 2 files with indirect coverage changes

total_size=len(y),
)
mean_field = pm.fit(10_000, obj_optimizer=pm.adam(learning_rate=0.01), progressbar=False)
np.testing.assert_allclose(mean_field.mean.get_value(), true_weights, rtol=1e-1)
Copy link
Member

Choose a reason for hiding this comment

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

Does this test need to run the whole model and check parameter recovery? It should be enough to compile the function and check that minibatch_feature and minibatch_y change after each loss function execution right?

Copy link
Member Author

@ricardoV94 ricardoV94 Jul 10, 2024

Choose a reason for hiding this comment

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

This should run pretty fast, with minibatch of 1. I think it's a useful integration test, we didn't have any linear regression minibatch test in the codebase.

Besides VI has a very complex logic leading to building the function that I rather treat as a black box

@ricardoV94 ricardoV94 merged commit a4ea9fc into pymc-devs:main Jul 10, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug VI Variational Inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants