diff --git a/paddle/fluid/pybind/eager_method.cc b/paddle/fluid/pybind/eager_method.cc index 7f32c14c493af45a9962763338973549071365da..cc2f21c418f08e494cc865b7e3b219b096c6d7ad 100644 --- a/paddle/fluid/pybind/eager_method.cc +++ b/paddle/fluid/pybind/eager_method.cc @@ -1313,7 +1313,7 @@ static PyObject* tensor_method__setitem_eager_tensor(TensorObject* self, } } } else { - auto self_numpy = TensorToPyArray(*self_tensor); + auto self_numpy = TensorToPyArray(*self_tensor, true); VLOG(4) << "parse_index is false"; if (PyCheckTensor(_index)) { VLOG(4) << "index is tensor"; diff --git a/python/paddle/fluid/tests/unittests/test_set_value_op.py b/python/paddle/fluid/tests/unittests/test_set_value_op.py index c2dde3a258d98b18c864fe89d953455fc58ec65f..b4d5c1d02eff58ede1f349f685165933b0379ff3 100644 --- a/python/paddle/fluid/tests/unittests/test_set_value_op.py +++ b/python/paddle/fluid/tests/unittests/test_set_value_op.py @@ -1635,6 +1635,20 @@ class TestSetValueInplaceLeafVar(unittest.TestCase): paddle.enable_static() +class TestSetValueIsSamePlace(unittest.TestCase): + def test_is_same_place(self): + paddle.disable_static() + paddle.seed(100) + paddle.set_device('cpu') + a = paddle.rand(shape=[2, 3, 4]) + origin_place = a.place + a[[0, 1], 1] = 10 + self.assertEqual(origin_place._type(), a.place._type()) + if paddle.is_compiled_with_cuda(): + paddle.set_device('gpu') + paddle.enable_static() + + @unittest.skipIf( not core.is_compiled_with_cuda() or not core.is_bfloat16_supported(core.CUDAPlace(0)),