-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][tensor] Remove assertion in ExpandShapeOp::build #91361
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
Conversation
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-tensor Author: Benoit Jacob (bjacob) ChangesUnblocking downstream integrate where an expected-to-fail test was expecting this to be a runtime verifier error, not a compiler crash: llvm/torch-mlir#3279. Full diff: https://github.com/llvm/llvm-project/pull/91361.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
index 4c65045084dc..7a13f7a7d135 100644
--- a/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
+++ b/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp
@@ -1676,10 +1676,12 @@ void ExpandShapeOp::build(OpBuilder &builder, OperationState &result,
auto tensorResultTy = cast<RankedTensorType>(resultType);
FailureOr<SmallVector<OpFoldResult>> outputShape = inferOutputShape(
builder, result.location, tensorResultTy, reassociation, inputShape);
- // Failure of this assertion usually indicates presence of multiple
- // dynamic dimensions in the same reassociation group.
- assert(succeeded(outputShape) && "unable to infer output shape");
- build(builder, result, tensorResultTy, src, reassociation, *outputShape);
+ SmallVector<OpFoldResult> outputShapeOrEmpty;
+ if (succeeded(outputShape)) {
+ outputShapeOrEmpty = *outputShape;
+ }
+ build(builder, result, tensorResultTy, src, reassociation,
+ outputShapeOrEmpty);
}
SmallVector<AffineMap, 4> CollapseShapeOp::getReassociationMaps() {
|
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.
Would it be possible to add test?
as a follow-up please :-) need to unblock the downstreams. also, the test would ideally test for a helpful error message, which runs into a problem i had writing this PR: I dont know how if it's safe to call So +1 to a follow-up that finds how to generate a helpful error , and tests that. |
I think we can capture the invalid op in op verifier. I'd suggest that we update the below code as well. It should look at expand_shape shape inference too. Then we can add the invalid op test to https://github.com/llvm/llvm-project/blob/main/mlir/test/Dialect/Tensor/invalid.mlir . What do you think? llvm-project/mlir/lib/Dialect/Tensor/IR/TensorOps.cpp Lines 1751 to 1786 in 026a29e
|
oh... ok, i can give that a try. |
Actually there is another problem: this condition in C++ builder code is impossible to exercise from |
Sorry that my comment was not clear.. It is true that it is hard to test c++ builder code. My point is that the build methods and verify methods should be aligned in some sense. It is okay to generate invalid op, but the verifier should signal it. In the case we've seen in torch-mlir repo, it is generating something like: tensor.expand_shape %arg0 [[0, 1]] output_shape [%sz0, %sz1] : tensor<?xf32> into tensor<?x?xf32> So I'd suggest add the invalid op to |
Actually, this IR is not invalid anymore(#90040). This indicates that we are calling the wrong build method(that's why the assertion). We need to raise some sort of signal in place of assertion(maybe in follow up PR). |
Yeah IR like this would go to the To exercise the error condition we are talking about here, which is in the |
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.
I see... thanks for filling me the context
Unblocking downstream integrate where an expected-to-fail test was expecting this to be a runtime verifier error, not a compiler crash: llvm/torch-mlir#3279.