-
Notifications
You must be signed in to change notification settings - Fork 135
The rewrite log1pmexp_to_log1mexp
is not applied
#1476
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
Comments
A possible workaround seems to be to register register_specialize(log1pmexp_to_log1mexp, name="log1pmexp_to_log1mexp") but I have no idea if this causes troubles elsewhere. |
If neg becomes -1 by the time stabilize comes we can change the rewrite to look for that form instead. I think the rewrite makes complete sense as stabilize |
I think I see your point and I have some questions to understand the current implementation to better assist with fixing the bug (if I can). If I understand correctly, "canonicalize" should bring everything to a common form, and the specific implementation is that Apologies for the long comment, I hope it makes sense and it can help clarify the issue and facilitate the debugging process. My goal is to understand the current implementation and provide assistance, not to criticize the architecture. (*) However, this appears to be a bit "brittle" since this rewrite occurs because "local_mul_canonizer" happens to come before "local_reciprocal_canon". If one uses |
The long comment is great and yes, you're touching on one of the weaknesses of the current system: rewrite ordering. If you're curious we are also exploring alternatives that are robust to rewrite ordering (at the cost of rewrite explosion xD) -egraphs:
I'll reply to your comment details tomorrow. |
Thanks for the link. It's a really interesting approach. I think your current implementation partially address the issue of rewrite ordering by having separate stabilize and specialize steps, with the former happening first. So in a sense you make sure that more important rewrites happen first (or happen at all). Long story short, to fix this issue we may need to change "log1pmexp_to_log1mexp" to use the canonical form "mul(-1.0, exp(x))" (as you suggest) and also fix "logsigm_to_softplus" and "local_log1p" (and others if there are) to avoid producing a "neg" as output. |
I wasn't suggesting we do it, just keeping in the back of the mind of how to bring some of those ideas. I shared because knowing an alternative can help gain intuition about the approach we've been taking and what the pain points are.
Sounds like a plan
I think in specialize we convert -1 * x back to |
I found the function |
Describe the issue:
While investigating PR #1452 I run into the following issue.
The rewrite
log1pmexp_to_log1mexp
(part of the "stabilize" phase) is generally not applied because:log1pmexp_to_log1mexp
tries to match(log1p, (neg, (exp, "x")))
, howeverneg
is converted to-1.0*
so it fails to the match aboveThis happens both when compiling and when applying
rewrite_graph
.See the MRE below, which gives:
If one removes the
"canonicalize"
step fromrewrite_graph
, then the rewrite is correctly applied:Reproducable code example:
Error message:
PyTensor version information:
PyTensor 2.31.3
Context for the issue:
No response
The text was updated successfully, but these errors were encountered: