未验证 提交 a7cbd3ef 编写于 作者: J Jiabin Yang 提交者: GitHub

[Bug Fix]Fix gradient accumulator (#39577)

* merge legacy to fluid

* Remove legacy code

* Remove legacy code

* Remove DataType test

* Using Tensor directly instead of using EagerTensor

* support gradient_accumulation

* make test_imperative_lod_tensor_to_selected_rows longer

* make test_imperative_lod_tensor_to_selected_rows longer

* refine code

* Rename all EagerTensor to Tensor

* Rename some EagerTensor to Tensor

* rename EagerTensor to EagerVariable

* add more test

* fix different device gradient_accmulator bug

* merge develop

* remove useless tests
上级 adf4b98f
......@@ -300,13 +300,10 @@ void TensorAdd(const VarType& src, VarType* dst) {
"should be equal, Otherwise, the calculation results "
"will be incorrect."));
#ifdef PADDLE_WITH_XPU
// if src and dst are in different place, copy dst to src's place
if (dst_tensor->place() != place) {
paddle::framework::TensorCopySync(*dst_tensor, place, dst_tensor);
}
#endif
#define PADDLE_TENSOR_ADD(cpp_type) \
if (data_type == framework::DataTypeTrait<cpp_type>::DataType()) { \
TensorAddFunctor<cpp_type> func( \
......
......@@ -163,10 +163,30 @@ TEST(test_add_functor, add_functor) {
gpu_res = TensorddTest(gpu_place, gpu_place, static_cast<double>(1.0),
static_cast<double>(2.0));
EXPECT_EQ(gpu_res, 0);
// normal
gpu_res = TensorddTest(gpu_place, gpu_place, static_cast<float>(1.0),
static_cast<float>(2.0));
EXPECT_EQ(gpu_res, 0);
gpu_res =
TensorddTest(gpu_place, gpu_place, static_cast<platform::float16>(1.0),
static_cast<platform::float16>(2.0));
EXPECT_EQ(gpu_res, 0);
// different places
gpu_res = TensorddTest(cpu_place, gpu_place, static_cast<float>(1.0),
static_cast<float>(2.0));
EXPECT_EQ(gpu_res, 0);
gpu_res = TensorddTest(gpu_place, cpu_place, static_cast<float>(1.0),
static_cast<float>(2.0));
EXPECT_EQ(gpu_res, 0);
gpu_res =
TensorddTest(cpu_place, gpu_place, static_cast<platform::float16>(1.0),
static_cast<platform::float16>(2.0));
EXPECT_EQ(gpu_res, 0);
gpu_res =
TensorddTest(gpu_place, cpu_place, static_cast<platform::float16>(1.0),
static_cast<platform::float16>(2.0));
EXPECT_EQ(gpu_res, 0);
#endif
#ifdef PADDLE_WITH_XPU
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册