[ONNX] Disable type-unsafe Cast transpose fusion - #3607
Open
liquetxnx wants to merge 2 commits into
Open
Conversation
Signed-off-by: Eunsang Son <liquetxnx22@gmail.com>
Add a Transpose-Cast-Transpose ONNX MLIR reproducer and preserve the canonicalization and LLVM lowering results. Before the fix, FuseTransposeAndCastPattern creates a Cast with to=i64 but an f32 result type, causing verification and LLVM lowering to fail. After the fix, the valid operation chain is preserved and lowers to fptosi. Signed-off-by: Eunsang Son <liquetxnx22@gmail.com>
Collaborator
|
Can one of the admins verify this patch? |
Collaborator
|
@jenkins-droid test this please |
Collaborator
|
@jenkin-droid test this please |
Collaborator
|
@jenkins-droid test this please |
1 similar comment
Collaborator
|
@jenkins-droid test this please |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
canonicalizepass creates an invalidonnx.Cast.The original Cast is valid:
After canonicalization, a rewritten Cast has
to = f32but anf16result:This causes:
Reproduction
The invalid rewritten IR can be inspected with:
Relevant data flow
The original data flow is:
The Reshape input and result types are identical:
Canonicalization can remove the identity Reshape, exposing:
Suspected cause
The likely source is the Transpose/elementwise fusion pattern in:
The relevant two-argument pattern reconstructs the elementwise operation using (about 680 lines):
This works for type-preserving operations such as
Relu, but not forONNXCastOp.When
$vistensor<...xf16>, the rewritten Cast receives anf16resulttype even though its
toattribute isf32.Expected behavior
The rewritten Cast should preserve the Cast result element type:
Suggested fix
ONNXCastOpfrom this generic type-preserving fusion pattern