Hello everyone! I’ve been noticing a bit of code duplication arise in the ecosystem lately, and figured it’s probably time to propose centralizing some of this code in the StableHLO repo. This is related to the recent openxla/discussions#106, I propose we keep discussion in this email thread since this proposal encompasses that discussion.
Out of scope: I am not proposing to make StableHLO the default transformation dialect, since in the current state of things this would introduce a large pain point of “some things happen in MHLO, others in StableHLO, we need to round trip to get what we want''. I believe the proposed changes have no negative impact on this story, and actually make for a more clear lowering story from SomeDialect→StableHLO→MHLO, as opposed to the current setup which relies on bi-directional conversions in a few places.
(P1) Migrate CHLO→MHLO lowerings to CHLO→StableHLO.
In the current setup, CHLO lives in openxla/stablehlo, but all lowerings live in openxla/xla and target MHLO. This has caused some users who need these lowerings, but don’t want an XLA/MHLO dependency to duplicate these passes (ex1, ex2), and other users to convert CHLO→MHLO→StableHLO (ex3). Migrating these to StableHLO and updating existing XLA uses of the pass to use CHLO→StableHLO→MHLO shouldn’t pose any additional risks, as lowering StableHLO→MHLO is well tested, and is a part of native JAX execution today.
(P2) Migrate Shape→MHLO to Shape→StableHLO
In its current state, this pass is primarily used after CHLO decompositions which may introduce shape operations (ex1, ex2), so it makes sense to migrate these passes together. This poses little risk for the same reason as CHLO, where lowering in this direction is natural and well supported. There is a use of this pass in MHLO→HLO (ex3) but replacing this with the new lowering path should be simple, I’m happy to prototype and de-risk if needed.
(P3) Add opt-in canonicalization patterns to StableHLO
Another growing ecosystem tech debt has been canonicalizations (ex1, ex2). While this will add some duplication with MHLO, I think it is worth it for the broader ecosystem to have centralized backend-agnostic patterns that can be used. Given StableHLO’s role as an input dialect, I propose we add these only as opt-in patterns, no transformations should be applied by default. As for which canonicalization patterns to add, I propose doing this on an as-needed basis for patterns deemed useful by StableHLO users, and think the above two example links are a good starting point.
Interested in everyone’s thoughts!
Best,
Kevin
--
You received this message because you are subscribed to the Google Groups "OpenXLA Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openxla-discu...@openxla.org.
To view this discussion on the web visit https://groups.google.com/a/openxla.org/d/msgid/openxla-discuss/2f226258-19ef-4cea-9d91-506d7a24ea95n%40openxla.org.
For more options, visit https://groups.google.com/a/openxla.org/d/optout.
To view this discussion on the web visit https://groups.google.com/a/openxla.org/d/msgid/openxla-discuss/CANF-O%3DZSK-BzbeuRYxwrw0XtQrOSaPQTrtz6NhDL8Zzr6vfeWg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/openxla.org/d/msgid/openxla-discuss/CAH8pnHapRpSFdwNveefxacCp3KfFkMX7ZD3zkdENqdnV46CPcQ%40mail.gmail.com.
> If that line can be held in a community dialect like this, it is useful to have such things be universal/automatic.[...]> So SGTM to use the existing mechanisms for patterns that fit the mold.I agree with the end vision that "true canonicalizers should be universally/automatically applied". I'm more hesitant that we know exactly which patterns are "canonical" today. I also don't think there's a good use for fine-grained control of these patterns, so I'm also not proposing that.
My thinking is that can be done in two steps:
1. Introduce a non-native pass similar to iree-stablehlo-canonicalize, a "general simplifications" pass as Jacques described it
2. Graduate simplification patterns to canonicalizers over time and use the native MLIR machinery for canonicalizations