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

Don't customize rewrite names #247

Closed
ricardoV94 opened this issue Mar 13, 2023 · 2 comments
Closed

Don't customize rewrite names #247

ricardoV94 opened this issue Mar 13, 2023 · 2 comments
Labels
graph rewriting help wanted Extra attention is needed

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Mar 13, 2023

Rewrites can be optionally included or excluded based on their registered names. However, some of the registered names don't match the name of the rewrite function, which is shown with optimizer_verbose=True

For instance:

import pytensor
import pytensor.tensor as pt

seq = pt.vector("seq")
xs, _ = pytensor.scan(
  lambda s: pt.exp(s),
  sequences = [seq],
)

pytensor.config.optimizer_verbose=True
pytensor.function([seq], xs)
...
rewriting: rewrite push_out_seq_scan replaces for{cpu,scan_fn}.0 of for{cpu,scan_fn}(Subtensor{int64}.0, Subtensor{:int64:}.0, Subtensor{int64}.0) with Elemwise{exp,no_inplace}.0 of Elemwise{exp,no_inplace}(Subtensor{:int64:}.0)
...

You would think you can disable it, by excluding push_out_seq_scan, but that does not work

from pytensor.compile.mode import get_mode

pytensor.function([seq], xs, mode=get_mode(None).excluding("push_out_seq_scan"))  
...
rewriting: rewrite push_out_seq_scan replaces for{cpu,scan_fn}.0 of for{cpu,scan_fn}(Subtensor{int64}.0, Subtensor{:int64:}.0, Subtensor{int64}.0) with Elemwise{exp,no_inplace}.0 of Elemwise{exp,no_inplace}(Subtensor{:int64:}.0)
...

Still there. Because it's actually registered with the name scan_pushout_seqs_ops:

"scan_pushout_seqs_ops",

pytensor.function([seq], xs, mode=get_mode(None).excluding("scan_pushout_seqs_ops"))  

Now it's excluded!

We should register the rewrites with the same name of the function that is shown in the debug (easy) or find a way to show the registration name instead (possibly harder?).

@ricardoV94 ricardoV94 changed the title Don't create new rewrite names and tags Don't customize rewrite names Mar 13, 2023
@ricardoV94 ricardoV94 added help wanted Extra attention is needed graph rewriting labels Mar 13, 2023
@michaelraczycki
Copy link

I'd like to help with that

@ricardoV94
Copy link
Member Author

That'd be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
graph rewriting help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants