iree-org / iree

A retargetable MLIR-based machine learning compiler and runtime toolkit.
http://iree.dev/
Apache License 2.0
2.56k stars 572 forks source link

Assertion Error: `!ShapedType::isDynamic(d.value()) && "single dimension cannot be expanded into multiple dynamic " "dimensions"' failed. #8012

Closed gprateek93 closed 2 years ago

gprateek93 commented 2 years ago

The following IR is failing in the FusionOfTensorOps pass on IREE pipeline.

#map0 = affine_map<(d0, d1) -> (d0, d1)>
#map1 = affine_map<(d0) -> (d0)>
module attributes {torch.debug_module_name = "HistogramBinningCalibrationByFeature"}  {
  func @forward(%arg0: tensor<?xi64>, %arg1: tensor<?x?xi64>, %arg2: tensor<?x?xf32>) -> tensor<?xf32> {
    %c0 = arith.constant 0 : index
    %c1 = arith.constant 1 : index
    %cst = arith.constant 1.000000e+00 : f32
    %c-1_i64 = arith.constant -1 : i64
    %c1_i64 = arith.constant 1 : i64
    %cst_0 = arith.constant 0.9162907600402832 : f64
    %cst_1 = arith.constant 9.000000e-01 : f64
    %0 = tensor.dim %arg2, %c0 : tensor<?x?xf32>
    %1 = tensor.dim %arg2, %c1 : tensor<?x?xf32>
    %2 = linalg.init_tensor [%0, %1] : tensor<?x?xf32>
    %3 = linalg.generic {indexing_maps = [#map0, #map0], iterator_types = ["parallel", "parallel"]} ins(%arg2 : tensor<?x?xf32>) outs(%2 : tensor<?x?xf32>) {
    ^bb0(%arg3: f32, %arg4: f32):  // no predecessors
      %12 = arith.truncf %cst_0 : f64 to f32
      %13 = arith.sitofp %c1_i64 : i64 to f32
      %14 = arith.mulf %arg3, %13 : f32
      %15 = arith.subf %14, %12 : f32
      linalg.yield %15 : f32
    } -> tensor<?x?xf32>
    %4 = tensor.dim %3, %c0 : tensor<?x?xf32>
    %5 = tensor.dim %3, %c1 : tensor<?x?xf32>
    %6 = linalg.init_tensor [%4, %5] : tensor<?x?xf32>
    %7 = linalg.generic {indexing_maps = [#map0, #map0], iterator_types = ["parallel", "parallel"]} ins(%3 : tensor<?x?xf32>) outs(%6 : tensor<?x?xf32>) {
    ^bb0(%arg3: f32, %arg4: f32):  // no predecessors
      %12 = arith.negf %arg3 : f32
      %13 = math.exp %12 : f32
      %14 = arith.addf %13, %cst : f32
      %15 = arith.divf %cst, %14 : f32
      linalg.yield %15 : f32
    } -> tensor<?x?xf32>
    %8 = tensor.collapse_shape %7 [[0, 1]] : tensor<?x?xf32> into tensor<?xf32>
    %9 = tensor.dim %8, %c0 : tensor<?xf32>
    %10 = linalg.init_tensor [%9] : tensor<?xf32>
    %11 = linalg.generic {indexing_maps = [#map1, #map1], iterator_types = ["parallel"]} ins(%8 : tensor<?xf32>) outs(%10 : tensor<?xf32>) {
    ^bb0(%arg3: f32, %arg4: f32):  // no predecessors
      %12 = arith.truncf %cst_1 : f64 to f32
      %13 = arith.mulf %arg3, %12 : f32
      linalg.yield %13 : f32
    } -> tensor<?xf32>
    return %11 : tensor<?xf32>
  }
}

The error message is as follows:

 ireec: /home/prateekgupta/iree-npcomp/external/iree/third_party/llvm-project/mlir/lib/Dialect/Tensor/IR/TensorInferTypeOpInterfaceImpl.cpp:99: mlir::OpFoldResult getExpandedOutputDimFromInputShape(mlir::OpBuilder &, mlir::Location, int64_t, mlir::Value, ArrayRef<int64_t>, ArrayRef<mlir::AffineMap>, llvm::DenseMap<int64_t, int64_t> &): Assertion `!ShapedType::isDynamic(d.value()) && "single dimension cannot be expanded into multiple dynamic " "dimensions"' failed.

One can execute the above IR successfully by disabling the FusionOfTensorOps pass.

GMNGeoffrey commented 2 years ago

Could you include the full stack trace please?

MaheshRavishankar commented 2 years ago

Looking at this now.

MaheshRavishankar commented 2 years ago

https://reviews.llvm.org/D116703 fixes the issue.