-
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_uv API #44848
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
@@ -0,0 +1,134 @@ | |||
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. |
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.
比较好奇这里的文件名为什么不在send_recv里面
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.
已放到 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. |
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.
注意一下这里float16是否已经支持了
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.
支持了
from paddle import _C_ops | ||
|
||
from .utils import reshape_lhs_rhs | ||
|
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.
加上 all = []
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.
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 |
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.
这里加上 all
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.
done
} | ||
ctx.template Alloc<T>(out); | ||
T* out_data = out->data<T>(); | ||
if (index_size == 0) return; |
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.
这里index_size为0,直接return 是否合适了,要么直接报错?直接return 看起来是一个未定义的行为
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.
修改成直接报错了
memset(x_grad_data, 0, memset_bytes_x); | ||
memset(y_grad_data, 0, memset_bytes_y); | ||
|
||
if (index_size == 0) return; |
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.
这里如果在前向Op进行处理,这里也可以直接报错
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.
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) { |
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.
这里有个讨论,这里是不是也可以直接加上out_grad_off,不管梯度是否为0;因为在多线程计算里面,看起来直接加法会比有分支更好
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.
主要是因为这里会涉及到一个原子操作,所以加上分支判断可以减少原子操作。
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]); |
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.
虽然这里的计算开销相对较小,不过建议是使用emplace
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.
已修改
} | ||
ctx.template Alloc<T>(out); | ||
T* out_data = out->data<T>(); | ||
if (index_size == 0) return; |
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.
同上
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.
done
cudaMemset(y_grad_data, 0, memset_bytes_y); | ||
#endif | ||
|
||
if (index_size == 0) return; |
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.
同上
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.
done
bcast_info.use_bcast, | ||
mul_functor, | ||
sum_functor); | ||
} else { |
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.
这里有个疑问,为什么MUL ADD两种聚合的方式的代码为什么不写在一起,在有些分支上可以ADD MUL来区分
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.
这么写逻辑更加清晰,而且看代码只有在 reduce_sum的地方有点重复,其他部分是不太一样的。
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.
LGTM
* 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
PR types
New features
PR changes
APIs
Describe
Add paddle.geometric.send_uv API, mainly used in graph learning domain.