-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Implement measurable transforms for division, subtraction and negation #144
Conversation
4fc450b
to
dcfaa14
Compare
Codecov ReportBase: 94.82% // Head: 94.55% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #144 +/- ##
==========================================
- Coverage 94.82% 94.55% -0.28%
==========================================
Files 12 12
Lines 1933 1835 -98
Branches 289 276 -13
==========================================
- Hits 1833 1735 -98
- Misses 55 56 +1
+ Partials 45 44 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a little more context to the description?
Done |
dcfaa14
to
aa66cab
Compare
aa66cab
to
7ffdcd1
Compare
Added other rewrites that cover negation and subtraction of MeasurableVariables |
e09f84b
to
00f52b6
Compare
00f52b6
to
c298001
Compare
6ccfb72
to
df99f5b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very unsure about these fundamental (implicit) canonicalization changes made to rational expressions. Those could really create issues down the road, and they're something that should probably be used in Aesara as well, or not at all. In other words, if they're justified here, why aren't they justified for general use in Aesara?
Anyway, we might be able to try going forward with this—after renaming that class—but I still think it needs more consideration, especially since adding explicit canonicalizations isn't usually necessary (i.e. functionality-specific local rewrites can make the relevant rational form considerations instead).
aeppl/tensor.py
Outdated
|
||
@local_optimizer([Elemwise]) | ||
def measurable_div_to_reciprocal_product(fgraph, node): | ||
r"""Convert divisions involving `MeasurableVariable`\s to products with their reciprocals.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to start using the notation/approach mentioned here to clearly specify our rewrites at a high-level.
Specifically, the numerator not being equal to one could be compactly conveyed this way, along with the basic form of the rewrite itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... forgot about this. Will do
I think it makes sense to canonicalize in Aesara, except if weird float precision issues may crop up in general. We already have an issue opened for that, so if it goes through we can revert these ones here. But even if we conclude they don't make sense in Aesara, here there are further context reasons to justify them. We know that in Aeppl most cases of unvalued RVs are meant to be replaced. If for some reason these canonicalizations are not desired, users can remove the rewrite from the standard database. We also already have other canonicalizations that don't translate to measurable variables directly like the broadcast one. The question is whether the trouble of affecting RV graphs that won't be replaced by value variables is larger than the cost of doing more refined intermediate rewrites that will be reverted automatically if unused... |
Alternatively, if we convert all unvalued RVs to MeasurableVariables before applying these canonicalizations, they will be undone when they are not needed by the same machinery in here: Line 321 in 394dc72
|
3d98da6
to
50a829e
Compare
@brandonwillard I have not addressed the concerns about intermediate rewrites that simply canonicalize intermediate variables, besides restricting those rewrites to "unvalued measurable variables". IMO until we figure out what we want to do with unmeasured RandomVariables in our graphs (as discussed in #174 and #85) we could keep assuming they are there to be replaced anyway, in which case these rewrites don't do any damage and make it simpler to cover a wider range of measurable Elemwise operations. Anyway, I re-requested your review to check that this is the only concern left and discuss it. |
50a829e
to
d0d8842
Compare
We can always make these rewrites elective (i.e. a user must explicitly load/use them) for the time being; otherwise, adding rewrites that change the expectations of other rewrites (i.e. affect and/or determine canonical/normal forms) leads to serious downstream problems. For instance, if Such "intermediate" rewrites can facilitate other rewrites that relate more directly to the desired functionality (i.e. the transforms in this PR), so the approach is very understandable. One important question that arises is these situations: "Can the intermediate rewrites be applied in isolation (i.e. not "committed" to the graph being rewritten) instead?". In quite a few cases for which this isn't possible, I've found that the limiting factors involved an inability to perform reasonable graph comparisons (e.g. one would need to inefficiently walk both graphs). Core Aesara changes like aesara-devs/aesara#1110 and aesara-devs/aesara#1165 would address those issues. In other cases, one needs intermediate rewrites to realize larger graph forms when, for example, there are no known sequences of "local" rewrites that will produce the desired forms consistently. Something like |
Thanks for the reply. I am not totally convinced why this matters here. Assuming we introduce other rewrites in the future that would try to match I understand why in Aesara we might not want to do that because of numerical stability. But here we are not dealing with direct computations yet, and we don't even know which, if any, IR form will lead to a more stable logprob (and the user much less), specially because this may be used as a building block for arbitrarily complex valued-variables. Note that given the checks in place, the outputs of these intermediate rewrites will always be picked up by The only side-effect happens with unvalued-orphan |
d0d8842
to
7e6cf6e
Compare
Adds rewrite that converts divisions with measurable variables to product with reciprocals, making the reciprocal measurable transform more widely applicable.
7e6cf6e
to
350a42e
Compare
In general, it looks like the transform approach in #26 and this PR is rather buggy and acceptable changes to the rewrite orders cause numerous problems. After fixing something like #170 and running this, it becomes very apparent. I'm going to close this and open a replacement PR that fixes the aforementioned, and the |
Follow up to #26
This implements measurable rewrites for the following type of graphs:
As well as:
It works by canonicalizing such operations to the form already understood by
find_measurable_transforms
(only a new condition forReciprocal
s was added)These canonicalizations are only applied when MeasurableVariables are involved to minimize disruption of the underlying graph