Skip to content
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/pir/math_op_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def cuda(self, device_id=None, blocking=True):
# 1 means cuda place, see paddle/phi/kernels/memcpy_kernel.cc
return _C_ops.memcpy(self, 1)

@property
def place(self):
"""
Value don't have 'place' interface in static graph mode
Expand Down
20 changes: 15 additions & 5 deletions test/dygraph_to_static/test_place.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,33 @@

from dygraph_to_static_utils import (
Dy2StTestBase,
test_legacy_and_pt_and_pir,
test_legacy_and_pt,
test_pir_only,
)

import paddle


class TestPlace(Dy2StTestBase):
@test_legacy_and_pt_and_pir
def test_place(self):
@test_legacy_and_pt
def test_place_legacy(self):
# TODO(cleanup-legacy-ir): remove this test case
paddle.enable_static()
x = paddle.to_tensor([1, 2, 3, 4])
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
self.assertIsNone(x.place())
self.assertTrue(len(w) == 1)
if paddle.framework.use_pir_api():
self.assertIn("Value do not have 'place'", str(w[-1].message))

@test_pir_only
def test_place(self):
paddle.enable_static()
x = paddle.to_tensor([1, 2, 3, 4])
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
self.assertIsNone(x.place)
self.assertTrue(len(w) == 1)
self.assertIn("Value do not have 'place'", str(w[-1].message))


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/test_math_op_patch_pir.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def test_place(self):
warnings.simplefilter("always")
with paddle.pir_utils.IrGuard():
x = paddle.static.data(name='x', shape=[3, 2, 1])
x.place()
_ = x.place
self.assertTrue(len(w) == 1)
self.assertTrue("place" in str(w[-1].message))

Expand Down