iree: large vector sizes failure - cpu compilation - quantised models

What happened?

On compiling a model with int8 quantization one of the dispatches fails to compile with the following error:

error: One or more operations with large vector sizes (16384 bytes) were found 

Min repro adapted from the failing dispatch:

module {
  func.func @largeVectorMinRepro(%arg0: tensor<1x320x65x65xi8>) -> tensor<1x320x1x1xf32> {
        %cst = arith.constant 1.250000e-01 : f32
        %cst_0 = arith.constant 0.000000e+00 : f32
        %c5408000 = arith.constant 5408000 : index
        %c0 = arith.constant 0 : index
        %3 = tensor.empty() : tensor<1x320x1x1xf32>
        %4 = tensor.empty() : tensor<65x65xf32>
        %5 = tensor.empty() : tensor<1x320x65x65xf32>
        %6 = linalg.fill ins(%cst_0 : f32) outs(%3 : tensor<1x320x1x1xf32>) -> tensor<1x320x1x1xf32>
        %7 = linalg.generic {indexing_maps = [affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>, affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>], iterator_types = ["parallel", "parallel", "parallel", "parallel"]} ins(%arg0 : tensor<1x320x65x65xi8>) outs(%5 : tensor<1x320x65x65xf32>) {
        ^bb0(%in: i8, %out: f32):
          %9 = arith.extsi %in : i8 to i32
          %10 = arith.sitofp %9 : i32 to f32
          %11 = arith.mulf %10, %cst : f32
          linalg.yield %11 : f32
        } -> tensor<1x320x65x65xf32>
        %8 = linalg.pooling_nchw_sum  ins(%7, %4 : tensor<1x320x65x65xf32>, tensor<65x65xf32>) outs(%6 : tensor<1x320x1x1xf32>) -> tensor<1x320x1x1xf32>
    return %8 : tensor<1x320x1x1xf32>
  }
}

compile command : iree-compile --iree-input-demote-i64-to-i32 --iree-hal-target-backends=llvm-cpu largevectorissue.minrepro.mlir -o test.vmfb

host issue here

Steps to reproduce your issue

  1. Go to ‘…’
  2. Click on ‘…’
  3. Scroll down to ‘…’
  4. See error

What component(s) does this issue relate to?

No response

Version information

No response

Additional context

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 18 (18 by maintainers)

Commits related to this issue

Most upvoted comments

We shouldn’t have them in between, they dont get cloned. Its possible that this came from CollapseDimensionsPass

I’m going to take a look at that

It’s hard to write such verifiers cause they are dependent on implementation status of codegen and not tied to any “real” constraints (like large vectors are bad, or large stack allocations are bad).

IIUC this is a bug. And we will need to investigate cause for every time we hit this error (it’s basically a catch all for “something went off the rails”). Not sure we can really do better than that

I think there are numeric issues because you initialize the acc to zeros every time. That’s why I’m saying that we should only fuse the input operands when tiling the reduction loops.

Let’s take gemm as an example. Code1 is what you’re doing when fuse the fill op, but what we want is Code2. Does it make sense?

Code1:

for (int i = 0; i < M; ++i)  {
  for (int j = 0; j < N; ++j) {
     for (int k = 0; k < K; ++k) {
       int64_t acc = 0; // linalg.fill
       acc = A[i][k] + B[k][j] // linalg.mamtul
       C[i][j] = acc; // scf.yield
     }
  }
}

Code2:


for (int i = 0; i < M; ++i)  {
  for (int j = 0; j < N; ++j) {
     C[i][j] = 0; // linalg.fill
     int64_t acc = C[i][j]; // iter_args(%arg6 = %arg4)
     for (int k = 0; k < K; ++k) {
       acc += A[i][k] + B[k][j] // linalg.mamtul
       C[i][j] = acc; // scf.yield
     }
  }
}

(You can try e2e tests with your suggestion, I think it will generate wrong outputs.)

@pashu123 this seems like a codegen bug. Please take a look