From 6f326467592d282a67e289bb2a2c9ef9c3755a70 Mon Sep 17 00:00:00 2001 From: Tom Allsop Date: Thu, 2 Feb 2023 15:38:32 +0000 Subject: Simplified unit tests to make them more robust Change-Id: I6f5fd4c695aba8cbf0d7dadf259649ed4924a76e --- tests/test_tosa_checker.py | 64 +++------------------------------------------- 1 file 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 {tf_saved_model.index_path = ["nms_1"]}, tensor {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} : () -> tensor - %9 = "tfl.pseudo_const"() {value = dense<5.000000e-01> : tensor} : () -> tensor - %10 = "tfl.pseudo_const"() {value = dense<1.000000e-01> : tensor} : () -> tensor - %11 = "tfl.pseudo_const"() {value = dense<1.000000e+00> : tensor} : () -> tensor - %selected_indices, %selected_scores, %valid_outputs = "tfl.non_max_suppression_v5"(%3, %7, %8, %9, %10, %11) : (tensor<6x4xf32>, tensor<6xf32>, tensor, tensor, tensor, tensor) -> (tensor, tensor, tensor<*xi32>) - return %selected_scores, %selected_indices : tensor, tensor - } -} -""" - 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 {tf_saved_model.index_path = ["nms_1"]}, tensor {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} : () -> tensor - %1 = "tosa.const"() {value = dense<5.000000e-01> : tensor} : () -> tensor - %2 = "tosa.const"() {value = dense<1.000000e-01> : tensor} : () -> tensor - %3 = "tosa.const"() {value = dense<1.000000e+00> : tensor} : () -> tensor - %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, tensor, tensor, tensor) -> (tensor, tensor, tensor<*xi32>) - return %selected_scores, %selected_indices : tensor, tensor - } -} -""" - 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 {tf_saved_model.index_path = ["input"]}) -> (tensor {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, tensor<8x16xf32>, none) -> tensor - return %2 : tensor - } -} -""" - 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 {tf_saved_model.index_path = ["input"]}) -> (tensor {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, tensor<8x16xf32>, tensor<8xf32>) -> tensor - %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) -> tensor - return %3 : tensor - } -} -""" - assert tosa_mlir_representation == expected_tosa_mlir_representation + assert "fully_connected" in tosa_mlir_representation \ No newline at end of file -- cgit v1.2.1