From a546b663c155300cc69902679b11231c7d0b6b62 Mon Sep 17 00:00:00 2001 From: Guo Sheng Date: Fri, 20 Sep 2019 19:24:04 +0800 Subject: [PATCH] Fix transformer inference when using ParallelExecutor by setting ExecutionStrategy to clear tensor array after each iteration. (#3374) --- PaddleNLP/neural_machine_translation/transformer/predict.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PaddleNLP/neural_machine_translation/transformer/predict.py b/PaddleNLP/neural_machine_translation/transformer/predict.py index 9a1a4691..d896517f 100644 --- a/PaddleNLP/neural_machine_translation/transformer/predict.py +++ b/PaddleNLP/neural_machine_translation/transformer/predict.py @@ -176,7 +176,11 @@ def do_predict(args): pos_enc_param.set( position_encoding_init(args.max_length + 1, args.d_model), place) - compiled_test_prog = fluid.CompiledProgram(test_prog) + exe_strategy = fluid.ExecutionStrategy() + # to clear tensor array after each iteration + exe_strategy.num_iteration_per_drop_scope = 1 + compiled_test_prog = fluid.CompiledProgram(test_prog).with_data_parallel( + exec_strategy=exe_strategy, places=place) f = open(args.output_file, "wb") # start predicting -- GitLab