Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tensor.to to check core.Place #59857

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/paddle/base/dygraph/tensor_patch_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ def _to(self, device=None, dtype=None, blocking=None):
elif isinstance(
device,
(
core.Place,
core.CPUPlace,
core.CUDAPlace,
core.CUDAPinnedPlace,
Expand Down
7 changes: 7 additions & 0 deletions test/legacy_test/test_Tensor_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ def test_Tensor_to_device(self):
else:
self.assertTrue(placex_str, "Place(" + place + ")")

def test_Tensor_to_device2(self):
x = paddle.to_tensor([1, 2, 3])
y = paddle.to_tensor([1, 2, 3], place="cpu")

y.to(x.place)
self.assertTrue(x.place, y.place)

def test_Tensor_to_device_dtype(self):
tensorx = paddle.to_tensor([1, 2, 3])
places = ["cpu"]
Expand Down