From 73e51a17e744bd2a04bfc1fe948e928870454e20 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Tue, 1 Dec 2020 16:47:07 +0800 Subject: [PATCH] add stop_gradient property and remove reduce redundant information (#29185) * add stop_gradient property and remove reduce redundant information * refine code --- python/paddle/fluid/framework.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/framework.py b/python/paddle/fluid/framework.py index 5e4f6394e12..662bc59255a 100644 --- a/python/paddle/fluid/framework.py +++ b/python/paddle/fluid/framework.py @@ -1313,12 +1313,15 @@ class Variable(object): dtype='float32') print(new_variable._to_readable_code()) """ + # VarType.LOD_TENSOR -> LOD_TENSOR + type_str = str(self.type).split('.')[1] if self.type == core.VarDesc.VarType.SELECTED_ROWS or self.type == core.VarDesc.VarType.LOD_TENSOR: - var_str = "{name} : paddle.{type}.shape{shape}.astype({dtype})".\ - format(i="{", e="}", name=self.name, type=self.type, shape=self.shape, dtype=self.dtype) + dtype_str = str(self.dtype).split('.')[1] + var_str = "{name} : {type}.shape{shape}.dtype({dtype}).stop_gradient({stop_gradient})".\ + format(name=self.name, type=type_str, shape=self.shape, dtype=dtype_str, stop_gradient=self.stop_gradient) else: - var_str = "{name} : paddle.{type})".\ - format(i="{", e="}", name=self.name, type=self.type) + var_str = "{name} : {type})".\ + format(name=self.name, type=type_str) if type(self) == Parameter: if self.trainable: -- GitLab