From af63b1184cc1ed32c14d972cf91a7d55a99f54b6 Mon Sep 17 00:00:00 2001 From: Jiabin Yang Date: Mon, 5 Aug 2019 20:43:34 +0800 Subject: [PATCH] test=develop, fix memory leak in dygraph (#18998) --- python/paddle/fluid/framework.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/python/paddle/fluid/framework.py b/python/paddle/fluid/framework.py index 0bf0e7c3e91..d899363cbae 100644 --- a/python/paddle/fluid/framework.py +++ b/python/paddle/fluid/framework.py @@ -272,11 +272,15 @@ def name_scope(prefix=None): g = f - 1 """ # TODO(panyx0718): Only [0-9a-z]. - assert prefix, "namescope prefix cannot be empty." - global _name_scope - _name_scope = _name_scope.child(prefix) - yield - _name_scope = _name_scope.parent() + # in dygraph we don't need namescope since it will cause mem leak + if not in_dygraph_mode(): + assert prefix, "namescope prefix cannot be empty." + global _name_scope + _name_scope = _name_scope.child(prefix) + yield + _name_scope = _name_scope.parent() + else: + yield def _full_name_scope(): -- GitLab