aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Allsop <tom.allsop@arm.com>2023-02-02 15:38:32 +0000
committerTom Allsop <tom.allsop@arm.com>2023-02-02 15:38:32 +0000
commit6f326467592d282a67e289bb2a2c9ef9c3755a70 (patch)
tree5c23bf37bac39180d60b06c336dacf21c484b6ad
parentb0b58d61adb32e6fb3704c60655b3a1a9d5d9afd (diff)
downloadtosa_checker-6f326467592d282a67e289bb2a2c9ef9c3755a70.tar.gz
Simplified unit tests to make them more robust
Change-Id: I6f5fd4c695aba8cbf0d7dadf259649ed4924a76e
-rw-r--r--tests/test_tosa_checker.py64
1 files changed, 4 insertions, 60 deletions
diff --git a/tests/test_tosa_checker.py b/tests/test_tosa_checker.py
index 52378ee..c5955f5 100644
--- a/tests/test_tosa_checker.py
+++ b/tests/test_tosa_checker.py
@@ -199,77 +199,21 @@ class TestTosaCompatibilityTool:
tfl_mlir_representation = checker._get_mlir_model_representation(
elide_large_elements_attrs=True
)
- # TODO Use regular expression to make the test more robust or parse the MLIR module
- expected_mlir_representation = """\
-module attributes {tf_saved_model.semantics, tfl.description = "MLIR Converted.", tfl.schema_version = 3 : i32} {
- func @main(%arg0: tensor<1x6x4xf32> {tf_saved_model.index_path = ["boxes"]}, %arg1: tensor<1x6xf32> {tf_saved_model.index_path = ["scores"]}) -> (tensor<?xf32> {tf_saved_model.index_path = ["nms_1"]}, tensor<?xi32> {tf_saved_model.index_path = ["nms"]}) attributes {tf.entry_function = {inputs = "serving_default_boxes:0,serving_default_scores:0", outputs = "PartitionedCall:1,PartitionedCall:0"}, tf_saved_model.exported_names = ["serving_default"]} {
- %0 = "tfl.pseudo_const"() {value = dense<0> : tensor<3xi32>} : () -> tensor<3xi32>
- %1 = "tfl.pseudo_const"() {value = dense<[1, 6, 4]> : tensor<3xi32>} : () -> tensor<3xi32>
- %2 = "tfl.pseudo_const"() {value = dense<1> : tensor<3xi32>} : () -> tensor<3xi32>
- %3 = "tfl.strided_slice"(%arg0, %0, %1, %2) {begin_mask = 6 : i32, ellipsis_mask = 0 : i32, end_mask = 6 : i32, new_axis_mask = 0 : i32, shrink_axis_mask = 1 : i32} : (tensor<1x6x4xf32>, tensor<3xi32>, tensor<3xi32>, tensor<3xi32>) -> tensor<6x4xf32>
- %4 = "tfl.pseudo_const"() {value = dense<0> : tensor<2xi32>} : () -> tensor<2xi32>
- %5 = "tfl.pseudo_const"() {value = dense<[1, 6]> : tensor<2xi32>} : () -> tensor<2xi32>
- %6 = "tfl.pseudo_const"() {value = dense<1> : tensor<2xi32>} : () -> tensor<2xi32>
- %7 = "tfl.strided_slice"(%arg1, %4, %5, %6) {begin_mask = 2 : i32, ellipsis_mask = 0 : i32, end_mask = 2 : i32, new_axis_mask = 0 : i32, shrink_axis_mask = 1 : i32} : (tensor<1x6xf32>, tensor<2xi32>, tensor<2xi32>, tensor<2xi32>) -> tensor<6xf32>
- %8 = "tfl.pseudo_const"() {value = dense<5> : tensor<i32>} : () -> tensor<i32>
- %9 = "tfl.pseudo_const"() {value = dense<5.000000e-01> : tensor<f32>} : () -> tensor<f32>
- %10 = "tfl.pseudo_const"() {value = dense<1.000000e-01> : tensor<f32>} : () -> tensor<f32>
- %11 = "tfl.pseudo_const"() {value = dense<1.000000e+00> : tensor<f32>} : () -> tensor<f32>
- %selected_indices, %selected_scores, %valid_outputs = "tfl.non_max_suppression_v5"(%3, %7, %8, %9, %10, %11) : (tensor<6x4xf32>, tensor<6xf32>, tensor<i32>, tensor<f32>, tensor<f32>, tensor<f32>) -> (tensor<?xi32>, tensor<?xf32>, tensor<*xi32>)
- return %selected_scores, %selected_indices : tensor<?xf32>, tensor<?xi32>
- }
-}
-"""
- assert tfl_mlir_representation == expected_mlir_representation
+ assert "non_max_suppression_v5" in tfl_mlir_representation
tosa_mlir_representation = checker._get_mlir_tosa_model_representation(
elide_large_elements_attrs=True
)
- expected_tosa_mlir_representation = """\
-module attributes {tf_saved_model.semantics, tfl.description = "MLIR Converted.", tfl.schema_version = 3 : i32} {
- func @main(%arg0: tensor<1x6x4xf32> {tf_saved_model.index_path = ["boxes"]}, %arg1: tensor<1x6xf32> {tf_saved_model.index_path = ["scores"]}) -> (tensor<?xf32> {tf_saved_model.index_path = ["nms_1"]}, tensor<?xi32> {tf_saved_model.index_path = ["nms"]}) attributes {tf.entry_function = {inputs = "serving_default_boxes:0,serving_default_scores:0", outputs = "PartitionedCall:1,PartitionedCall:0"}, tf_saved_model.exported_names = ["serving_default"]} {
- %0 = "tosa.const"() {value = dense<5> : tensor<i32>} : () -> tensor<i32>
- %1 = "tosa.const"() {value = dense<5.000000e-01> : tensor<f32>} : () -> tensor<f32>
- %2 = "tosa.const"() {value = dense<1.000000e-01> : tensor<f32>} : () -> tensor<f32>
- %3 = "tosa.const"() {value = dense<1.000000e+00> : tensor<f32>} : () -> tensor<f32>
- %4 = "tosa.reshape"(%arg0) {new_shape = [6, 4]} : (tensor<1x6x4xf32>) -> tensor<6x4xf32>
- %5 = "tosa.reshape"(%arg1) {new_shape = [6]} : (tensor<1x6xf32>) -> tensor<6xf32>
- %selected_indices, %selected_scores, %valid_outputs = "tfl.non_max_suppression_v5"(%4, %5, %0, %1, %2, %3) : (tensor<6x4xf32>, tensor<6xf32>, tensor<i32>, tensor<f32>, tensor<f32>, tensor<f32>) -> (tensor<?xi32>, tensor<?xf32>, tensor<*xi32>)
- return %selected_scores, %selected_indices : tensor<?xf32>, tensor<?xi32>
- }
-}
-"""
- assert tosa_mlir_representation == expected_tosa_mlir_representation
+ assert "non_max_suppression_v5" in tosa_mlir_representation
def test_tosa_compat_model_mlir_representation(self, compat_file):
checker = tosa_checker.TOSAChecker(model_path=compat_file)
tfl_mlir_representation = checker._get_mlir_model_representation(
elide_large_elements_attrs=True
)
- expected_mlir_representation = """\
-module attributes {tf_saved_model.semantics, tfl.description = "MLIR Converted.", tfl.schema_version = 3 : i32} {
- func @main(%arg0: tensor<?x16xf32> {tf_saved_model.index_path = ["input"]}) -> (tensor<?x8xf32> {tf_saved_model.index_path = ["dense"]}) attributes {tf.entry_function = {inputs = "serving_default_input:0", outputs = "StatefulPartitionedCall:0"}, tf_saved_model.exported_names = ["serving_default"]} {
- %0 = "tfl.pseudo_const"() {value = opaque<"elided_large_const", "0xDEADBEEF"> : tensor<8x16xf32>} : () -> tensor<8x16xf32>
- %1 = "tfl.no_value"() {value} : () -> none
- %2 = "tfl.fully_connected"(%arg0, %0, %1) {asymmetric_quantize_inputs = false, fused_activation_function = "RELU", keep_num_dims = false, weights_format = "DEFAULT"} : (tensor<?x16xf32>, tensor<8x16xf32>, none) -> tensor<?x8xf32>
- return %2 : tensor<?x8xf32>
- }
-}
-"""
- assert tfl_mlir_representation == expected_mlir_representation
+ assert "fully_connected" in tfl_mlir_representation
tosa_mlir_representation = checker._get_mlir_tosa_model_representation(
elide_large_elements_attrs=True
)
- expected_tosa_mlir_representation = """\
-module attributes {tf_saved_model.semantics, tfl.description = "MLIR Converted.", tfl.schema_version = 3 : i32} {
- func @main(%arg0: tensor<?x16xf32> {tf_saved_model.index_path = ["input"]}) -> (tensor<?x8xf32> {tf_saved_model.index_path = ["dense"]}) attributes {tf.entry_function = {inputs = "serving_default_input:0", outputs = "StatefulPartitionedCall:0"}, tf_saved_model.exported_names = ["serving_default"]} {
- %0 = "tosa.const"() {value = opaque<"elided_large_const", "0xDEADBEEF"> : tensor<8x16xf32>} : () -> tensor<8x16xf32>
- %1 = "tosa.const"() {value = dense<0.000000e+00> : tensor<8xf32>} : () -> tensor<8xf32>
- %2 = "tosa.fully_connected"(%arg0, %0, %1) : (tensor<?x16xf32>, tensor<8x16xf32>, tensor<8xf32>) -> tensor<?x8xf32>
- %3 = "tosa.clamp"(%2) {max_fp = 3.40282347E+38 : f32, max_int = 2147483647 : i64, min_fp = 0.000000e+00 : f32, min_int = 0 : i64} : (tensor<?x8xf32>) -> tensor<?x8xf32>
- return %3 : tensor<?x8xf32>
- }
-}
-"""
- assert tosa_mlir_representation == expected_tosa_mlir_representation
+ assert "fully_connected" in tosa_mlir_representation \ No newline at end of file