未验证 提交 d772166c 编写于 作者: S Siming Dai 提交者: GitHub

Fix UVA Tensor (#46371)

上级 ab97b760
...@@ -608,9 +608,10 @@ void SetStringTensorFromPyArray(phi::StringTensor *self, ...@@ -608,9 +608,10 @@ void SetStringTensorFromPyArray(phi::StringTensor *self,
} }
template <typename T> template <typename T>
void SetUVATensorFromPyArrayImpl(framework::LoDTensor *self_tensor, void SetUVATensorFromPyArrayImpl(
const py::array_t<T> &array, framework::LoDTensor *self_tensor,
int device_id) { const py::array_t<T, py::array::c_style | py::array::forcecast> &array,
int device_id) {
#if defined(PADDLE_WITH_CUDA) #if defined(PADDLE_WITH_CUDA)
VLOG(4) << "Running in SetUVATensorFromPyArrayImpl."; VLOG(4) << "Running in SetUVATensorFromPyArrayImpl.";
std::vector<int64_t> dims; std::vector<int64_t> dims;
...@@ -647,7 +648,7 @@ void SetUVATensorFromPyArrayImpl(framework::LoDTensor *self_tensor, ...@@ -647,7 +648,7 @@ void SetUVATensorFromPyArrayImpl(framework::LoDTensor *self_tensor,
template <typename T> template <typename T>
void SetUVATensorFromPyArray( void SetUVATensorFromPyArray(
const std::shared_ptr<paddle::imperative::VarBase> &self, const std::shared_ptr<paddle::imperative::VarBase> &self,
const py::array_t<T> &array, const py::array_t<T, py::array::c_style | py::array::forcecast> &array,
int device_id) { int device_id) {
#if defined(PADDLE_WITH_CUDA) #if defined(PADDLE_WITH_CUDA)
VLOG(4) << "Running in SetUVATensorFromPyArray for VarBase."; VLOG(4) << "Running in SetUVATensorFromPyArray for VarBase.";
......
...@@ -57,6 +57,17 @@ class TestUVATensorFromNumpy(unittest.TestCase): ...@@ -57,6 +57,17 @@ class TestUVATensorFromNumpy(unittest.TestCase):
np.testing.assert_allclose(tensor.numpy(), data, rtol=1e-05) np.testing.assert_allclose(tensor.numpy(), data, rtol=1e-05)
np.testing.assert_allclose(tensor2.numpy(), data, rtol=1e-05) np.testing.assert_allclose(tensor2.numpy(), data, rtol=1e-05)
def test_uva_tensor_corectness(self):
if paddle.fluid.core.is_compiled_with_cuda():
a = np.arange(0, 100, dtype="int32")
a = a.reshape([10, 10])
slice_a = a[:, 5]
tensor1 = paddle.to_tensor(slice_a)
tensor2 = core.eager.to_uva_tensor(slice_a)
np.testing.assert_allclose(tensor1.numpy(),
tensor2.numpy(),
rtol=1e-05)
def test_uva_tensor_creation(self): def test_uva_tensor_creation(self):
with _test_eager_guard(): with _test_eager_guard():
self.func_uva_tensor_creation() self.func_uva_tensor_creation()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册