Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Dialect/ONNX/ONNXOps/Quantize/DequantizeLinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ LogicalResult ONNXDequantizeLinearOpShapeHelper::computeShape() {
}

// Get values.
// Save the final result.
setOutputDims(outputDims);
// Store inferred output dims; skip refineDims so Y is not overwritten by
// stale static types on Y.
setOutputDims(outputDims, /*n=*/0, /*refineShape=*/false);
return success();
}

Expand Down
24 changes: 6 additions & 18 deletions test/mlir/conversion/onnx_to_tosa/NN/DequantizeLinear.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,9 @@ func.func @dynamic(%arg0 : tensor<?xi8>, %arg1 : tensor<f32>, %arg2 : tensor<i8>
}

// CHECK-LABEL: func.func @dynamic
// CHECK-SAME: ([[PARAM_0_:%.+]]: tensor<?xi8>, [[PARAM_1_:%.+]]: tensor<f32>, [[PARAM_2_:%.+]]: tensor<i8>) -> tensor<1xf32> {
// CHECK-DAG: [[VAR_0_:%.+]] = tosa.cast [[PARAM_0_]] : (tensor<?xi8>) -> tensor<?xf32>
// CHECK-DAG: [[VAR_1_:%.+]] = tosa.reshape [[PARAM_2_]] {new_shape = array<i64: 1>} : (tensor<i8>) -> tensor<1xi8>
// CHECK: [[VAR_2_:%.+]] = tosa.cast [[VAR_1_]] : (tensor<1xi8>) -> tensor<1xf32>
// CHECK-DAG: [[VAR_3_:%.+]] = tosa.sub [[VAR_0_]], [[VAR_2_]] : (tensor<?xf32>, tensor<1xf32>) -> tensor<?xf32>
// CHECK-DAG: [[VAR_4_:%.+]] = tosa.reshape [[PARAM_1_]] {new_shape = array<i64: 1>} : (tensor<f32>) -> tensor<1xf32>
// CHECK-DAG: [[VAR_5_:%.+]] = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
// CHECK: [[VAR_6_:%.+]] = tosa.mul [[VAR_3_]], [[VAR_4_]], [[VAR_5_]] : (tensor<?xf32>, tensor<1xf32>, tensor<1xi8>) -> tensor<1xf32>
// CHECK: return [[VAR_6_]] : tensor<1xf32>
// CHECK-SAME: ([[PARAM_0_:%.+]]: tensor<?xi8>, [[PARAM_1_:%.+]]: tensor<f32>, [[PARAM_2_:%.+]]: tensor<i8>) -> tensor<?xf32> {
// CHECK: [[VAR_0_:%.+]] = "onnx.DequantizeLinear"([[PARAM_0_]], [[PARAM_1_]], [[PARAM_2_]]) {{.*}} : (tensor<?xi8>, tensor<f32>, tensor<i8>) -> tensor<?xf32>
// CHECK: return [[VAR_0_]] : tensor<?xf32>
// CHECK: }
// -----

Expand Down Expand Up @@ -153,15 +147,9 @@ func.func @dynamic3(%arg0 : tensor<2x?xi8>, %arg1 : tensor<f32>, %arg2 : tensor<
}

// CHECK-LABEL: func.func @dynamic3
// CHECK-SAME: ([[PARAM_0_:%.+]]: tensor<2x?xi8>, [[PARAM_1_:%.+]]: tensor<f32>, [[PARAM_2_:%.+]]: tensor<i8>) -> tensor<2x1xf32> {
// CHECK-DAG: [[VAR_0_:%.+]] = tosa.cast [[PARAM_0_]] : (tensor<2x?xi8>) -> tensor<2x?xf32>
// CHECK-DAG: [[VAR_1_:%.+]] = tosa.reshape [[PARAM_2_]] {new_shape = array<i64: 1, 1>} : (tensor<i8>) -> tensor<1x1xi8>
// CHECK: [[VAR_2_:%.+]] = tosa.cast [[VAR_1_]] : (tensor<1x1xi8>) -> tensor<1x1xf32>
// CHECK-DAG: [[VAR_3_:%.+]] = tosa.sub [[VAR_0_]], [[VAR_2_]] : (tensor<2x?xf32>, tensor<1x1xf32>) -> tensor<2x?xf32>
// CHECK-DAG: [[VAR_4_:%.+]] = tosa.reshape [[PARAM_1_]] {new_shape = array<i64: 1, 1>} : (tensor<f32>) -> tensor<1x1xf32>
// CHECK-DAG: [[VAR_5_:%.+]] = "tosa.const"() <{value = dense<0> : tensor<1xi8>}> : () -> tensor<1xi8>
// CHECK: [[VAR_6_:%.+]] = tosa.mul [[VAR_3_]], [[VAR_4_]], [[VAR_5_]] : (tensor<2x?xf32>, tensor<1x1xf32>, tensor<1xi8>) -> tensor<2x1xf32>
// CHECK: return [[VAR_6_]] : tensor<2x1xf32>
// CHECK-SAME: ([[PARAM_0_:%.+]]: tensor<2x?xi8>, [[PARAM_1_:%.+]]: tensor<f32>, [[PARAM_2_:%.+]]: tensor<i8>) -> tensor<2x?xf32> {
// CHECK: [[VAR_0_:%.+]] = "onnx.DequantizeLinear"([[PARAM_0_]], [[PARAM_1_]], [[PARAM_2_]]) {{.*}} : (tensor<2x?xi8>, tensor<f32>, tensor<i8>) -> tensor<2x?xf32>
// CHECK: return [[VAR_0_]] : tensor<2x?xf32>
// CHECK: }
// -----

Expand Down
12 changes: 12 additions & 0 deletions test/mlir/onnx/onnx_shape_inference.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,18 @@ func.func @test_dequantize_linear_2(%arg0 : tensor<5x?x3x4xi8>, %arg1 : tensor<*

// -----

// COM: inferShapes derives Y's shape from X.
func.func @test_dequantize_linear_stale_output_batch(%arg0 : tensor<2x4x8xi8>, %arg1 : tensor<f32>, %arg2 : tensor<i8>) -> tensor<1x4x8xf32> {
%1 = "onnx.DequantizeLinear"(%arg0, %arg1, %arg2) {} : (tensor<2x4x8xi8>, tensor<f32>, tensor<i8>) -> tensor<1x4x8xf32>
"onnx.Return"(%1) {} : (tensor<1x4x8xf32>) -> ()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is'n the model here already broken? Not sure if we should try to support that


// CHECK-LABEL: test_dequantize_linear_stale_output_batch
// CHECK: [[RES:%.+]] = "onnx.DequantizeLinear"(%arg0, %arg1, %arg2) {axis = 1 : si64, block_size = 0 : si64} : (tensor<2x4x8xi8>, tensor<f32>, tensor<i8>) -> tensor<2x4x8xf32>
// CHECK: onnx.Return [[RES]] : tensor<2x4x8xf32>
}

// -----

//===----------------------------------------------------------------------===//
/// Test shape inference for ConvInteger operation and all its attributes.
//===----------------------------------------------------------------------===//
Expand Down
Loading