Skip to content

Commit

Permalink
Merge branch 'refactor_dygraph_v1' of https://github.com/JiabinYang/P…
Browse files Browse the repository at this point in the history
…addle into api_code_gene
  • Loading branch information
wanghuancoder committed Nov 2, 2021
2 parents 6072d3a + 0483d22 commit 5f8cd21
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
15 changes: 11 additions & 4 deletions paddle/fluid/eager/autocodegen/eager_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -852,11 +852,18 @@ static std::pair<std::string, std::string> GenerateForwardFunctionContents(
std::string arg_str =
paddle::string::Sprintf(FWD_NUM_ARG_TEMPLATE, outnum);
dygraph_function_args_str += arg_str;
const char* FWD_OUTS_CONTENT_TEMPLATE =
"{ \"%s\", egr::ConstructDuplicableOutput(%s) },";
outs_contents_str += paddle::string::Sprintf(FWD_OUTS_CONTENT_TEMPLATE,
output_name, outnum);
} else {
const char* FWD_OUTS_CONTENT_TEMPLATE =
"{ \"%s\", "
"{std::make_shared<egr::EagerTensor>(egr::Controller::Instance()."
"GenerateUniqueName())}},";
outs_contents_str += paddle::string::Sprintf(FWD_OUTS_CONTENT_TEMPLATE,
output_name, outnum);
}
const char* FWD_OUTS_CONTENT_TEMPLATE =
"{ \"%s\", egr::ConstructDuplicableOutput(%s) },";
outs_contents_str +=
paddle::string::Sprintf(FWD_OUTS_CONTENT_TEMPLATE, output_name, outnum);
}
if (outs_contents_str.size() > 0)
outs_contents_str.pop_back(); // Remove trailing ","
Expand Down
16 changes: 8 additions & 8 deletions paddle/fluid/eager/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ std::vector<std::shared_ptr<egr::EagerTensor>> SyncToVars(
const egr::EagerTensor& tensor) {
// TODO(jiabin): No const cast here. We should call SyncToVar in Python_C
// wrapper
auto egr_tensor = std::make_shared<EagerTensor>(tensor);
egr_tensor->SyncToVar(paddle::framework::proto::VarType_Type_LOD_TENSOR);
return {egr_tensor};
const_cast<EagerTensor*>(&tensor)->SyncToVar(
paddle::framework::proto::VarType_Type_LOD_TENSOR);
return {std::make_shared<EagerTensor>(tensor)};
}

std::vector<std::shared_ptr<egr::EagerTensor>> SyncToVars(
Expand All @@ -38,8 +38,9 @@ std::vector<std::shared_ptr<egr::EagerTensor>> SyncToVars(
size_t num = tensors.size();
res.reserve(num);
for (size_t i = 0; i < num; i++) {
const_cast<EagerTensor*>(&(tensors[i]))
->SyncToVar(paddle::framework::proto::VarType_Type_LOD_TENSOR);
res.emplace_back(new EagerTensor(tensors[i]));
res.back()->SyncToVar(paddle::framework::proto::VarType_Type_LOD_TENSOR);
}
return res;
}
Expand All @@ -49,9 +50,8 @@ std::vector<std::shared_ptr<egr::EagerTensor>> SyncToTensors(
const egr::EagerTensor& tensor) {
// TODO(jiabin): No const cast here. We should call SyncToTensor in Python_C
// wrapper
auto egr_tensor = std::make_shared<EagerTensor>(tensor);
egr_tensor->SyncToTensor();
return {egr_tensor};
const_cast<EagerTensor*>(&tensor)->SyncToTensor();
return {std::make_shared<EagerTensor>(tensor)};
}

std::vector<std::shared_ptr<egr::EagerTensor>> SyncToTensors(
Expand All @@ -62,8 +62,8 @@ std::vector<std::shared_ptr<egr::EagerTensor>> SyncToTensors(
size_t num = tensors.size();
res.reserve(num);
for (size_t i = 0; i < num; i++) {
const_cast<EagerTensor*>(&(tensors[i]))->SyncToTensor();
res.emplace_back(new EagerTensor(tensors[i]));
res.back()->SyncToTensor();
}
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/pybind/eager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ PyObject* eagertensor_new(PyTypeObject* type, PyObject* args,
}

static void eagertensor_dealloc(EagerTensorObject* self) {
// TODO(wanghuancoder): Call destructor here.
self->eagertensor.~EagerTensor();
Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self));
}

Expand Down
2 changes: 2 additions & 0 deletions paddle/fluid/pybind/eager_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ PyObject* ToPyObject(const egr::EagerTensor& value) {
PyObject* obj = pEagerTensorType->tp_alloc(pEagerTensorType, 0);
if (obj) {
auto v = reinterpret_cast<EagerTensorObject*>(obj);
new (&(v->eagertensor)) egr::EagerTensor();
v->eagertensor = value;
} else {
PADDLE_THROW(platform::errors::Fatal(
Expand Down Expand Up @@ -223,6 +224,7 @@ PyObject* ToPyObject(const std::vector<egr::EagerTensor>& value) {
PyObject* obj = pEagerTensorType->tp_alloc(pEagerTensorType, 0);
if (obj) {
auto v = reinterpret_cast<EagerTensorObject*>(obj);
new (&(v->eagertensor)) egr::EagerTensor();
v->eagertensor = value[i];
} else {
PADDLE_THROW(platform::errors::Fatal(
Expand Down

1 comment on commit 5f8cd21

@paddle-bot-old
Copy link

@paddle-bot-old paddle-bot-old bot commented on 5f8cd21 Nov 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵️ CI failures summary

🔍 PR: #16 Commit ID: 5f8cd21 contains failed CI.

🔹 Failed: PR-CI-iScan-Python

Unknown Failed
Unknown Failed

🔹 Failed: PR-CI-musl

Unknown Failed
2021-11-02 18:53:24 Auto-merging paddle/fluid/framework/pten_utils.h
2021-11-02 18:53:24 CONFLICT (add/add): Merge conflict in paddle/fluid/framework/pten_utils.h
2021-11-02 18:53:24 Auto-merging paddle/fluid/framework/pten_utils.cc
2021-11-02 18:53:24 CONFLICT (add/add): Merge conflict in paddle/fluid/framework/pten_utils.cc
2021-11-02 18:53:24 Removing paddle/fluid/framework/paddle2cinn/cinn_runner_test.cc
2021-11-02 18:53:24 Removing paddle/fluid/framework/paddle2cinn/cinn_runner.h
2021-11-02 18:53:24 Removing paddle/fluid/framework/paddle2cinn/cinn_runner.cc
2021-11-02 18:53:24 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object_test.cc
2021-11-02 18:53:24 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object.h
2021-11-02 18:53:24 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object.cc
2021-11-02 18:53:24 Auto-merging paddle/fluid/framework/operator.h
2021-11-02 18:53:24 CONFLICT (content): Merge conflict in paddle/fluid/framework/operator.h
2021-11-02 18:53:24 Auto-merging paddle/fluid/framework/operator.cc
2021-11-02 18:53:24 CONFLICT (content): Merge conflict in paddle/fluid/framework/operator.cc
2021-11-02 18:53:24 Auto-merging paddle/fluid/framework/details/nan_inf_utils.h
2021-11-02 18:53:24 Auto-merging paddle/fluid/framework/details/CMakeLists.txt
2021-11-02 18:53:24 Auto-merging paddle/fluid/framework/CMakeLists.txt
2021-11-02 18:53:24 CONFLICT (content): Merge conflict in paddle/fluid/framework/CMakeLists.txt
2021-11-02 18:53:24 Automatic merge failed; fix conflicts and then commit the result.

🔹 Failed: PR-CI-iScan-C

Unknown Failed
Unknown Failed

🔹 Failed: PR-CI-Mac-Python3

Unknown Failed
2021-11-02 18:53:48 自动合并 paddle/fluid/framework/pten_utils.h
2021-11-02 18:53:48 冲突(添加/添加):合并冲突于 paddle/fluid/framework/pten_utils.h
2021-11-02 18:53:48 自动合并 paddle/fluid/framework/pten_utils.cc
2021-11-02 18:53:48 冲突(添加/添加):合并冲突于 paddle/fluid/framework/pten_utils.cc
2021-11-02 18:53:48 删除 paddle/fluid/framework/paddle2cinn/cinn_runner_test.cc
2021-11-02 18:53:48 删除 paddle/fluid/framework/paddle2cinn/cinn_runner.h
2021-11-02 18:53:48 删除 paddle/fluid/framework/paddle2cinn/cinn_runner.cc
2021-11-02 18:53:48 删除 paddle/fluid/framework/paddle2cinn/cinn_compiled_object_test.cc
2021-11-02 18:53:48 删除 paddle/fluid/framework/paddle2cinn/cinn_compiled_object.h
2021-11-02 18:53:48 删除 paddle/fluid/framework/paddle2cinn/cinn_compiled_object.cc
2021-11-02 18:53:48 自动合并 paddle/fluid/framework/operator.h
2021-11-02 18:53:48 冲突(内容):合并冲突于 paddle/fluid/framework/operator.h
2021-11-02 18:53:48 自动合并 paddle/fluid/framework/operator.cc
2021-11-02 18:53:48 冲突(内容):合并冲突于 paddle/fluid/framework/operator.cc
2021-11-02 18:53:48 自动合并 paddle/fluid/framework/details/nan_inf_utils.h
2021-11-02 18:53:48 自动合并 paddle/fluid/framework/details/CMakeLists.txt
2021-11-02 18:53:48 自动合并 paddle/fluid/framework/CMakeLists.txt
2021-11-02 18:53:48 冲突(内容):合并冲突于 paddle/fluid/framework/CMakeLists.txt
2021-11-02 18:53:48 自动合并失败,修正冲突然后提交修正的结果。

🔹 Failed: PR-CI-Windows

Unknown Failed
2021-11-02 18:54:04 Auto-merging paddle/fluid/framework/pten_utils.h
2021-11-02 18:54:04 CONFLICT (add/add): Merge conflict in paddle/fluid/framework/pten_utils.cc
2021-11-02 18:54:04 Auto-merging paddle/fluid/framework/pten_utils.cc
2021-11-02 18:54:04 Removing paddle/fluid/framework/paddle2cinn/cinn_runner_test.cc
2021-11-02 18:54:04 Removing paddle/fluid/framework/paddle2cinn/cinn_runner.h
2021-11-02 18:54:04 Removing paddle/fluid/framework/paddle2cinn/cinn_runner.cc
2021-11-02 18:54:04 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object_test.cc
2021-11-02 18:54:04 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object.h
2021-11-02 18:54:04 Removing paddle/fluid/framework/paddle2cinn/cinn_compiled_object.cc
2021-11-02 18:54:04 Auto-merging paddle/fluid/framework/operator.h
2021-11-02 18:54:04 CONFLICT (content): Merge conflict in paddle/fluid/framework/operator.h
2021-11-02 18:54:04 Auto-merging paddle/fluid/framework/operator.cc
2021-11-02 18:54:04 CONFLICT (content): Merge conflict in paddle/fluid/framework/operator.cc
2021-11-02 18:54:04 Auto-merging paddle/fluid/framework/details/nan_inf_utils.h
2021-11-02 18:54:04 Auto-merging paddle/fluid/framework/details/CMakeLists.txt
2021-11-02 18:54:04 Auto-merging paddle/fluid/framework/CMakeLists.txt
2021-11-02 18:54:04 CONFLICT (content): Merge conflict in paddle/fluid/framework/CMakeLists.txt
2021-11-02 18:54:04 Automatic merge failed; fix conflicts and then commit the result.
2021-11-02 18:54:04 C:\Users\Administrator\Downloads\workspace\05f3a352-dbe5-4e13-8488-08e49883e799\Paddle>if 1 NEQ 0 exit /b 1

Please sign in to comment.