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

What is the best way to match against optional attributes? #1902

Open
xuzhenqi opened this issue Oct 11, 2024 · 2 comments
Open

What is the best way to match against optional attributes? #1902

xuzhenqi opened this issue Oct 11, 2024 · 2 comments
Labels
question Further information is requested topic: rewriter

Comments

@xuzhenqi
Copy link
Contributor

Suppose we need to remove an optional input of a node, for example, we want to replace DFT(x, None, -2) with DFT(x), since the default axis is -2, so we can remove the axis input.

The DFT node has two optional attributes (onesided and inverse). What is the best way to write pattern to cover these cases:

  • DFT(x, None, -2) -> DFT(x)
  • DFT(x, None, -2, onesided=1) -> DFT(x, onesided=1)
  • DFT(x, None, -2, inverse=1) -> DFT(x, inverse=1)
  • DFT(x, None, -2, inverse=1, onesided=1) -> DFT(x, inverse=1, onesided=1)

It seems we need write four rules for the four cases, is there any better solutions? cc @justinchuby

@xuzhenqi
Copy link
Contributor Author

https://github.com/microsoft/onnxscript/blob/main/onnxscript/rewriter/pattern.py#L534

What if we allow an attr pattern to bind a None value?

@justinchuby
Copy link
Collaborator

@gramalingam

@justinchuby justinchuby added question Further information is requested topic: rewriter labels Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested topic: rewriter
Projects
None yet
Development

No branches or pull requests

2 participants