From bd878826519bd2b15e7ba4cf0d61da2a39ac5ad3 Mon Sep 17 00:00:00 2001 From: typhoonzero Date: Wed, 28 Feb 2018 13:42:57 +0800 Subject: [PATCH] fix rename_var deref --- python/paddle/fluid/framework.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/python/paddle/fluid/framework.py b/python/paddle/fluid/framework.py index 64441e8fa49..9a691385916 100644 --- a/python/paddle/fluid/framework.py +++ b/python/paddle/fluid/framework.py @@ -747,13 +747,8 @@ class Block(object): if not self.has_var(name): raise ValueError("var %s is not in current" % name) v = self.var(name) - stop_gradient = None - trainable = None - optimize_attr = None - regularizer = None - gradient_clip_attr = None - error_clip = None if type(v) == Parameter: + var_type = "Parameter" stop_gradient = v.stop_gradient trainable = v.trainable optimize_attr = v.optimize_attr @@ -761,6 +756,7 @@ class Block(object): gradient_clip_attr = v.gradient_clip_attr error_clip = v.error_clip elif type(v) == Variable: + var_type = "Variable" error_clip = v.error_clip stop_gradient = v.stop_gradient else: @@ -768,8 +764,7 @@ class Block(object): self.desc.rename_var(name, new_name) d = self.desc.find_var(new_name) - var = None - if type(v) == Parameter: + if var_type == "Parameter": var = Parameter( self, d.shape(), @@ -781,7 +776,7 @@ class Block(object): regularizer=regularizer, gradient_clip_attr=gradient_clip_attr, error_clip=error_clip) - elif type(v) == Variable: + elif var_type == "Variable": var = Variable( self, name=new_name, -- GitLab