Automatically minibatch a model - #700
Draft
ricardoV94 wants to merge 3 commits into
Draft
Conversation
Special-case Blockwise(Dot) so a known batch dimension on the non-contracted (m, p) axes maps 1:1 to the output, while a known contracted dimension raises. Also fix the CAReduce check to use `is not None` so reducing a tracked dim labeled 0 (the leading axis) is correctly rejected.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #700 +/- ##
===========================================
+ Coverage 51.60% 90.94% +39.33%
===========================================
Files 73 91 +18
Lines 8003 8700 +697
===========================================
+ Hits 4130 7912 +3782
+ Misses 3873 788 -3085
🚀 New features to boost your workflow:
|
ricardoV94
force-pushed
the
minibatch_model
branch
2 times, most recently
from
June 26, 2026 17:28
3a72ec1 to
e3dcf44
Compare
Add `subgraph_batch_dim_ancestors`, the input-direction dual of the forward connection pass: given one batch axis of an output variable, propagate it backward to the ancestors that feed it, returning which axis of each ancestor carries it. A reduced or contracted axis is not propagated (the ancestor below it is not reached); an op whose inverse cannot be traced propagates the axis conservatively to all its inputs so nothing carrying it is silently dropped. Rename the forward pass `_subgraph_batch_dim_connection` to `_subgraph_batch_dim_clients` to name its direction explicitly alongside the new ancestor trace.
Add `minibatch`, which rewrites a model to draw random minibatches of its observed data and rescales the affected observed logp by total_size, the transform-based equivalent of building the model with `pm.Minibatch`. The minibatched (leading) axis of each observed is traced backward with `subgraph_batch_dim_ancestors` to find the variables that share it: the data to slice, and any free RV or Potential that would need rescaling. Forward tracing from the data and resized observeds finds Deterministics to relabel and terms that are clients of the minibatch. With `validate=True` the transform rejects constructs whose logp cannot be correctly rescaled (free RVs / Potentials on the minibatched axis, partially specified data, non-batchable observeds).
ricardoV94
force-pushed
the
minibatch_model
branch
from
June 27, 2026 13:11
e3dcf44 to
c22961f
Compare
ricardoV94
commented
Jun 27, 2026
| raise TypeError("batch_size must be an integer") | ||
|
|
||
| if observed is None: | ||
| observed = [rv for rv in model.observed_RVs if rv.ndim > 0] |
Member
Author
There was a problem hiding this comment.
grab the ones with batch ndim not just rv.ndim > 0
Merged
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.
No description provided.