Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mlir][linalg] Fix numerical issue with softmax #96090

Merged
merged 1 commit into from
Jun 20, 2024
Merged

Conversation

pashu123
Copy link
Member

@llvmbot
Copy link
Member

llvmbot commented Jun 19, 2024

@llvm/pr-subscribers-mlir-linalg

@llvm/pr-subscribers-mlir

Author: Prashant Kumar (pashu123)

Changes

For more info:
iree-org/iree#17670 (comment)


Full diff: https://github.com/llvm/llvm-project/pull/96090.diff

2 Files Affected:

  • (modified) mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp (+2-2)
  • (modified) mlir/test/Dialect/Linalg/transform-op-decompose.mlir (+1-1)
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
index 7b6256050e772..57d126603ebd7 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
@@ -2714,8 +2714,8 @@ FailureOr<SmallVector<Value>> SoftmaxOp::decomposeOperation(OpBuilder &b) {
   Value neutralForMaxFInit =
       b.create<linalg::FillOp>(loc, Value{neutralForMaxF}, outputReduce)
           .result();
-  Value max = reduce<arith::MaximumFOp>(b, loc, input, neutralForMaxFInit,
-                                        reductionDim);
+  Value max =
+      reduce<arith::MaxNumFOp>(b, loc, input, neutralForMaxFInit, reductionDim);
 
   // Step 2: Subtract max from input and exponentiate.
   Value numerator = buildSubAndExpOp(b, loc, input, max, output, reductionDim);
diff --git a/mlir/test/Dialect/Linalg/transform-op-decompose.mlir b/mlir/test/Dialect/Linalg/transform-op-decompose.mlir
index ef0aca2cc366f..2e211d2fa7dbe 100644
--- a/mlir/test/Dialect/Linalg/transform-op-decompose.mlir
+++ b/mlir/test/Dialect/Linalg/transform-op-decompose.mlir
@@ -215,7 +215,7 @@ func.func @softmax(%arg0: tensor<2x16x32xf32>, %dst: tensor<2x16x32xf32>) -> ten
 // CHECK:        %[[D3:.+]] = linalg.generic {indexing_maps = [#[[$MAP]], #[[$MAP1]]], iterator_types = ["parallel",
 // CHECK-SAME:     "parallel", "reduction"]} ins(%[[ARG0]] : tensor<2x16x32xf32>) outs(%[[D2]] : tensor<2x16xf32>) {
 // CHECK:        ^bb0(%[[IN:.+]]: f32, %[[OUT:.+]]: f32):
-// CHECK:          %[[D8:.+]] = arith.maximumf %[[IN]], %[[OUT]] : f32
+// CHECK:          %[[D8:.+]] = arith.maxnumf %[[IN]], %[[OUT]] : f32
 // CHECK:          linalg.yield %[[D8]] : f32
 // CHECK:        } -> tensor<2x16xf32>
 // CHECK:        %[[D4:.+]] = linalg.generic {indexing_maps = [#[[$MAP]], #[[$MAP1]], #[[$MAP]]], iterator_types =

@pashu123 pashu123 requested a review from hanhanW June 19, 2024 16:42
@pashu123 pashu123 merged commit fa06668 into llvm:main Jun 20, 2024
10 checks passed
Max191 added a commit to iree-org/llvm-project that referenced this pull request Jun 28, 2024
qedawkins pushed a commit to iree-org/llvm-project that referenced this pull request Jul 2, 2024
qedawkins pushed a commit to iree-org/llvm-project that referenced this pull request Jul 3, 2024
yzhang93 pushed a commit to iree-org/llvm-project that referenced this pull request Jul 9, 2024
kuhar pushed a commit to iree-org/llvm-project that referenced this pull request Jul 9, 2024
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
yzhang93 pushed a commit to iree-org/llvm-project that referenced this pull request Jul 11, 2024
yzhang93 pushed a commit to iree-org/llvm-project that referenced this pull request Jul 11, 2024
aviator19941 pushed a commit to iree-org/llvm-project that referenced this pull request Jul 16, 2024
Max191 added a commit to iree-org/llvm-project that referenced this pull request Jul 16, 2024
aviator19941 pushed a commit to iree-org/llvm-project that referenced this pull request Jul 18, 2024
aviator19941 pushed a commit to iree-org/llvm-project that referenced this pull request Jul 22, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 24, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 24, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 24, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 24, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 24, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 24, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 24, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 25, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 26, 2024
ScottTodd pushed a commit to iree-org/llvm-project that referenced this pull request Jul 26, 2024
bjacob pushed a commit to iree-org/llvm-project that referenced this pull request Jul 27, 2024
bjacob pushed a commit to iree-org/llvm-project that referenced this pull request Jul 27, 2024
bjacob pushed a commit to iree-org/llvm-project that referenced this pull request Jul 29, 2024
bjacob pushed a commit to iree-org/llvm-project that referenced this pull request Jul 29, 2024
bjacob pushed a commit to iree-org/llvm-project that referenced this pull request Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants