diff --git a/python/paddle/base/dygraph/tensor_patch_methods.py b/python/paddle/base/dygraph/tensor_patch_methods.py index 83bb82ee70d171..b726a029141d74 100644 --- a/python/paddle/base/dygraph/tensor_patch_methods.py +++ b/python/paddle/base/dygraph/tensor_patch_methods.py @@ -677,10 +677,6 @@ def __deepcopy__(self, memo): Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True, 2.) """ - if not self.is_leaf: - raise RuntimeError( - "Only Leaf Tensor support the deepcopy at the moment, non-Leaf Tensors contains graph information that does't support deepcopy" - ) new_tensor = core.eager.Tensor() new_tensor.name = self.name + unique_name.generate("_deepcopy") memo[id(self)] = new_tensor diff --git a/test/legacy_test/test_var_base.py b/test/legacy_test/test_var_base.py index 052f9bb1bc6030..026675e45b5189 100644 --- a/test/legacy_test/test_var_base.py +++ b/test/legacy_test/test_var_base.py @@ -512,9 +512,6 @@ def test_deep_copy(self): with self.assertRaises(ValueError): x_copy[:] = 5.0 - with self.assertRaises(RuntimeError): - copy.deepcopy(z) - x_copy2 = copy.deepcopy(x, memo) y_copy2 = copy.deepcopy(y, memo) self.assertEqual(id(x_copy), id(x_copy2))