Skip to content

error: pattern listener tracker fail; transform dialect interpreter failed #13419

Closed

Description

@silvasean

What happened?

The transform-dialect-based lowering seems to be hitting an issue with this test case.

Run with no_attention2.mlir from here

iree-compile --iree-hal-target-backends=cuda --iree-input-type=mhlo --iree-hal-cuda-llvm-target-arch=sm_80 no_attention2.mlir

Sorry for the large test case. The failing dispatch looks like this but for some reason isolating it into a small repro doesn't reproduce the failure for me locally.

    builtin.module {
      func.func @_main_dispatch_342_generic_2048x2048_f32(%arg0: !flow.dispatch.tensor<readonly:tensor<2048x2048xf32>>, %arg1: !flow.dispatch.tensor<readonly:tensor<2048xf32>>, %arg2: !flow.dispatch.tensor<writeonly:tensor<2048xf32>>) {
        %cst = arith.constant 0.000000e+00 : f32
        %cst_0 = arith.constant 2.048000e+03 : f32
        %0 = flow.dispatch.tensor.load %arg0, offsets = [0, 0], sizes = [2048, 2048], strides = [1, 1] : !flow.dispatch.tensor<readonly:tensor<2048x2048xf32>> -> tensor<2048x2048xf32>
        %1 = flow.dispatch.tensor.load %arg1, offsets = [0], sizes = [2048], strides = [1] : !flow.dispatch.tensor<readonly:tensor<2048xf32>> -> tensor<2048xf32>
        %2 = tensor.empty() : tensor<2048xf32>
        %3 = linalg.fill ins(%cst : f32) outs(%2 : tensor<2048xf32>) -> tensor<2048xf32>
        %4 = linalg.generic {indexing_maps = [#map4, #map8], iterator_types = ["parallel", "reduction"]} ins(%0 : tensor<2048x2048xf32>) outs(%3 : tensor<2048xf32>) {
        ^bb0(%in: f32, %out: f32):
          %6 = arith.negf %in : f32
          %7 = arith.addf %out, %6 : f32
          linalg.yield %7 : f32
        } -> tensor<2048xf32>
        %5 = linalg.generic {indexing_maps = [#map, #map, #map, #map], iterator_types = ["parallel"]} ins(%4, %1, %3 : tensor<2048xf32>, tensor<2048xf32>, tensor<2048xf32>) outs(%2 : tensor<2048xf32>) {
        ^bb0(%in: f32, %in_1: f32, %in_2: f32, %out: f32):
          %6 = arith.addf %in, %in_1 : f32
          %7 = arith.divf %6, %cst_0 : f32
          %8 = arith.addf %in_2, %7 : f32
          linalg.yield %8 : f32
        } -> tensor<2048xf32>
        flow.dispatch.tensor.store %5, %arg2, offsets = [0], sizes = [2048], strides = [1] : tensor<2048xf32> -> !flow.dispatch.tensor<writeonly:tensor<2048xf32>>
        return
      }
    }

Full error log link

Steps to reproduce your issue

See above

What component(s) does this issue relate to?

Compiler

Version information

iree.git @ ab37989

Additional context

No response

Activity

  1. added
    bug 🐞
    on May 4, 2023
  2. stellaraccident commented on May 4, 2023

    @stellaraccident
    Collaborator

    @ftynse can you have a look?

  3. ftynse commented on May 5, 2023

    @ftynse
    Contributor

    I don't seem to be able to reproduce this. Getting a different error about func.func @_main having mismatching argument types and signature.

    <unknown>:0: error: 'func.func' op type of entry block argument #0('i32') must match the type of the corresponding argument in function signature('tensor<i32>')
    
  4. ftynse commented on May 5, 2023

    @ftynse
    Contributor

    If I disable the verifier, I can get slightly further to error: failed to legalize unresolved materialization from '!stream.resource<*>', 'index' to 'i32' that remained live after conversion, but this comes from the Stream level. Transform dialect interpreter runs later than that and I cannot reach it.

  5. silvasean commented on May 5, 2023

    @silvasean
    ContributorAuthor

    That seems like the error from llvm/llvm-project#62249 (I have a workaround patched locally). (I haven't synced to head due to #13189). To work around it you can disable the detensorize pass as described in step 1 here: #13202 (comment)

  6. silvasean commented on May 5, 2023

    @silvasean
    ContributorAuthor

    FYI if it is useful, I worked around this particular issue in the program and hit another instance of this on another dispatch region. Seems to be another reduction.

      flow.executable private @_main_dispatch_949 {
        flow.executable.export public @_main_dispatch_949_generic_8192x2048_f32 workgroups(%arg0: index) -> (index, index, index) {
          %x, %y, %z = flow.dispatch.workgroup_count_from_dag_root %arg0
          flow.return %x, %y, %z : index, index, index
        }
        builtin.module {
          func.func @_main_dispatch_949_generic_8192x2048_f32(%arg0: !flow.dispatch.tensor<readonly:tensor<2048x8192xf32>>, %arg1: !flow.dispatch.tensor<readonly:tensor<8192xf32>>, %arg2: !flow.dispatch.tensor<readonly:tensor<8192xi1>>, %arg3: !flow.dispatch.tensor<writeonly:tensor<8192xf32>>) {
            %cst = arith.constant 0.000000e+00 : f32
            %0 = flow.dispatch.tensor.load %arg0, offsets = [0, 0], sizes = [2048, 8192], strides = [1, 1] : !flow.dispatch.tensor<readonly:tensor<2048x8192xf32>> -> tensor<2048x8192xf32>
            %1 = flow.dispatch.tensor.load %arg1, offsets = [0], sizes = [8192], strides = [1] : !flow.dispatch.tensor<readonly:tensor<8192xf32>> -> tensor<8192xf32>
            %2 = flow.dispatch.tensor.load %arg2, offsets = [0], sizes = [8192], strides = [1] : !flow.dispatch.tensor<readonly:tensor<8192xi1>> -> tensor<8192xi1>
            %3 = tensor.empty() : tensor<8192xf32>
            %4 = linalg.fill ins(%cst : f32) outs(%3 : tensor<8192xf32>) -> tensor<8192xf32>
            %5 = linalg.generic {indexing_maps = [affine_map<(d0, d1) -> (d1, d0)>, affine_map<(d0, d1) -> (d0)>], iterator_types = ["parallel", "reduction"]} ins(%0 : tensor<2048x8192xf32>) outs(%4 : tensor<8192xf32>) {
            ^bb0(%in: f32, %out: f32):
              %7 = arith.addf %out, %in : f32
              linalg.yield %7 : f32
            } -> tensor<8192xf32>
            %6 = linalg.generic {indexing_maps = [affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>, affine_map<(d0) -> (d0)>], iterator_types = ["parallel"]} ins(%1, %2, %5, %4 : tensor<8192xf32>, tensor<8192xi1>, tensor<8192xf32>, tensor<8192xf32>) outs(%3 : tensor<8192xf32>) {
            ^bb0(%in: f32, %in_0: i1, %in_1: f32, %in_2: f32, %out: f32):
              %7 = arith.addf %in_2, %in_1 : f32
              %8 = arith.select %in_0, %7, %cst : f32
              %9 = arith.addf %in, %8 : f32
              linalg.yield %9 : f32
            } -> tensor<8192xf32>
            flow.dispatch.tensor.store %6, %arg3, offsets = [0], sizes = [8192], strides = [1] : tensor<8192xf32> -> !flow.dispatch.tensor<writeonly:tensor<8192xf32>>
            return
          }
        }
      }
    
  7. ftynse commented on May 6, 2023

    @ftynse
    Contributor

    The issue comes from upstream for some reason failing the tracking when an op is "replaced" with another pre-existing op. This sounds perfectly valid in, e.g., CSE. Shortcutting that with

    diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
    index 6284b41302e2..d43234bb6e48 100644
    --- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
    +++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
    @@ -181,8 +181,12 @@ transform::TrackingListener::findReplacementOp(Operation *op,
         return nullptr;
     
       // If the replacement op is not a new op, drop the mapping.
    -  if (!isNewOp(defOp))
    +#if 0
    +  if (!isNewOp(defOp)) {
    +    llvm::errs() << "is not a new op " << *defOp << "\n";
         return nullptr;
    +  }
    +#endif
     
       return defOp;
     }

    removes this particular issue. @matthias-springer any reason why the replacement must be a new op?

  8. ftynse commented on May 6, 2023

    @ftynse
    Contributor

    Also with that shortcut, we start hitting another issue:

    /home/silvasean/paxml/praxis/praxis/layers/normalizations.py:367:0: error: a handle passed as operand #0 and consumed by this operation points to a payload entity more than once
    /home/silvasean/paxml/praxis/praxis/layers/normalizations.py:367:0: note: repeated target op
    

    Where the problematic transform op is

    %5 = transform.structured.fuse_into_containing_op %2 into %forall_op_3

    and the payload op is

    %10 = linalg.fill ins(%cst : f32) outs(%extracted_slice_2 : tensor<1xf32>) -> tensor<1xf32>

    For some reason, %2 points to two operations. It is produced by the chain

    %0:4 = transform.iree.match_callback failures(propagate) "reduction"(%arg0) : (!pdl.operation) -> (!pdl.operation, !pdl.operation, !pdl.operation, !pdl.operation)
    %2 = transform.structured.fuse_into_containing_op %0#1 into %forall_op
    

    so it must be only linalg.fill. Further investigation shows that %2 is being assigned two payloads by fuse_into_containing_op. I suspect we may be hitting this TODO:

    https://github.com/llvm/llvm-project/blob/3fb067f7ba8e7fee66b0740705f4bc767638ccc7/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp#L641-L645

    but I ran out of time. Will pick up when I get meeting-free time.

  9. allieculp commented on May 9, 2023

    @allieculp

    @ftynse Setting this to P1, in progress. Let us know when you have an update!

  10. moved this from Inbox to In Progress in (Deprecated) IREEon May 9, 2023
  11. allieculp commented on May 9, 2023

    @allieculp

    @nicolasvasilache for visibility

  12. 15 remaining items

  13. silvasean commented on May 16, 2023

    @silvasean
    ContributorAuthor

    With D150429 additionally applied, the error appears to be gone! Do we know when all the necessary fixes will land in IREE head?

  14. ftynse commented on May 17, 2023

    @ftynse
    Contributor

    Nice! I don't know how IREE handles upstream integrates and couldn't find any relevant documentation. #13651 attempts to integrate past the relevant upstream changes, but is currently blocked by mlir-hlo cmake build being broken.

  15. ScottTodd commented on May 17, 2023

    @ScottTodd
    Member

    I don't know how IREE handles upstream integrates and couldn't find any relevant documentation.

    https://github.com/openxla/iree/tree/main/build_tools/scripts/integrate

  16. ftynse commented on May 17, 2023

    @ftynse
    Contributor

    #13651 attempts to integrate past the relevant upstream changes, but is currently blocked by mlir-hlo cmake build being broken.

    Solved that, now blocked by end-to-end tests stored outside the repo (?) that fail because of TOSA upstream changes.

  17. allieculp commented on May 19, 2023

    @allieculp

    @ftynse @silvasean Is this fixed?

  18. ftynse commented on May 20, 2023

    @ftynse
    Contributor
  19. MaheshRavishankar commented on May 25, 2023

    @MaheshRavishankar
    Collaborator

    @silvasean the required commit has made it into IREE.

  20. silvasean commented on May 25, 2023

    @silvasean
    ContributorAuthor

    Okay let's close this then (I verified it with the patch applied locally in #13419 (comment))

  21. moved this from Needs Verification to Done in (Deprecated) IREEon May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐞

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions