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

Fix UVA Tensor (#46371)

上级 ab97b760
develop 1.8.5 add_kylinv10 bugfix-eval-frame-leakgae cherry-pick-fix-customOP-random-fail fix-run-program-grad-node-mem fix_check fix_custom_device_copy_sync fix_dlpack_for fix_newexe_gc hack_event incuabte/new_frl incubate/new_frl incubate/new_frl_rc incubate/stride layer_norm matmul_double_grad operator_opt pass-compile-eval-frame prv-md-even-more prv-reshape-mkldnn-ut2 release-deleted/2.5 release-rc/2.5 release/2.5 release/llm_2.5 revert-46827-deform_comment revert-47325-remove_cudnn_hardcode revert-47645-add_npu_storage_dims revert-48815-set_free_when_no_cache_hit_default_value_true revert-49499-test_ninja_on_ci revert-49654-prim_api_gen revert-49673-modify_get_single_cov revert-49763-fix_static_composite_gen revert-50158-fix_found_inf_bug_for_custom_optimizer revert-50188-refine_optimizer_create_accumulators revert-50335-fix_optminizer_set_auxiliary_var_bug revert-51676-flag_delete revert-51850-fix_softmaxce_dev revert-52186-deve revert-52523-test_py38 revert-52912-develop revert-53248-set_cmake_policy revert-54029-fix_windows_compile_bug revert-54068-support_translating_op_attribute revert-54214-modify_cmake_dependencies revert-54370-offline_pslib revert-54391-fix_cmake_md5error revert-54411-fix_cpp17_compile revert-54466-offline_pslib revert-54480-cmake-rocksdb revert-55568-fix_BF16_bug1 revert-56328-new_ir_support_vector_type_place_transfer revert-56366-fix_openssl_bug revert-56545-revert-56366-fix_openssl_bug revert-56620-fix_new_ir_ocr_bug revert-56925-check_inputs_grad_semantic revert-57005-refine_stride_flag sd_conv_linear_autocast semi-auto/rule-base support-0D-sort test_for_Filtetfiles zhiqiu-patch-1 v2.5.1 v2.5.0 v2.5.0-rc1 v2.5.0-rc0
无相关合并请求
......@@ -608,8 +608,9 @@ void SetStringTensorFromPyArray(phi::StringTensor *self,
}
template <typename T>
void SetUVATensorFromPyArrayImpl(framework::LoDTensor *self_tensor,
const py::array_t<T> &array,
void SetUVATensorFromPyArrayImpl(
framework::LoDTensor *self_tensor,
const py::array_t<T, py::array::c_style | py::array::forcecast> &array,
int device_id) {
#if defined(PADDLE_WITH_CUDA)
VLOG(4) << "Running in SetUVATensorFromPyArrayImpl.";
......@@ -647,7 +648,7 @@ void SetUVATensorFromPyArrayImpl(framework::LoDTensor *self_tensor,
template <typename T>
void SetUVATensorFromPyArray(
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) {
#if defined(PADDLE_WITH_CUDA)
VLOG(4) << "Running in SetUVATensorFromPyArray for VarBase.";
......
......@@ -57,6 +57,17 @@ class TestUVATensorFromNumpy(unittest.TestCase):
np.testing.assert_allclose(tensor.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):
with _test_eager_guard():
self.func_uva_tensor_creation()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
反馈
建议
客服 返回
顶部