add stop_gradient property and remove reduce redundant information (#29185)

* add stop_gradient property and remove reduce redundant information

* refine code
revert-31562-mean
Leo Chen 4 years ago committed by GitHub
parent 64f29fbb70
commit 73e51a17e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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:

Loading…
Cancel
Save