Skip to content

Commit d72d488

Browse files
committed
[mlir][quant] output spec verification check for quant.region
We can have validation test for quant.region having incompatible output spec. Reviewed By: stellaraccident Differential Revision: https://reviews.llvm.org/D128245
1 parent 4710e78 commit d72d488

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

mlir/test/Dialect/Quant/quant_region.mlir

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,36 @@ func.func @unmatched_primitive(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>, %arg2
7070

7171
// -----
7272

73+
func.func @unmatched_quantize(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>, %arg2: tensor<4xf32>) -> (tensor<4xf32>) {
74+
// @expected-error @+1 {{'quant.region' op has incompatible specification !quant.uniform<i32:f16, 4.000000e+00> and output type 'tensor<4xf32>'}}
75+
%0 = "quant.region"(%arg0, %arg1, %arg2) ({
76+
^bb0(%10: tensor<4xf32>, %11: tensor<4xf32>, %12: tensor<4xf32>):
77+
%13 = "foo"(%10, %11) : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32>
78+
%14 = "bar"(%13, %12) : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32>
79+
"quant.return"(%14) : (tensor<4xf32>) -> ()
80+
}) {input_specs = [!quant.uniform<i8:f32, 1.0>, !quant.uniform<i8:f32, 2.0>, !quant.uniform<i8:f32, 3.0>],
81+
output_specs = [!quant.uniform<i32:f16, 4.0>], logical_kernel = "xyz"}
82+
: (tensor<4xf32>, tensor<4xf32>, tensor<4xf32>) -> (tensor<4xf32>)
83+
return %0 : tensor<4xf32>
84+
}
85+
86+
// -----
87+
88+
func.func @unmatched_primitive(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>, %arg2: tensor<4xf32>) -> (tensor<4xf32>) {
89+
// @expected-error @+1 {{'quant.region' op has incompatible specification i32 and output type 'tensor<4xf32>'}}
90+
%0 = "quant.region"(%arg0, %arg1, %arg2) ({
91+
^bb0(%10: tensor<4xf32>, %11: tensor<4xf32>, %12: tensor<4xf32>):
92+
%13 = "foo"(%10, %11) : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32>
93+
%14 = "bar"(%13, %12) : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32>
94+
"quant.return"(%14) : (tensor<4xf32>) -> ()
95+
}) {input_specs = [!quant.uniform<i8:f32, 1.0>, !quant.uniform<i8:f32, 2.0>, !quant.uniform<i32:f32, 2.0>],
96+
output_specs = [i32], logical_kernel = "xyz"}
97+
: (tensor<4xf32>, tensor<4xf32>, tensor<4xf32>) -> (tensor<4xf32>)
98+
return %0 : tensor<4xf32>
99+
}
100+
101+
// -----
102+
73103
func.func @unmatched_number(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>, %arg2: tensor<4xf32>) -> (tensor<4xf32>) {
74104
// @expected-error @+1 {{'quant.region' op has unmatched operands/results number and spec attributes number}}
75105
%0 = "quant.region"(%arg0, %arg1, %arg2) ({

0 commit comments

Comments
 (0)