Skip to content

Commit

Permalink
delete deep copy is_leaf check (PaddlePaddle#57192)
Browse files Browse the repository at this point in the history
* delete deep copy is_leaf check
  • Loading branch information
wanghuancoder authored Sep 12, 2023
1 parent e6938c6 commit ff98caf
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 7 deletions.
4 changes: 0 additions & 4 deletions python/paddle/base/dygraph/tensor_patch_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions test/legacy_test/test_var_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit ff98caf

Please sign in to comment.