From c444b3f66a91fea98419310f0258c9fcc191c72d Mon Sep 17 00:00:00 2001 From: z30004183 Date: Thu, 31 Mar 2022 18:23:21 +0800 Subject: [PATCH 1/3] update test_num with bs --- .../bert_base_get_info.py | 12 ++++++++++-- .../bert_postprocess_data.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_base_get_info.py b/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_base_get_info.py index ce1b597ce2..875c8036e9 100644 --- a/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_base_get_info.py +++ b/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_base_get_info.py @@ -13,12 +13,20 @@ # limitations under the License. # ============================================================================ import os +import argparse + -test_num = 10649 base_path = './bert_bin/' +# three inputs in each eval +test_num = len(os.listdir(base_path)) +parser = argparse.ArgumentParser(description='manual to this script') +parser.add_argument('--batchsize', type=int, default=8) +args = parser.parse_args() +batchsize = args.batchsize +real_test = test_num // batchsize * batchsize with open('./bert_base_uncased.info', 'w') as f: - for i in range(test_num): + for i in range(real_test): ids_name = base_path + 'input_ids_{}.bin'.format(i) segment_name = base_path + 'segment_ids_{}.bin'.format(i) mask_name = base_path + 'input_mask_{}.bin'.format(i) diff --git a/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_postprocess_data.py b/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_postprocess_data.py index 11e0ada13c..715dd5d004 100644 --- a/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_postprocess_data.py +++ b/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_postprocess_data.py @@ -395,8 +395,8 @@ def main(): required=True, help="NPU benchmark infer result path") args = parser.parse_args() - test_num = 10649 npu_path = args.npu_result + test_num = len(os.listdir(npu_path)) // 2 tokenizer = BertTokenizer(args.vocab_file, do_lower_case=args.do_lower_case, max_len=512) # for bert large eval_examples = read_squad_examples( input_file=args.predict_file, is_training=False) -- Gitee From d91b54ea09b92163a004fa53e7894ee4d62e66af Mon Sep 17 00:00:00 2001 From: z30004183 Date: Thu, 31 Mar 2022 18:35:52 +0800 Subject: [PATCH 2/3] update test_num with bs --- .../nlp/Bert_Base_Uncased_for_Pytorch/bert_base_get_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_base_get_info.py b/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_base_get_info.py index 875c8036e9..3d9146da31 100644 --- a/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_base_get_info.py +++ b/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_base_get_info.py @@ -18,7 +18,7 @@ import argparse base_path = './bert_bin/' # three inputs in each eval -test_num = len(os.listdir(base_path)) +test_num = len(os.listdir(base_path)) // 3 parser = argparse.ArgumentParser(description='manual to this script') parser.add_argument('--batchsize', type=int, default=8) args = parser.parse_args() -- Gitee From 177370b03d706f89c3a8c246f295fd00a88eec4a Mon Sep 17 00:00:00 2001 From: z30004183 Date: Thu, 31 Mar 2022 19:00:16 +0800 Subject: [PATCH 3/3] update print --- .../Bert_Base_Uncased_for_Pytorch/bert_postprocess_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_postprocess_data.py b/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_postprocess_data.py index 715dd5d004..ebf52e30e9 100644 --- a/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_postprocess_data.py +++ b/ACL_PyTorch/built-in/nlp/Bert_Base_Uncased_for_Pytorch/bert_postprocess_data.py @@ -432,7 +432,6 @@ def main(): all_results.append(RawResult(unique_id=unique_id, start_logits=start_logits, end_logits=end_logits)) - print(" [INFO] i == ", i) time_to_infer = time.time() - infer_start output_prediction_file = os.path.join("./", "predictions.json") output_nbest_file = os.path.join("./", "nbest_predictions.json") @@ -442,7 +441,8 @@ def main(): f.write(json.dumps(answers, indent=4) + "\n") with open(output_nbest_file, "w") as f: f.write(json.dumps(nbest_answers, indent=4) + "\n") - + print("Completed") + if __name__ == '__main__': main() \ No newline at end of file -- Gitee