[LinalgExt] Fix operand order in attention normalization (#25170) Fix operand order in attention normalization - use value op scale instead of scale op value, which produces wrong results for a division - harden testcase, to check for correct operand order - Introduced in #18890 Co-authored-by: Thomas Ziereis <ziereis@roofline.ai> Statement of AI usage: Claude code was used, to look up, where this was introduced --------- Signed-off-by: Tim Jammer <jammer@roofline.ai> Co-authored-by: Thomas Ziereis <ziereis@roofline.ai>
diff --git a/compiler/src/iree/compiler/Dialect/LinalgExt/IR/AggregatedOpInterfaceImpl.cpp b/compiler/src/iree/compiler/Dialect/LinalgExt/IR/AggregatedOpInterfaceImpl.cpp index 096a0c5..362d621 100644 --- a/compiler/src/iree/compiler/Dialect/LinalgExt/IR/AggregatedOpInterfaceImpl.cpp +++ b/compiler/src/iree/compiler/Dialect/LinalgExt/IR/AggregatedOpInterfaceImpl.cpp
@@ -54,7 +54,7 @@ // Convert scale to the same datatype as input. Value scale = convertScalarToDtype(b, loc, args[0], args[1].getType(), /*isUnsignedCast=*/false); - Value result = T::create(b, loc, scale, args[1]); + Value result = T::create(b, loc, args[1], scale); linalg::YieldOp::create(b, loc, result); }); return genericOp.getResult(0);
diff --git a/compiler/src/iree/compiler/Dialect/LinalgExt/IR/TilingInterfaceImpl.cpp b/compiler/src/iree/compiler/Dialect/LinalgExt/IR/TilingInterfaceImpl.cpp index 096e1b3..57c3c6b 100644 --- a/compiler/src/iree/compiler/Dialect/LinalgExt/IR/TilingInterfaceImpl.cpp +++ b/compiler/src/iree/compiler/Dialect/LinalgExt/IR/TilingInterfaceImpl.cpp
@@ -3624,7 +3624,7 @@ // Convert scale to the same datatype as input. Value scale = convertScalarToDtype(b, loc, args[0], args[1].getType(), /*isUnsignedCast=*/false); - Value result = T::create(b, loc, scale, args[1]); + Value result = T::create(b, loc, args[1], scale); linalg::YieldOp::create(b, loc, result); }); return genericOp.getResult(0);
diff --git a/compiler/src/iree/compiler/Dialect/LinalgExt/IR/test/decompose_aggregate_op.mlir b/compiler/src/iree/compiler/Dialect/LinalgExt/IR/test/decompose_aggregate_op.mlir index b82d514..aeec85d 100644 --- a/compiler/src/iree/compiler/Dialect/LinalgExt/IR/test/decompose_aggregate_op.mlir +++ b/compiler/src/iree/compiler/Dialect/LinalgExt/IR/test/decompose_aggregate_op.mlir
@@ -126,8 +126,9 @@ // CHECK: linalg.yield // P = P /= sum // CHECK: linalg.generic +// CHECK: ^bb0(%[[SUM:.*]]: f32, %[[P:.*]]: f32): // CHECK-NOT: arith.extf -// CHECK: arith.divf +// CHECK: arith.divf %[[P]], %[[SUM]] // CHECK: linalg.yield // truncf P : f32 to f16 // CHECK: linalg.generic