From ebe4eab98527a4a77284715241c1080d9ab894b4 Mon Sep 17 00:00:00 2001 From: liym27 <33742067+liym27@users.noreply.github.com> Date: Thu, 26 Mar 2020 01:03:20 +0800 Subject: [PATCH] fix bug of ListTransformer in dygraph_to_static. test=develop (#23153) --- .../fluid/dygraph/dygraph_to_static/list_transformer.py | 3 ++- .../fluid/tests/unittests/dygraph_to_static/test_list.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/list_transformer.py b/python/paddle/fluid/dygraph/dygraph_to_static/list_transformer.py index bb7b5e5e8bb..5579229ccd5 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/list_transformer.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/list_transformer.py @@ -196,6 +196,7 @@ class ListTransformer(gast.NodeTransformer): self.list_name_to_updated[target_id] = False self.list_nodes.add(node) return True - elif target_id in self.list_name_to_updated: + elif target_id in self.list_name_to_updated and \ + self.list_name_to_updated[target_id] == False: del self.list_name_to_updated[target_id] return False diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_list.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_list.py index 84dc9d2d904..588d900f316 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_list.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_list.py @@ -58,8 +58,8 @@ def test_list_in_for_loop_with_concat(x, iter_num): a = [] for i in range(iter_num): a.append(x) - out = fluid.layers.concat(a, axis=0) - return out + a = fluid.layers.concat(a, axis=0) + return a def test_list_in_while_loop(x, iter_num): -- GitLab