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

[geometric]Add paddle.geometric.send_uv API #44848

Merged
merged 14 commits into from
Aug 16, 2022

Conversation

DesmonDay
Copy link
Contributor

@DesmonDay DesmonDay commented Aug 3, 2022

PR types

New features

PR changes

APIs

Describe

Add paddle.geometric.send_uv API, mainly used in graph learning domain.

@paddle-bot
Copy link

paddle-bot bot commented Aug 3, 2022

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@DesmonDay DesmonDay changed the title initial commit Add paddle.geometric.send_uv API Aug 3, 2022
@ZHUI ZHUI assigned ZHUI and wawltor Aug 4, 2022
@DesmonDay DesmonDay changed the title Add paddle.geometric.send_uv API [geometric]Add paddle.geometric.send_uv API Aug 8, 2022
@@ -0,0 +1,134 @@
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

比较好奇这里的文件名为什么不在send_recv里面

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已放到 send_recv 中。

Args:
x (Tensor): The source node feature tensor, and the available data type is float32, float64, int32, int64. And we support float16 in gpu version.
y (Tensor): The destination node feature tensor, and the available data type is float32, float64, int32, int64. And we support float16 in gpu version.
src_index (Tensor): An 1-D tensor, and the available data type is int32, int64.
Copy link
Contributor

Choose a reason for hiding this comment

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

注意一下这里float16是否已经支持了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

支持了

from paddle import _C_ops

from .utils import reshape_lhs_rhs

Copy link
Contributor

Choose a reason for hiding this comment

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

加上 all = []

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -14,3 +14,4 @@

from .send_recv import send_u_recv # noqa: F401
from .send_recv import send_ue_recv # noqa: F401
from .send import send_uv # noqa: F401
Copy link
Contributor

Choose a reason for hiding this comment

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

这里加上 all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
ctx.template Alloc<T>(out);
T* out_data = out->data<T>();
if (index_size == 0) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

这里index_size为0,直接return 是否合适了,要么直接报错?直接return 看起来是一个未定义的行为

Copy link
Contributor Author

Choose a reason for hiding this comment

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

修改成直接报错了

memset(x_grad_data, 0, memset_bytes_x);
memset(y_grad_data, 0, memset_bytes_y);

if (index_size == 0) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

这里如果在前向Op进行处理,这里也可以直接报错

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

T* x_grad_off = x_grad + dst * slice_size;
const T* out_grad_off = out_grad + i * slice_size;
for (int64_t j = 0; j < slice_size; j++) {
if (out_grad_off[j] != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

这里有个讨论,这里是不是也可以直接加上out_grad_off,不管梯度是否为0;因为在多线程计算里面,看起来直接加法会比有分支更好

Copy link
Contributor Author

Choose a reason for hiding this comment

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

主要是因为这里会涉及到一个原子操作,所以加上分支判断可以减少原子操作。

auto out_grad_dims_1 = phi::vectorize<int>(out_grad_dims);
std::vector<int> out_grad_dims_2(out_grad_dims_1.begin() + 1,
out_grad_dims_1.end());
out_grad_dims_2.insert(out_grad_dims_2.begin(), x_grad_dims[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

虽然这里的计算开销相对较小,不过建议是使用emplace

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

}
ctx.template Alloc<T>(out);
T* out_data = out->data<T>();
if (index_size == 0) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

cudaMemset(y_grad_data, 0, memset_bytes_y);
#endif

if (index_size == 0) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

bcast_info.use_bcast,
mul_functor,
sum_functor);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

这里有个疑问,为什么MUL ADD两种聚合的方式的代码为什么不写在一起,在有些分支上可以ADD MUL来区分

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这么写逻辑更加清晰,而且看代码只有在 reduce_sum的地方有点重复,其他部分是不太一样的。

Copy link
Contributor

@wawltor wawltor left a comment

Choose a reason for hiding this comment

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

LGTM

@ZeyuChen ZeyuChen merged commit 88724a5 into PaddlePaddle:develop Aug 16, 2022
DesmonDay added a commit to DesmonDay/Paddle that referenced this pull request Oct 13, 2022
* initial commit

* fix op maker bug

* fix mul grad bug

* add unittest

* fix add grad bug, add cpu kernel

* add paddle.geometric.message_passing

* add paddle.geometric.send_uv api, add unittest

* add fp16 judgement

* fix file typo, move compute_type to message_op

* add impl file

* fix unittest timeout time

* add review revise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants