From 9556c688df2afbd9def788edddefd3e441ca3062 Mon Sep 17 00:00:00 2001 From: Charles-hit <56987902+Charles-hit@users.noreply.github.com> Date: Fri, 19 Aug 2022 10:24:16 +0800 Subject: [PATCH] fix some auto code generation bugs (#45232) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复生成动态图代码时,如果输出没有配置名字,会导致下标越界的问题。 * decide forward_return[0] is not none * 修改反向yaml前向输出只有一个时,未配置名字,那么输出自动生成为out * modify code style --- .../final_state_generator/codegen_utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/eager/auto_code_generator/final_state_generator/codegen_utils.py b/paddle/fluid/eager/auto_code_generator/final_state_generator/codegen_utils.py index 29049bff90d..64f2602c441 100644 --- a/paddle/fluid/eager/auto_code_generator/final_state_generator/codegen_utils.py +++ b/paddle/fluid/eager/auto_code_generator/final_state_generator/codegen_utils.py @@ -446,7 +446,13 @@ class FunctionGeneratorBase: for i in range(len(forward_returns_list)): forward_return = forward_returns_list[i] - return_name = forward_return[0] + if len(forward_return[0]) == 0: + if (len(forward_returns_list) == 1): + return_name = "out" + else: + return_name = "out_{}".format(i + 1) + else: + return_name = forward_return[0] return_type = forward_return[1] return_pos = forward_return[2] -- GitLab