From 1b7a9cda1d79335d382936fac44587044f43029a Mon Sep 17 00:00:00 2001 From: WWWw <109729945+initialencounter@users.noreply.github.com> Date: Fri, 1 Nov 2024 13:51:47 +0800 Subject: [PATCH 1/2] Update benchmark --- tests/test_benchmark.py | 49 +++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index 0f83fcd..cd16896 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -50,6 +50,20 @@ def transform_and_check(self, name, filename, transformation_func, suffix, check return summarize_model(output_file, suffix) return None + def run_model_test(self, name, filename, check_func=None): + summary_list = [summarize_model(filename)] + summary_list.append(self.transform_and_check(name, filename, bench_onnxslim, "onnxslim", check_func)) + summary_list.append(self.transform_and_check(name, filename, bench_onnxsim, "onnxsim", check_func)) + summary_list.append( + self.transform_and_check(name, filename, bench_polygraphy, "polygraphy", check_func) + ) + + summary_list = [summary for summary in summary_list if summary is not None] + + print() + print_model_info_as_table(name, summary_list) + + def test_silero_vad(self, request): def check_model_inference(model_path): batch_size = 2 @@ -63,18 +77,35 @@ def check_model_inference(model_path): name = request.node.originalname[len("test_") :] filename = f"{MODELZOO_PATH}/{name}/{name}.onnx" + self.run_model_test(name, filename, check_model_inference) - summary_list = [summarize_model(filename)] - summary_list.append(self.transform_and_check(name, filename, bench_onnxslim, "onnxslim", check_model_inference)) - summary_list.append(self.transform_and_check(name, filename, bench_onnxsim, "onnxsim", check_model_inference)) - summary_list.append( - self.transform_and_check(name, filename, bench_polygraphy, "polygraphy", check_model_inference) - ) + def test_decoder_with_past_model(self, request): + def check_model_inference(model_path): + batch_size = 2 + input_ids = np.ones((batch_size, 256), dtype=np.int64) + encoder_hidden_states = np.zeros((batch_size, 128, 16), dtype=np.float32) - summary_list = [summary for summary in summary_list if summary is not None] + ort_sess = ort.InferenceSession(model_path) + outputs = ort_sess.run(None, {"input_ids": input_ids, "encoder_hidden_states": encoder_hidden_states}) - print() - print_model_info_as_table(request.node.name, summary_list) + name = request.node.originalname[len("test_") :] + filename = f"{MODELZOO_PATH}/{name}/{name}.onnx" + self.run_model_test(name, filename, check_model_inference) + + def test_tiny_en_decoder(self, request): + name = request.node.originalname[len("test_") :] + filename = f"{MODELZOO_PATH}/{name}/{name}.onnx" + self.run_model_test(name, filename) + + def test_transformer_encoder(self, request): + name = request.node.originalname[len("test_") :] + filename = f"{MODELZOO_PATH}/{name}/{name}.onnx" + self.run_model_test(name, filename) + + def test_uiex(self, request): + name = request.node.originalname[len("test_") :] + filename = f"{MODELZOO_PATH}/{name}/{name}.onnx" + self.run_model_test(name, filename) if __name__ == "__main__": From a8c57173b68f6b0b85c288efe67b27e63c3addf8 Mon Sep 17 00:00:00 2001 From: UltralyticsAssistant Date: Fri, 1 Nov 2024 05:52:21 +0000 Subject: [PATCH 2/2] Auto-format by https://ultralytics.com/actions --- tests/test_benchmark.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index cd16896..38c13a0 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -54,16 +54,13 @@ def run_model_test(self, name, filename, check_func=None): summary_list = [summarize_model(filename)] summary_list.append(self.transform_and_check(name, filename, bench_onnxslim, "onnxslim", check_func)) summary_list.append(self.transform_and_check(name, filename, bench_onnxsim, "onnxsim", check_func)) - summary_list.append( - self.transform_and_check(name, filename, bench_polygraphy, "polygraphy", check_func) - ) + summary_list.append(self.transform_and_check(name, filename, bench_polygraphy, "polygraphy", check_func)) summary_list = [summary for summary in summary_list if summary is not None] print() print_model_info_as_table(name, summary_list) - def test_silero_vad(self, request): def check_model_inference(model_path): batch_size = 2 @@ -86,7 +83,7 @@ def check_model_inference(model_path): encoder_hidden_states = np.zeros((batch_size, 128, 16), dtype=np.float32) ort_sess = ort.InferenceSession(model_path) - outputs = ort_sess.run(None, {"input_ids": input_ids, "encoder_hidden_states": encoder_hidden_states}) + ort_sess.run(None, {"input_ids": input_ids, "encoder_hidden_states": encoder_hidden_states}) name = request.node.originalname[len("test_") :] filename = f"{MODELZOO_PATH}/{name}/{name}.onnx"