Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AutoParallel] Custom op support auto parallel #58553

Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0a508e0
custom op support auto parallel
wanghuancoder Oct 30, 2023
4b658f4
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Oct 30, 2023
ebc9369
refine
wanghuancoder Oct 31, 2023
0d5cdfd
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Oct 31, 2023
429bfd8
refine
wanghuancoder Oct 31, 2023
08f2564
refine
wanghuancoder Nov 1, 2023
ae6d1b1
refine
wanghuancoder Nov 1, 2023
fec496c
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Nov 1, 2023
d28838e
refine
wanghuancoder Nov 1, 2023
7490838
refine
wanghuancoder Nov 1, 2023
da6a898
refine
wanghuancoder Nov 1, 2023
b8f5a48
refine
wanghuancoder Nov 1, 2023
40d2070
refine
wanghuancoder Nov 1, 2023
ff62c9a
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Nov 2, 2023
3f38300
refine
wanghuancoder Nov 2, 2023
b0c8891
refine
wanghuancoder Nov 2, 2023
b9fe126
refine
wanghuancoder Nov 2, 2023
e069ba3
refine
wanghuancoder Nov 2, 2023
64fb686
refine
wanghuancoder Nov 2, 2023
174be88
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Nov 2, 2023
635fe9b
refine
wanghuancoder Nov 2, 2023
322b1b3
refine
wanghuancoder Nov 3, 2023
b856a7a
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Nov 3, 2023
be791d2
refine
wanghuancoder Nov 3, 2023
903d61e
refine
wanghuancoder Nov 6, 2023
ea4aa2f
refine
wanghuancoder Nov 6, 2023
963c4a7
refine
wanghuancoder Nov 6, 2023
5de9314
refine
wanghuancoder Nov 6, 2023
405955d
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
wanghuancoder Nov 6, 2023
8185016
refine
wanghuancoder Nov 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions paddle/fluid/eager/custom_operator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
cc_library(
custom_operator_node
SRCS custom_operator_node.cc
DEPS phi grad_node_info custom_operator utils custom_operator_utils)

cc_library(
custom_operator_utils
SRCS custom_operator_utils.cc
DEPS phi grad_node_info custom_operator utils)
31 changes: 16 additions & 15 deletions paddle/fluid/eager/custom_operator/custom_operator_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "paddle/fluid/eager/custom_operator/custom_operator_node.h"

#include "paddle/fluid/eager/custom_operator/custom_operator_utils.h"
#include "paddle/fluid/framework/custom_operator.h"
#include "paddle/fluid/framework/custom_operator_utils.h"
#include "paddle/fluid/platform/profiler/event_tracing.h"
Expand Down Expand Up @@ -172,8 +173,6 @@ RunCustomOpNode::operator()(paddle::small_vector<std::vector<paddle::Tensor>,
paddle::OpMetaInfoHelper::GetInputs(vec_map[1]);
const auto& grad_outputs_names =
paddle::OpMetaInfoHelper::GetOutputs(vec_map[1]);
const auto& grad_inplace_map =
paddle::OpMetaInfoHelper::GetInplaceMap(vec_map[1]);
const auto& map =
egr::Controller::Instance().GetCustomEdgesSlotMap().at(op_type_);

Expand Down Expand Up @@ -251,11 +250,12 @@ RunCustomOpNode::operator()(paddle::small_vector<std::vector<paddle::Tensor>,
}
VLOG(7) << "Run Kernel of Grad Custom Op: " << op_type_ << "_grad";

// handle inplace map
ctx.UpdatePlainOutputs(
grad_inputs_name, grad_outputs_names, grad_inplace_map);
(*paddle::OpMetaInfoHelper::GetKernelFn(vec_map[1]))(&ctx);
ctx.AssignInplaceOutputs();
run_custom_op_impl(vec_map[1], false, false, ctx);

for (size_t i = 0; i < ctx.OutputRange().size(); ++i) {
auto output_pair = ctx.OutputRangeAt(i);
outs[i] = ctx.OutputsBetween(output_pair.first, output_pair.second);
}

// handle optional None output when construct backward graph
for (size_t i = 0; i < ctx.OutputRange().size(); i++) {
Expand All @@ -264,7 +264,9 @@ RunCustomOpNode::operator()(paddle::small_vector<std::vector<paddle::Tensor>,
ctx.MutableOutputAt(ctx.OutputRangeAt(i).first);
if (!out_tensor->initialized()) {
PADDLE_ENFORCE(
paddle::framework::detail::IsOptionalVar(grad_outputs_names.at(i)),
paddle::framework::detail::IsOptionalVar(
grad_outputs_names.at(i)) ||
out_tensor->is_dist_tensor(),
phi::errors::InvalidArgument(
"Custom grad operator's %d-th output is not initialized. "
"Please check your implementation again. If you are "
Expand Down Expand Up @@ -386,8 +388,6 @@ RunCustomOpDoubleGradNode::operator()(
paddle::OpMetaInfoHelper::GetInputs(vec_map[2]);
const auto& grad_outputs_names =
paddle::OpMetaInfoHelper::GetOutputs(vec_map[2]);
const auto& grad_inplace_map =
paddle::OpMetaInfoHelper::GetInplaceMap(vec_map[2]);
const auto& map =
egr::Controller::Instance().GetCustomEdgesSlotMap().at(op_type_);

Expand Down Expand Up @@ -451,11 +451,12 @@ RunCustomOpDoubleGradNode::operator()(
}
VLOG(7) << "Run Kernel of Grad Custom Op: " << op_type_ << "_grad_grad";

// handle inplace map
ctx.UpdatePlainOutputs(
grad_inputs_name, grad_outputs_names, grad_inplace_map);
(*paddle::OpMetaInfoHelper::GetKernelFn(vec_map[2]))(&ctx);
ctx.AssignInplaceOutputs();
run_custom_op_impl(vec_map[2], false, true, ctx);

for (size_t i = 0; i < ctx.OutputRange().size(); ++i) {
auto output_pair = ctx.OutputRangeAt(i);
outs[i] = ctx.OutputsBetween(output_pair.first, output_pair.second);
}

return outs;
}
Expand Down
Loading