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

Auto generate StableHLO transform patterns #422

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

GleasonK
Copy link
Contributor

@GleasonK GleasonK commented Mar 2, 2025

The core of this PR is to make it trivial for patterns to have corresponding Transform dialect bindings.

Generates patterns and a populate method for each pattern, as well as a transform dialect op which wraps each pattern. Additionally there's some pattern-group ops as well.

@wsmoses wsmoses requested review from ftynse and wsmoses March 2, 2025 19:39
@wsmoses
Copy link
Member

wsmoses commented Mar 2, 2025

just to make sure the names are what are expected, can we add them to

cse_broadcast_in_dim<16>;
?


// Naming convention: `<RootOp><ChildOp>Const`:

// Pattern: (x / cst_1) * cst_2 -> x * (cst_2 / cst_1)
def MulDivConst : BinOpLiftConstantComputationFlip<StableHLO_MulOp, StableHLO_DivOp>;
def MulDivConst : BinOpLiftConstantComputationFlip<"mul_div_const", StableHLO_MulOp, StableHLO_DivOp>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How useful is it having a ton of individual patterns as transform ops?

I'm thinking a few possible outcomes here -- we offer individual patterns and grouped pattern ops for transform (i.e. {mul_div_const, mul_mul_const,...} and binop_const) -- or maybe this is something we resolve in the python layer with something like aliases?

I guess the real question is -- is there any issue with exploding the number of transform extension ops we're providing here?

I'd like to expand this to all StableHLO optim patterns so we can think about using some of the upstream ones (and upstreaming new ones) without impacting usability:
https://github.com/openxla/stablehlo/blob/main/stablehlo/transforms/optimization/StablehloAggressiveSimplificationPatterns.td

cc @ftynse @wsmoses

Copy link
Member

@wsmoses wsmoses Mar 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: fixed the link
So part of the original motivation for having the names was debugging both performance and issues.

For example, one can excise specific patterns to find bugs like #423

For performance it gives a search space since some patterns aren't always beneficial in practice (though from the hlo side it may seem strictly simplifying).

I don't think this means we need to have all things as individual patterns, but we can group things where convenient.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative would be to have one stablehlo_patterns op that is further parameterized by a list of patterns to include/exclude. But that means having (yet another) registration mechanism for that list whereas now we can use the op registration mechanism. Having logical groupings to reduce clutter makes sense to me as a short-term trade-off. Longer-term, we need to find a good way to manage this with e.g., adding ops on the fly or somehow referring to pattern name/location without creating a whole new op every time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, agree. I think a few groupings are probably best in the short term, might remove the individual granularity and just use the StablehloPatternGroup from this PR.

I like the file locality of this approach in the meantime to keep things trivial for users contributing patterns / also lets you refer to identifiers in TD files for slightly-better-than-stringly-typed safety. Also will make it really easy to give existing StableHLO patterns bindings in transform dialect

@GleasonK GleasonK marked this pull request as ready for review March 4, 2025 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants