-
Notifications
You must be signed in to change notification settings - Fork 512
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
mhlo: migrate conversion to stablehlo #1840
Conversation
@ashay Oh that's a good catch! When we forked StableHLO from MHLO, we did a survey of frontends and looked into which MHLO ops are used and which ops aren't. Only the former ops made the cut, and
I see that at the moment torch-mlir/lib/Conversion/TorchToMhlo/Basic.cpp Line 1382 in 5057e88
|
Nit: possibly in a separate PR, we can rename all the Also when possible, updating the VerifyStablehloBackendContract pass to reject Mhlo would be good (in some sense that is the true milestone of completion of this workstream). And if we can get sign-off from @burmako that it is indeed checking the correct set of ops: https://github.com/llvm/torch-mlir/pull/1840/files#diff-d8eb5bebe72fb7e5c0d49bd9c2234d6ac74e44f250d38e7f0d7af0fee52530d7 -- two questions:
|
Fixed in this PR.
Since the TorchToMhlo pipeline ultimately lowers to Mhlo, I don't think we can get rid of the VerifyMhloBackendContract pass. So I added the VerifyStablehloBackendContract pass after the torch-to-stablehlo conversion while retaining the existing VerifyMhloBackendContract pass., |
This patch replaces all MHLO operations with their StableHLO counterparts and adds a validation pass to ensure that no MHLO operations remain before translating all Stablehlo operations to the MHLO dialect for further lowering to the Linalg dialect. This patch also updates all lit tests so that they refer to the `convert-torch-to-stablehlo` pass and so that they check for StableHLO operations.
Since the dialect translation previous generated MHLO operations, the names of many files, functions, and passes referred to the MHLO dialect. This patch renames them to refer to Stablehlo.
It should lower to StableHLO and not Mhlo. The later lowering to MHLO is really just used as part of e2e testing since only mhlo has a path to linalg. Other than that incidental aspect MHLO is irrelevant to Torch-MLIR. (StableHLO has a path to MHLO, but that is not our project's responsibility) Concretely we would put lowering stablehlo->mhlo here:
(and that whole directory structure also needs to be renamed to stablehlo, as well as the e2e test config) |
As far as VerifyStablehloBackendContract goes, how about we populate it with the contents of the current VerifyMhloBackendContract with the only change being Here's the rationale for this proposal: StableHLO is ready to serve as a drop-in replacement for MHLO in the role of an interface between ML frameworks and ML compilers. It supports everything that MHLO supports at the interface level, and then some, but some future work still remains, namely:
Given that, the existing pieces of VerifyMhloBackendContract make sense:
As we're working through these open questions, I expect that we'll be able to eventually shrink the backend contract. For example, one potential future could involve: a) keeping What do you think? |
Thanks Eugene, this makes sense to me! Looking forward to collaborating to tighten this up! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but let's wait for one of the owners of StableHLO support in Torch-MLIR approve as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This patch replaces all MHLO operations with their StableHLO counterparts and adds a validation pass to ensure that no MHLO operations remain before translating all Stablehlo operations to the MHLO dialect for further lowering to the Linalg dialect. This patch also updates all lit tests so that they refer to the `convert-torch-to-stablehlo` pass and so that they check for StableHLO operations.
This patch replaces all MHLO operations with their StableHLO
counterparts and adds a validation pass to ensure that no MHLO operations
remain before translating all Stablehlo operations to the MHLO dialect
for further lowering to the Linalg dialect.
This patch also updates all lit tests so that they refer to the
convert-torch-to-stablehlo
pass and so that they check for StableHLOoperations.