Skip to content

Commit 8640c5d

Browse files
authored
Merge branch 'main' into mschofie/windows-fixes
2 parents fbad338 + 281114a commit 8640c5d

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/Dialect/ONNX/Transforms/Recompose.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ struct RecomposeLayerNormFromMulPattern : public OpRewritePattern<ONNXMulOp> {
271271
return reportFailure("RMS norm mul has too many uses");
272272
if (isdRecipOp && !isdRecipOp->hasOneUse())
273273
return reportFailure("RMS norm recip has too many uses");
274-
if (!nsMulOp->hasOneUse())
275-
return reportFailure("RMS norm scale mul has too many uses");
276274
// Now check values epsilon.
277275
if (!isScalarTensor(epsilon))
278276
return reportFailure("RMS epsilon is expected to be scalar");

test/mlir/onnx/onnx_recompose.mlir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,28 @@ func.func @rms_layer_norm_v2(%x: tensor<1x384x768xf32>, %scale: tensor<768xf32>,
247247

248248
// -----
249249

250+
// RMS Layer norm with multiple uses of the scale multiplication
251+
func.func @rms_layer_norm_multi_use(%x: tensor<1x384x768xf32>, %scale: tensor<768xf32>) -> (tensor<1x384x768xf32>) {
252+
%eps = onnx.Constant dense<9.99999974E-6> : tensor<f32>
253+
%dd = "onnx.Mul"(%x, %x) : (tensor<1x384x768xf32>, tensor<1x384x768xf32>) -> tensor<1x384x768xf32>
254+
%var = "onnx.ReduceMeanV13"(%dd) {axes = [-1], keepdims = 1 : si64, onnx_node_name = "ReduceMean_42"} : (tensor<1x384x768xf32>) -> tensor<1x384x1xf32>
255+
%varEps = "onnx.Add"(%eps, %var) : (tensor<f32>, tensor<1x384x1xf32>) -> tensor<1x384x1xf32>
256+
%StdDev = "onnx.Sqrt"(%varEps) : (tensor<1x384x1xf32>) -> tensor<1x384x1xf32>
257+
%Norm = "onnx.Div"(%x, %StdDev) : (tensor<1x384x768xf32>, tensor<1x384x1xf32>) -> tensor<1x384x768xf32>
258+
%NormScaled = "onnx.Mul"(%scale, %Norm) : (tensor<768xf32>, tensor<1x384x768xf32>) -> tensor<1x384x768xf32>
259+
%MultiUse = "onnx.Add"(%NormScaled, %NormScaled) : (tensor<1x384x768xf32>, tensor<1x384x768xf32>) -> tensor<1x384x768xf32>
260+
return %MultiUse : tensor<1x384x768xf32>
261+
// CHECK-LABEL: func.func @rms_layer_norm_multi_use
262+
// CHECK-SAME: ([[PARAM_0_:%.+]]: tensor<1x384x768xf32>, [[PARAM_1_:%.+]]: tensor<768xf32>) -> tensor<1x384x768xf32> {
263+
// CHECK: [[VAR_0_:%.+]] = "onnx.NoValue"() {value} : () -> none
264+
// CHECK: [[VAR_Y_:%.+]], [[VAR_InvStdDev_:%.+]] = "onnx.RMSLayerNormalization"([[PARAM_0_]], [[PARAM_1_]], [[VAR_0_]]) {axis = 2 : si64, epsilon = 9.99999974E-6 : f32, stash_type = 1 : si64} : (tensor<1x384x768xf32>, tensor<768xf32>, none) -> (tensor<1x384x768xf32>, none)
265+
// CHECK: [[VAR_1_:%.+]] = "onnx.Add"([[VAR_Y_]], [[VAR_Y_]]) : (tensor<1x384x768xf32>, tensor<1x384x768xf32>) -> tensor<1x384x768xf32>
266+
// CHECK: return [[VAR_1_]] : tensor<1x384x768xf32>
267+
// CHECK: }
268+
}
269+
270+
// -----
271+
250272
// COM: QLinearMatMul
251273
func.func @qlinear_matmul(%arg0: tensor<?x?x768xi8>, %arg1: tensor<f32>, %arg2: tensor<i8>, %arg3: tensor<768x768xi8>, %arg4: tensor<f32>, %arg5: tensor<i8>, %arg6: tensor<f32>, %arg7: tensor<i8>) -> (tensor<?x?x768xi8>) {
252274
%0 = "onnx.DequantizeLinear"(%arg0, %arg1, %arg2) {axis = 1 : si64} : (tensor<?x?x768xi8>, tensor<f32>, tensor<i8>) -> tensor<?x?x768xf32>

0 commit comments

Comments
 (0)