|
| 1 | +// RUN: onnx-mlir-opt --dqq-opt-onnx-to-onnx %s -split-input-file | FileCheck %s |
| 2 | + |
| 3 | +func.func @test_qdq_pattern1(%arg0: tensor<1x128x768xui16>) -> tensor<1x128x768xui16> { |
| 4 | +%0 = onnx.Constant dense<2.57987776E-5> : tensor<f32> |
| 5 | +%1 = onnx.Constant dense<39664> : tensor<ui16> |
| 6 | +%2 = "onnx.DequantizeLinear"(%arg0, %0, %1) {axis = 1 : si64, block_size = 0 : si64} : (tensor<1x128x768xui16>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xf32> |
| 7 | +%3 = "onnx.QuantizeLinear"(%2, %0, %1) {axis = 1 : si64, block_size = 0 : si64, output_dtype = 0 : si64, saturate = 1 : si64} : (tensor<1x128x768xf32>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xui16> |
| 8 | +return %3 : tensor<1x128x768xui16> |
| 9 | + |
| 10 | +} |
| 11 | + |
| 12 | +// CHECK-LABEL: func.func @test_qdq_pattern1(%arg0: tensor<1x128x768xui16>) -> tensor<1x128x768xui16> |
| 13 | +// CHECK: return %arg0 : tensor<1x128x768xui16> |
| 14 | +// CHECK-NOT: onnx.DequantizeLinear |
| 15 | +// CHECK-NOT: onnx.QuantizeLinear |
| 16 | + |
| 17 | +func.func @test_qdq_pattern2(%arg0: tensor<1x128x768xui16>) -> tensor<1x128x768xui16> { |
| 18 | +%0 = onnx.Constant dense<2.57987776E-5> : tensor<f32> |
| 19 | +%1 = onnx.Constant dense<39664> : tensor<ui16> |
| 20 | +%2 = onnx.Constant dense<6.57987776E-5> : tensor<f32> |
| 21 | +%3 = onnx.Constant dense<45664> : tensor<ui16> |
| 22 | +%4 = "onnx.DequantizeLinear"(%arg0, %0, %1) {axis = 1 : si64, block_size = 0 : si64} : (tensor<1x128x768xui16>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xf32> |
| 23 | +%5 = "onnx.QuantizeLinear"(%4, %2, %3) {axis = 1 : si64, block_size = 0 : si64, output_dtype = 0 : si64, saturate = 1 : si64} : (tensor<1x128x768xf32>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xui16> |
| 24 | +return %5 : tensor<1x128x768xui16> |
| 25 | +} |
| 26 | + |
| 27 | +// CHECK-LABEL: func.func @test_qdq_pattern2(%arg0: tensor<1x128x768xui16>) -> tensor<1x128x768xui16> |
| 28 | +// CHECK: onnx.DequantizeLinear |
| 29 | +// CHECK: onnx.QuantizeLinear |
| 30 | + |
| 31 | +func.func @test_qdq_pattern3(%arg0: tensor<1x128x768xui16>) -> tensor<1x128x768xui16> { |
| 32 | +%0 = onnx.Constant dense<2.57987776E-5> : tensor<f32> |
| 33 | +%1 = onnx.Constant dense<39664> : tensor<ui16> |
| 34 | +%2 = "onnx.DequantizeLinear"(%arg0, %0, %1) {axis = 2 : si64, block_size = 0 : si64} : (tensor<1x128x768xui16>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xf32> |
| 35 | +%3 = "onnx.QuantizeLinear"(%2, %0, %1) {block_size = 0 : si64, output_dtype = 0 : si64, saturate = 1 : si64} : (tensor<1x128x768xf32>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xui16> |
| 36 | +return %3 : tensor<1x128x768xui16> |
| 37 | + |
| 38 | +} |
| 39 | + |
| 40 | +// CHECK-LABEL: func.func @test_qdq_pattern3(%arg0: tensor<1x128x768xui16>) -> tensor<1x128x768xui16> |
| 41 | +// CHECK: onnx.DequantizeLinear |
| 42 | +// CHECK: onnx.QuantizeLinear |
| 43 | + |
| 44 | +func.func @test_qdq_pattern4(%arg0: tensor<1x128x768xui16>) -> tensor<1x128x768xui16> { |
| 45 | +%0 = onnx.Constant dense<2.57987776E-5> : tensor<f32> |
| 46 | +%1 = onnx.Constant dense<39664> : tensor<ui16> |
| 47 | +%2 = "onnx.DequantizeLinear"(%arg0, %0, %1) {axis = 1 : si64, block_size = 1 : si64} : (tensor<1x128x768xui16>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xf32> |
| 48 | +%3 = "onnx.QuantizeLinear"(%2, %0, %1) {axis = 1 : si64, output_dtype = 0 : si64, saturate = 1 : si64} : (tensor<1x128x768xf32>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xui16> |
| 49 | +return %3 : tensor<1x128x768xui16> |
| 50 | + |
| 51 | +} |
| 52 | + |
| 53 | +// CHECK-LABEL: func.func @test_qdq_pattern4(%arg0: tensor<1x128x768xui16>) -> tensor<1x128x768xui16> |
| 54 | +// CHECK: onnx.DequantizeLinear |
| 55 | +// CHECK: onnx.QuantizeLinear |
| 56 | + |
| 57 | +func.func @test_qdq_pattern6(%arg0: tensor<1x128x768xui16>, %arg1: tensor<f32>) -> tensor<1x128x768xui16> { |
| 58 | +%0 = onnx.Constant dense<39664> : tensor<ui16> |
| 59 | +%1 = "onnx.DequantizeLinear"(%arg0, %arg1, %0) {axis = 1 : si64, block_size = 0 : si64} : (tensor<1x128x768xui16>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xf32> |
| 60 | +%2 = "onnx.QuantizeLinear"(%1, %arg1, %0) {axis = 1 : si64, block_size = 0 : si64, output_dtype = 0 : si64, saturate = 1 : si64} : (tensor<1x128x768xf32>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xui16> |
| 61 | +return %2 : tensor<1x128x768xui16> |
| 62 | +} |
| 63 | + |
| 64 | +// CHECK-LABEL: func.func @test_qdq_pattern6(%arg0: tensor<1x128x768xui16>, %arg1: tensor<f32>) -> tensor<1x128x768xui16> |
| 65 | +// CHECK: onnx.DequantizeLinear |
| 66 | +// CHECK: onnx.QuantizeLinear |
| 67 | + |
| 68 | +func.func @test_qdq_pattern7(%arg0: tensor<1x128x768xui16>, %arg1: tensor<ui16>) -> tensor<1x128x768xui16> { |
| 69 | +%0 = onnx.Constant dense<2.57987776E-5> : tensor<f32> |
| 70 | +%1 = "onnx.DequantizeLinear"(%arg0, %0, %arg1) {axis = 1 : si64, block_size = 0 : si64} : (tensor<1x128x768xui16>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xf32> |
| 71 | +%2 = "onnx.QuantizeLinear"(%1, %0, %arg1) {axis = 1 : si64, block_size = 0 : si64, output_dtype = 0 : si64, saturate = 1 : si64} : (tensor<1x128x768xf32>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xui16> |
| 72 | +return %2 : tensor<1x128x768xui16> |
| 73 | +} |
| 74 | + |
| 75 | +// CHECK-LABEL: func.func @test_qdq_pattern7(%arg0: tensor<1x128x768xui16>, %arg1: tensor<ui16>) -> tensor<1x128x768xui16> |
| 76 | +// CHECK: onnx.DequantizeLinear |
| 77 | +// CHECK: onnx.QuantizeLinear |
| 78 | + |
| 79 | +func.func @test_qdq_pattern8(%arg0: tensor<1x128x768xi16>) -> tensor<1x128x768xui16> { |
| 80 | +%0 = onnx.Constant dense<2.57987776E-5> : tensor<f32> |
| 81 | +%1 = onnx.Constant dense<39664> : tensor<ui16> |
| 82 | +%2 = "onnx.DequantizeLinear"(%arg0, %0, %1) {axis = 1 : si64, block_size = 0 : si64} : (tensor<1x128x768xi16>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xf32> |
| 83 | +%3 = "onnx.QuantizeLinear"(%2, %0, %1) {axis = 1 : si64, block_size = 0 : si64, output_dtype = 0 : si64, saturate = 1 : si64} : (tensor<1x128x768xf32>, tensor<f32>, tensor<ui16>) -> tensor<1x128x768xui16> |
| 84 | +return %3 : tensor<1x128x768xui16> |
| 85 | +} |
| 86 | + |
| 87 | +// CHECK-LABEL: func.func @test_qdq_pattern8(%arg0: tensor<1x128x768xi16>) -> tensor<1x128x768xui16> |
| 88 | +// CHECK: onnx.DequantizeLinear |
| 89 | +// CHECK: onnx.QuantizeLinear |
0 commit comments