From 4ab2b9ec454a76e94ef32079a3cc4c5989a513dd Mon Sep 17 00:00:00 2001 From: pengaoao Date: Mon, 21 Mar 2022 12:19:28 +0800 Subject: [PATCH 1/5] add wenet perf script --- .../get_no_flash_encoder_out.diff | 2 +- .../built-in/audio/Wenet_for_Pytorch/getwer.diff | 2 +- .../process_encoder_data_noflash.py | 11 +++++++---- .../recognize_attenstion_rescoring.py | 16 ++++++++++++++-- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/get_no_flash_encoder_out.diff b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/get_no_flash_encoder_out.diff index 81924cf956..b209edb704 100644 --- a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/get_no_flash_encoder_out.diff +++ b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/get_no_flash_encoder_out.diff @@ -32,7 +32,7 @@ index 73990fa..e2f3555 100644 + y, exe_time = encoder_model_noflash( + [speech.numpy(), speech_lengths.numpy().astype("int32")]) # (beam_size, max_hyps_len, vocab_size) + encoder_out, encoder_mask = torch.from_numpy(y[0]), torch.from_numpy(y[1]) -+ return encoder_out, encoder_mask ++ return encoder_out, encoder_mask, exe_time def recognize( self, diff --git a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/getwer.diff b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/getwer.diff index a40643cc7a..633513671c 100644 --- a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/getwer.diff +++ b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/getwer.diff @@ -167,7 +167,7 @@ index 73990fa..82337ca 100644 + if score > best_score: + best_score = score + best_index = i -+ return hyps[best_index][0] ++ return hyps[best_index][0], exe_time + def attention_rescoring( self, diff --git a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/process_encoder_data_noflash.py b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/process_encoder_data_noflash.py index 9c92947c83..709d6f199d 100644 --- a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/process_encoder_data_noflash.py +++ b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/process_encoder_data_noflash.py @@ -174,7 +174,7 @@ if __name__ == '__main__': #init acl if os.path.exists(args.json_path): os.remove(args.json_path) - + total_t = 0 encoder_dic = {} import time for batch_idx, batch in enumerate(test_data_loader): @@ -185,7 +185,7 @@ if __name__ == '__main__': feats_lengths = feats_lengths.to(device) target_lengths = target_lengths.to(device) assert (feats.size(0) == 1) - encoder_out, encoder_mask = model.get_no_flash_encoder_out( + encoder_out, encoder_mask, exe_time = model.get_no_flash_encoder_out( encoder_model_noflash, batch_idx, feats, @@ -196,11 +196,14 @@ if __name__ == '__main__': ctc_weight=args.ctc_weight, simulate_streaming=args.simulate_streaming, reverse_weight=args.reverse_weight) - + total_t += exe_time encoder_dic["encoder_out_"+ str(batch_idx)] = [encoder_out.shape[0], encoder_out.shape[1],encoder_out.shape[2]] encoder_dic["encoder_mask_"+ str(batch_idx)] = [encoder_mask.shape[0], encoder_mask.shape[1],encoder_mask.shape[2]] encoder_out.numpy().tofile(os.path.join(args.bin_path, "encoder_out_{}.bin".format(batch_idx))) encoder_mask.numpy().tofile(os.path.join(args.bin_path, "encoder_mask_{}.bin".format(batch_idx))) - + ave_t = total_t / (batch_idx + 1) + dic_perf = {} + dic_perf["t1"] = ave_t + dic2json(dic_perf, "t1.json") dic2json(encoder_dic, args.json_path) diff --git a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/recognize_attenstion_rescoring.py b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/recognize_attenstion_rescoring.py index 37ce531b19..bdc02ad3a4 100644 --- a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/recognize_attenstion_rescoring.py +++ b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/recognize_attenstion_rescoring.py @@ -52,6 +52,12 @@ import acl from wenet.transformer.acl_net import Net import json import os + +def dic2json(input_dict, json_path): + json_str = json.dumps(input_dict) + with open(json_path, 'a') as json_file: + json_file.write(json_str) + if __name__ == '__main__': parser = argparse.ArgumentParser(description='recognize with your model') parser.add_argument('--config', required=True, help='config file') @@ -149,7 +155,7 @@ if __name__ == '__main__': model = model.to(device) model.eval() - + total_t = 0 #init acl ret = acl.init() device_id = 0 @@ -169,7 +175,7 @@ if __name__ == '__main__': feats_lengths = feats_lengths.to(device) target_lengths = target_lengths.to(device) assert (feats.size(0) == 1) - hyp = model.get_wer( + hyp, exe_time = model.get_wer( batch_idx, bin_path, json_data, @@ -182,6 +188,7 @@ if __name__ == '__main__': ctc_weight=args.ctc_weight, simulate_streaming=args.simulate_streaming, reverse_weight=args.reverse_weight) + total_t += exe_time hyps = [hyp] for i, key in enumerate(keys): content = '' @@ -191,3 +198,8 @@ if __name__ == '__main__': content += char_dict[w] logging.info('{} {}'.format(key, content)) fout.write('{} {}\n'.format(key, content)) + ave_t = total_t / (batch_idx + 1) + dic_perf = {} + dic_perf["t2"] = ave_t + if "no" in args.bin_path: + dic2json(dic_perf, "t2.json") -- Gitee From c55c07c93131b71e70411ee4a3c3ec25471340e7 Mon Sep 17 00:00:00 2001 From: pengaoao Date: Mon, 21 Mar 2022 14:26:06 +0800 Subject: [PATCH 2/5] fix --- ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/README.md b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/README.md index 9d2618ebf0..cd8295ceeb 100644 --- a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/README.md +++ b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/README.md @@ -102,7 +102,9 @@ python3 adaptnoflashencoder.py生成no_flash_encoder_revise.onnx | 模型 | 官网pth精度 | 710/310离线推理精度 | gpu性能 | 710性能 | 310性能 | | :---: | :----------------------------: | :-------------------------: | :-----: | :-----: | ------- | -| wenet | GPU流式:5.94%, 非流式:4.64% | 流式:5.66%, 非流式:5.66% | 66fps | 5.8fps | 11.6fps | +| wenet | GPU流式:5.94%, 非流式:4.64% | 流式:5.66%, 非流式:5.66% | 66fps | 7.69 | 11.6fps | + +生成的t1.json, t2.json文件中分别为encoder,decoder耗时,将其相加即可 静态shape场景(仅支持非流式场景): -- Gitee From fc0303c54505bb0e247111900d474bb0fa4dadc9 Mon Sep 17 00:00:00 2001 From: pengaoao Date: Mon, 21 Mar 2022 14:44:36 +0800 Subject: [PATCH 3/5] fix --- .../audio/Wenet_for_Pytorch/README.md | 2 +- .../audio/Wenet_for_Pytorch/infer_perf.py | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py diff --git a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/README.md b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/README.md index cd8295ceeb..e3d5cafbe8 100644 --- a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/README.md +++ b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/README.md @@ -104,7 +104,7 @@ python3 adaptnoflashencoder.py生成no_flash_encoder_revise.onnx | :---: | :----------------------------: | :-------------------------: | :-----: | :-----: | ------- | | wenet | GPU流式:5.94%, 非流式:4.64% | 流式:5.66%, 非流式:5.66% | 66fps | 7.69 | 11.6fps | -生成的t1.json, t2.json文件中分别为encoder,decoder耗时,将其相加即可 +生成的t1.json, t2.json文件中分别为encoder,decoder耗时,将其相加即可,运行python3.7.5 infer_perf.py 静态shape场景(仅支持非流式场景): diff --git a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py new file mode 100644 index 0000000000..0b38093d77 --- /dev/null +++ b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py @@ -0,0 +1,24 @@ +# Copyright (c) 2020 Mobvoi Inc. (authors: Binbin Zhang, Xiaoyu Chen, Di Wu) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import json +t1 = {} +with open("t1", 'r') as load_f: + t1 = json.load(load_f) + +t2 = {} +with open("t1", 'r') as load_f: + t2 = json.load(load_f) + +perf = t1["t1"] + t2["t2"] +print("perf") \ No newline at end of file -- Gitee From a6392ae358ddd4e615e30e02588048ac1483ccd2 Mon Sep 17 00:00:00 2001 From: pengaoao Date: Mon, 21 Mar 2022 14:52:28 +0800 Subject: [PATCH 4/5] fix --- ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py index 0b38093d77..c5d27f06ad 100644 --- a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py +++ b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py @@ -13,12 +13,12 @@ # limitations under the License. import json t1 = {} -with open("t1", 'r') as load_f: +with open("t1.json", 'r') as load_f: t1 = json.load(load_f) t2 = {} -with open("t1", 'r') as load_f: +with open("t2.json", 'r') as load_f: t2 = json.load(load_f) perf = t1["t1"] + t2["t2"] -print("perf") \ No newline at end of file +print("perf:", perf) \ No newline at end of file -- Gitee From 2f10dd40bacb3b50d999d265361caaf9cf4652bb Mon Sep 17 00:00:00 2001 From: pengaoao Date: Mon, 21 Mar 2022 14:56:17 +0800 Subject: [PATCH 5/5] fix --- ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py index c5d27f06ad..acff85e655 100644 --- a/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py +++ b/ACL_PyTorch/built-in/audio/Wenet_for_Pytorch/infer_perf.py @@ -21,4 +21,4 @@ with open("t2.json", 'r') as load_f: t2 = json.load(load_f) perf = t1["t1"] + t2["t2"] -print("perf:", perf) \ No newline at end of file +print("fps:", 1000 / perf) \ No newline at end of file -- Gitee