-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[geometric]Add paddle.geometric.send_ue_recv API #43174
Merged
Merged
Changes from 56 commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
9312d16
add init file
DesmonDay 7b0e641
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
DesmonDay dd22ac2
add op definition and infermeta
DesmonDay a0938cb
add kernel definition funcs
DesmonDay 1bc283c
add broadcast infer shape
DesmonDay c1d51a9
add gpu forward kernel
DesmonDay 6e19153
delete SUB and DIV
DesmonDay c14114b
add x_grad
DesmonDay 4bf6480
add template
DesmonDay 94702d4
add e_grad for min and max
DesmonDay 0d82c54
fix small bug
DesmonDay 40e3fc4
temp commit
DesmonDay c566dcc
temp commit
DesmonDay de96e57
add e_grad for sum and mean
DesmonDay 7f6fb72
fix some compile bug
DesmonDay 375be76
fix compile bugs
DesmonDay 9dd7083
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
DesmonDay 0ea8878
fix compile problem
DesmonDay f1ea92f
add sum forward unittest
DesmonDay f961f9b
fix broadcast error, add kernel sig, register e_grad, change unit test
DesmonDay 1cbbb4d
fix grad
DesmonDay 48230e2
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
DesmonDay e9d57fe
add temp grad fix
DesmonDay be98048
temp commit
DesmonDay 18b5382
add min max unittest
DesmonDay 81014e7
add max, min unittest, fix mul bug
DesmonDay a02e07a
add cpu forward sum and mean
DesmonDay bb5c366
add forward min max, fix mean unittest
DesmonDay 6b82a27
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
DesmonDay fb10fb4
add cpu backward min max
DesmonDay e59e516
fix code-style
DesmonDay de7782e
add backward sum mean
DesmonDay cd10b9e
fix rocm ci
DesmonDay 737da40
set uniitest timeout
DesmonDay 5f6e0b5
fix bug of x broadcast to e, gpu grad
DesmonDay ba4a65a
fix bug of x broadcast to e, cpu grad
DesmonDay 190695a
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
DesmonDay 575ab03
rename BOOST_GET_CONST macro
DesmonDay 10b5cc7
fix rocm ci
DesmonDay b6e2c27
mv graph_send_e_recv to graph_send_ue_recv
DesmonDay 4c9b0fb
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
DesmonDay 5f4e958
move out_size to IntArray
DesmonDay 100f853
add eager op test
DesmonDay 8b5aed9
fix max pool type bug, add unittest for api
DesmonDay 8a5057d
revise api doc
DesmonDay dab0ccc
add fp16 for atomic min and max, add unittest
DesmonDay 9e21001
add unittest
DesmonDay 471b051
add fp16 support for graph_send_recv
DesmonDay 4b6d6ab
fix unittest fp16 bug
DesmonDay 677ea3a
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
DesmonDay 917b029
change OutSizeTensor to Out_size
DesmonDay bb8517a
move E to Y
DesmonDay 666bd68
add copyright, fix comment
DesmonDay a480092
review code
DesmonDay 36d1eab
fix thread block size
DesmonDay 50bf7da
fix thread block size
DesmonDay e7cbc9f
change api attribute name: pool_type to reduce_op, compute_type to me…
DesmonDay 2b0bd9a
change api attribute name, move pool_type to reduce_op, move compute_…
DesmonDay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "paddle/fluid/framework/infershape_utils.h" | ||
#include "paddle/fluid/framework/op_registry.h" | ||
#include "paddle/phi/core/infermeta_utils.h" | ||
#include "paddle/phi/infermeta/multiary.h" | ||
|
||
namespace paddle { | ||
namespace operators { | ||
|
||
class GraphSendUERecvOP : public framework::OperatorWithKernel { | ||
public: | ||
using framework::OperatorWithKernel::OperatorWithKernel; | ||
|
||
protected: | ||
framework::OpKernelType GetExpectedKernelType( | ||
const framework::ExecutionContext& ctx) const override { | ||
return framework::OpKernelType( | ||
OperatorWithKernel::IndicateVarDataType(ctx, "X"), | ||
ctx.device_context()); | ||
} | ||
}; | ||
|
||
class GraphSendUERecvGradOp : public framework::OperatorWithKernel { | ||
public: | ||
using framework::OperatorWithKernel::OperatorWithKernel; | ||
|
||
void InferShape(framework::InferShapeContext* ctx) const override { | ||
auto in_dims = ctx->GetInputDim("X"); | ||
ctx->SetOutputDim(framework::GradVarName("X"), in_dims); | ||
auto y_dims = ctx->GetInputDim("Y"); | ||
ctx->SetOutputDim(framework::GradVarName("Y"), y_dims); | ||
} | ||
|
||
protected: | ||
framework::OpKernelType GetExpectedKernelType( | ||
const framework::ExecutionContext& ctx) const override { | ||
return framework::OpKernelType(OperatorWithKernel::IndicateVarDataType( | ||
ctx, framework::GradVarName("Out")), | ||
ctx.device_context()); | ||
} | ||
}; | ||
|
||
class GraphSendUERecvOpMaker : public framework::OpProtoAndCheckerMaker { | ||
public: | ||
void Make() override { | ||
AddInput("X", | ||
"The input tensor with data type float32, float64, int32, int64."); | ||
AddInput("Y", | ||
"The input edge weight tensor, data type should be same with X"); | ||
AddInput("Src_index", "The source index tensor."); | ||
AddInput("Dst_index", "The destination index tensor."); | ||
AddInput("Out_size", | ||
"(Tensor<int>, optional). The 0th dimension of the output." | ||
"It has a higher priority than Attr(out_size).") | ||
.AsDispensable(); | ||
AddOutput("Out", "Output tensor of graph_send_ue_recv op."); | ||
AddOutput("Dst_count", | ||
"Count tensor of Dst_index, mainly for MEAN pool_type.") | ||
.AsIntermediate(); | ||
AddAttr<std::string>("compute_type", | ||
"(string, default 'ADD')" | ||
"Define differenct computation types between X and E.") | ||
.SetDefault("ADD") | ||
.InEnum({"ADD", "MUL"}); | ||
AddAttr<std::string>("pool_type", | ||
"(string, default 'SUM')" | ||
"Define different pool types to receive the result " | ||
"tensors of Dst_index.") | ||
.SetDefault("SUM") | ||
.InEnum({"SUM", "MEAN", "MIN", "MAX"}); | ||
AddAttr<std::vector<int64_t>>( | ||
"out_size", | ||
"(vector<int64_t>, default {0})" | ||
"Define the first dimension of Output tensor." | ||
"If set default {0}, then the shape of Out is the same with X.") | ||
.SetDefault({0}); | ||
AddComment(R"DOC( | ||
Graph Learning Send_UE_Recv combine operator. | ||
|
||
$Out = Recv(Compute(Send(X, Src_index), Y, compute_type), Dst_index, pool_type)$ | ||
|
||
This operator is mainly used in Graph Learning domain, and the main purpose is to reduce | ||
intermediate memory consumption in the process of message passing. | ||
|
||
Take `X` as the input tensor, we first use `src_index` to gather corresponding data. | ||
Then the gather data should compute with `Y` in different compute_types, like add, sub, mul, and div, | ||
and get the computation result. Then, use `dst_index` to update the corresponding position of output | ||
tensor in different pooling types, like sum, mean, max, or min. | ||
|
||
)DOC"); | ||
} | ||
}; | ||
|
||
template <typename T> | ||
class GraphSendUERecvGradOpMaker : public framework::SingleGradOpMaker<T> { | ||
public: | ||
using framework::SingleGradOpMaker<T>::SingleGradOpMaker; | ||
|
||
protected: | ||
void Apply(GradOpPtr<T> op) const override { | ||
op->SetType("graph_send_ue_recv_grad"); | ||
op->SetInput("X", this->Input("X")); | ||
op->SetInput("Y", this->Input("Y")); | ||
op->SetInput("Src_index", this->Input("Src_index")); | ||
op->SetInput("Dst_index", this->Input("Dst_index")); | ||
|
||
if (PADDLE_GET_CONST(std::string, this->GetAttr("pool_type")) == "MEAN") { | ||
op->SetInput("Dst_count", this->Output("Dst_count")); | ||
} | ||
|
||
if (PADDLE_GET_CONST(std::string, this->GetAttr("pool_type")) == "MIN" || | ||
PADDLE_GET_CONST(std::string, this->GetAttr("pool_type")) == "MAX") { | ||
op->SetInput("Out", this->Output("Out")); | ||
} | ||
|
||
op->SetInput(framework::GradVarName("Out"), this->OutputGrad("Out")); | ||
op->SetOutput(framework::GradVarName("X"), this->InputGrad("X")); | ||
op->SetOutput(framework::GradVarName("Y"), this->InputGrad("Y")); | ||
op->SetAttrMap(this->Attrs()); | ||
} | ||
}; | ||
|
||
} // namespace operators | ||
} // namespace paddle | ||
|
||
namespace ops = paddle::operators; | ||
|
||
DECLARE_INFER_SHAPE_FUNCTOR(graph_send_ue_recv, | ||
GraphSendUERecvInferShapeFunctor, | ||
PD_INFER_META(phi::GraphSendUERecvInferMeta)); | ||
REGISTER_OPERATOR(graph_send_ue_recv, | ||
ops::GraphSendUERecvOP, | ||
ops::GraphSendUERecvOpMaker, | ||
ops::GraphSendUERecvGradOpMaker<paddle::framework::OpDesc>, | ||
ops::GraphSendUERecvGradOpMaker<paddle::imperative::OpBase>, | ||
GraphSendUERecvInferShapeFunctor); | ||
REGISTER_OPERATOR(graph_send_ue_recv_grad, ops::GraphSendUERecvGradOp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块的type再确认一下