Open pdhirajkumarprasad opened 2 weeks ago
@pdhirajkumarprasad Do you know how I can get and run these failed models? https://github.com/pdhirajkumarprasad/SHARK-TestSuite/blob/feature/qa/issue/onnx-to-torch/unresolved_materialization I would like to see a bigger IR.
Download below scripts: run.sh.txt upgrade_onnx.py.txt
Rename to run.sh/upgrade_onnx.py(by removing the .txt) extension
Save the model in file say modelList
Run: ./run.sh modelList
It will save the logs in ./temp directory
@pdhirajkumarprasad @jinchen62 The IR is inherently wrong, but this error message is generated from a (possibly) faulty lowering. Shape should not go for an empty tensor(scalar) as there is not point for that.
This (rough) patch should fix this error and produce a correct one from MLIR:
diff --git a/lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp b/lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp
index 68868e95..4fb5aa53 100644
--- a/lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp
+++ b/lib/Conversion/TorchOnnxToTorch/DefaultDomainQtoZ.cpp
@@ -1659,6 +1659,12 @@ void mlir::torch::onnx_c::populateDefaultDomainQtoZ(
auto inputType = dyn_cast<Torch::ValueTensorType>(operand.getType());
int64_t inputRank = inputType.getSizes().size();
+ if (start == 0 && end == -1) {
+ rewriter.replaceOpWithNewOp<Torch::Aten_ShapeAsTensorOp>(
+ binder.op, resultType, operand);
+ return success();
+ }
+
auto shapeType = Torch::ValueTensorType::get(
binder.op->getContext(), SmallVector<int64_t>{inputRank},
resultType.getOptionalDtype());
@@ -1666,11 +1672,6 @@ void mlir::torch::onnx_c::populateDefaultDomainQtoZ(
Value shape = rewriter.create<Torch::Aten_ShapeAsTensorOp>(
binder.getLoc(), shapeType, operand);
- if (start == 0 && end == -1) {
- rewriter.replaceOp(binder.op, shape);
- return success();
- }
-
Value sv = rewriter.create<Torch::ConstantIntOp>(
binder.getLoc(), rewriter.getI64IntegerAttr(start));
@@ -1681,10 +1682,9 @@ void mlir::torch::onnx_c::populateDefaultDomainQtoZ(
Value dim = rewriter.create<Torch::ConstantIntOp>(binder.getLoc(), 0);
- shape = rewriter.create<Torch::AtenSliceTensorOp>(
- binder.getLoc(), resultType, shape, dim, sv, ev, step);
+ rewriter.replaceOpWithNewOp<Torch::AtenSliceTensorOp>(
+ binder.op, resultType, shape, dim, sv, ev, step);
- rewriter.replaceOp(binder.op, shape);
return success();
});
I think we should handle scalar inputs and error out more gracefully in such cases.
When we returned in the first if
condition, the resultType was not consumed, hence the materialization error.
For the given IR, getting error as
command: