Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
6f4bd0ea
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6f4bd0ea
编写于
4月 06, 2022
作者:
Y
YuanRisheng
提交者:
GitHub
4月 06, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Phi]Add graph_send_recv yaml file (#41206)
* add graph_send_recv yaml * deal with confict * fix compile bugs
上级
0c968b9d
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
93 addition
and
21 deletion
+93
-21
paddle/phi/kernels/cpu/graph_send_recv_grad_kernel.cc
paddle/phi/kernels/cpu/graph_send_recv_grad_kernel.cc
+2
-2
paddle/phi/kernels/gpu/graph_send_recv_grad_kernel.cu
paddle/phi/kernels/gpu/graph_send_recv_grad_kernel.cu
+2
-2
paddle/phi/kernels/graph_send_recv_grad_kernel.h
paddle/phi/kernels/graph_send_recv_grad_kernel.h
+2
-2
paddle/phi/ops/compat/graph_send_recv_sig.cc
paddle/phi/ops/compat/graph_send_recv_sig.cc
+1
-1
python/paddle/fluid/dygraph/tracer.py
python/paddle/fluid/dygraph/tracer.py
+8
-0
python/paddle/fluid/tests/unittests/test_graph_send_recv_op.py
...n/paddle/fluid/tests/unittests/test_graph_send_recv_op.py
+35
-8
python/paddle/incubate/operators/graph_send_recv.py
python/paddle/incubate/operators/graph_send_recv.py
+20
-5
python/paddle/utils/code_gen/api.yaml
python/paddle/utils/code_gen/api.yaml
+12
-1
python/paddle/utils/code_gen/backward.yaml
python/paddle/utils/code_gen/backward.yaml
+11
-0
未找到文件。
paddle/phi/kernels/cpu/graph_send_recv_grad_kernel.cc
浏览文件 @
6f4bd0ea
...
...
@@ -118,12 +118,12 @@ void GraphSendRecvGradOpKernelLaunchHelper(
template
<
typename
T
,
typename
Context
>
void
GraphSendRecvGradKernel
(
const
Context
&
ctx
,
const
DenseTensor
&
out_grad
,
const
DenseTensor
&
x
,
paddle
::
optional
<
const
DenseTensor
&>
out
,
const
DenseTensor
&
src_index
,
const
DenseTensor
&
dst_index
,
paddle
::
optional
<
const
DenseTensor
&>
out
,
paddle
::
optional
<
const
DenseTensor
&>
dst_count
,
const
DenseTensor
&
out_grad
,
const
std
::
string
&
pool_type
,
DenseTensor
*
x_grad
)
{
auto
index_type
=
src_index
.
dtype
();
...
...
paddle/phi/kernels/gpu/graph_send_recv_grad_kernel.cu
浏览文件 @
6f4bd0ea
...
...
@@ -102,12 +102,12 @@ void GraphSendRecvGradOpCUDAKernelLaunchHelper(
template
<
typename
T
,
typename
Context
>
void
GraphSendRecvGradKernel
(
const
Context
&
ctx
,
const
DenseTensor
&
out_grad
,
const
DenseTensor
&
x
,
paddle
::
optional
<
const
DenseTensor
&>
out
,
const
DenseTensor
&
src_index
,
const
DenseTensor
&
dst_index
,
paddle
::
optional
<
const
DenseTensor
&>
out
,
paddle
::
optional
<
const
DenseTensor
&>
dst_count
,
const
DenseTensor
&
out_grad
,
const
std
::
string
&
pool_type
,
DenseTensor
*
x_grad
)
{
auto
index_type
=
src_index
.
dtype
();
...
...
paddle/phi/kernels/graph_send_recv_grad_kernel.h
浏览文件 @
6f4bd0ea
...
...
@@ -22,12 +22,12 @@ namespace phi {
template
<
typename
T
,
typename
Context
>
void
GraphSendRecvGradKernel
(
const
Context
&
ctx
,
const
DenseTensor
&
out_grad
,
const
DenseTensor
&
x
,
paddle
::
optional
<
const
DenseTensor
&>
out
,
const
DenseTensor
&
src_index
,
const
DenseTensor
&
dst_index
,
paddle
::
optional
<
const
DenseTensor
&>
out
,
paddle
::
optional
<
const
DenseTensor
&>
dst_count
,
const
DenseTensor
&
out_grad
,
const
std
::
string
&
pool_type
,
DenseTensor
*
x_grad
);
}
// namespace phi
paddle/phi/ops/compat/graph_send_recv_sig.cc
浏览文件 @
6f4bd0ea
...
...
@@ -28,7 +28,7 @@ KernelSignature GraphSendRecvGradOpArgumentMapping(
const
ArgumentMappingContext
&
ctx
)
{
return
KernelSignature
(
"graph_send_recv_grad"
,
{
GradVarName
(
"Out"
),
"X"
,
"Out"
,
"Src_index"
,
"Dst_index"
,
"Dst_count"
},
{
"X"
,
"Src_index"
,
"Dst_index"
,
"Out"
,
"Dst_count"
,
GradVarName
(
"Out"
)
},
{
"pool_type"
},
{
GradVarName
(
"X"
)});
}
...
...
python/paddle/fluid/dygraph/tracer.py
浏览文件 @
6f4bd0ea
...
...
@@ -22,6 +22,14 @@ from paddle.fluid import framework
from
paddle
import
_C_ops
final_state_name_mapping
=
{
"graph_send_recv"
:
{
"final_op_name"
:
"final_state_graph_send_recv"
,
"x"
:
"X"
,
"src_index"
:
"Src_index"
,
"dst_index"
:
"Dst_index"
,
"out"
:
"Out"
,
"dst_count"
:
"Dst_count"
},
"matmul_v2"
:
{
"final_op_name"
:
"final_state_matmul"
,
"transpose_x"
:
"trans_x"
,
...
...
python/paddle/fluid/tests/unittests/test_graph_send_recv_op.py
浏览文件 @
6f4bd0ea
...
...
@@ -17,13 +17,26 @@ import unittest
import
numpy
as
np
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid.framework
import
_test_eager_guard
from
op_test
import
OpTest
def
graph_send_recv_wrapper
(
x
,
src_index
,
dst_index
,
pool_type
=
"sum"
,
out_size
=
None
,
name
=
None
):
return
paddle
.
incubate
.
graph_send_recv
(
x
,
src_index
,
dst_index
,
pool_type
.
lower
(),
out_size
,
name
)
class
TestGraphSendRecvMaxOp
(
OpTest
):
def
setUp
(
self
):
paddle
.
enable_static
()
self
.
python_api
=
graph_send_recv_wrapper
self
.
python_out_sig
=
[
"Out"
]
self
.
op_type
=
"graph_send_recv"
x
=
np
.
random
.
random
((
10
,
20
)).
astype
(
"float64"
)
index
=
np
.
random
.
randint
(
0
,
10
,
(
15
,
2
)).
astype
(
np
.
int64
)
...
...
@@ -39,15 +52,18 @@ class TestGraphSendRecvMaxOp(OpTest):
self
.
outputs
=
{
'Out'
:
out
}
def
test_check_output
(
self
):
self
.
check_output
()
self
.
check_output
(
check_eager
=
True
)
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
user_defined_grads
=
[
self
.
gradient
])
self
.
check_grad
(
[
'X'
],
'Out'
,
user_defined_grads
=
[
self
.
gradient
],
check_eager
=
True
)
class
TestGraphSendRecvMinOp
(
OpTest
):
def
setUp
(
self
):
paddle
.
enable_static
()
self
.
python_api
=
graph_send_recv_wrapper
self
.
python_out_sig
=
[
"Out"
]
self
.
op_type
=
"graph_send_recv"
x
=
np
.
random
.
random
((
10
,
20
)).
astype
(
"float64"
)
index
=
np
.
random
.
randint
(
0
,
10
,
(
15
,
2
)).
astype
(
np
.
int64
)
...
...
@@ -64,15 +80,18 @@ class TestGraphSendRecvMinOp(OpTest):
self
.
outputs
=
{
'Out'
:
out
}
def
test_check_output
(
self
):
self
.
check_output
()
self
.
check_output
(
check_eager
=
True
)
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
user_defined_grads
=
[
self
.
gradient
])
self
.
check_grad
(
[
'X'
],
'Out'
,
user_defined_grads
=
[
self
.
gradient
],
check_eager
=
True
)
class
TestGraphSendRecvSumOp
(
OpTest
):
def
setUp
(
self
):
paddle
.
enable_static
()
self
.
python_api
=
graph_send_recv_wrapper
self
.
python_out_sig
=
[
"Out"
]
self
.
op_type
=
"graph_send_recv"
x
=
np
.
random
.
random
((
10
,
20
)).
astype
(
"float64"
)
index
=
np
.
random
.
randint
(
0
,
10
,
(
15
,
2
)).
astype
(
np
.
int64
)
...
...
@@ -88,15 +107,17 @@ class TestGraphSendRecvSumOp(OpTest):
self
.
outputs
=
{
'Out'
:
out
}
def
test_check_output
(
self
):
self
.
check_output
()
self
.
check_output
(
check_eager
=
True
)
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
)
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
True
)
class
TestGraphSendRecvMeanOp
(
OpTest
):
def
setUp
(
self
):
paddle
.
enable_static
()
self
.
python_api
=
graph_send_recv_wrapper
self
.
python_out_sig
=
[
"Out"
]
self
.
op_type
=
"graph_send_recv"
x
=
np
.
random
.
random
((
10
,
20
)).
astype
(
"float64"
)
index
=
np
.
random
.
randint
(
0
,
10
,
(
15
,
2
)).
astype
(
np
.
int64
)
...
...
@@ -113,10 +134,10 @@ class TestGraphSendRecvMeanOp(OpTest):
self
.
outputs
=
{
'Out'
:
out
,
'Dst_count'
:
dst_count
}
def
test_check_output
(
self
):
self
.
check_output
()
self
.
check_output
(
check_eager
=
True
)
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
)
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
True
)
def
compute_graph_send_recv_for_sum_mean
(
inputs
,
attributes
):
...
...
@@ -333,6 +354,12 @@ class API_GraphSendRecvOpTest(unittest.TestCase):
{}
\n
{}, check diff!"
.
format
(
np_res_set_outsize
,
res_set_outsize
))
def
test_api_eager_dygraph
(
self
):
with
_test_eager_guard
():
self
.
test_dygraph
()
self
.
test_int32_input
()
self
.
test_set_outsize_gpu
()
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/incubate/operators/graph_send_recv.py
浏览文件 @
6f4bd0ea
...
...
@@ -13,7 +13,7 @@
# limitations under the License.
from
paddle.fluid.layer_helper
import
LayerHelper
from
paddle.fluid.framework
import
_non_static_mode
from
paddle.fluid.framework
import
_non_static_mode
,
_in_legacy_dygraph
,
in_dygraph_mode
from
paddle.fluid.data_feeder
import
check_variable_and_dtype
from
paddle.fluid
import
core
from
paddle
import
_C_ops
...
...
@@ -109,15 +109,30 @@ def graph_send_recv(x,
# TODO(daisiming): Should we add judgement for out_size: max(dst_index) + 1.
if
_non_static_mode
()
:
if
out_size
is
None
or
out_size
<=
0
:
if
out_size
is
None
or
out_size
<=
0
:
if
_in_legacy_dygraph
()
:
out
,
tmp
=
_C_ops
.
graph_send_recv
(
x
,
src_index
,
dst_index
,
'pool_type'
,
pool_type
.
upper
())
else
:
return
out
if
in_dygraph_mode
():
return
_C_ops
.
final_state_graph_send_recv
(
x
,
src_index
,
dst_index
,
pool_type
.
upper
(),
0
)
else
:
if
_in_legacy_dygraph
():
out
,
tmp
=
_C_ops
.
graph_send_recv
(
x
,
src_index
,
dst_index
,
'pool_type'
,
pool_type
.
upper
(),
'out_size'
,
out_size
)
return
out
return
out
if
in_dygraph_mode
():
if
isinstance
(
out_size
,
core
.
eager
.
Tensor
):
if
(
out_size
.
size
<
1
):
raise
ValueError
(
"out_size should be long type, but received Tensor type."
)
out_size
=
out_size
.
numpy
()[
0
]
return
_C_ops
.
final_state_graph_send_recv
(
x
,
src_index
,
dst_index
,
pool_type
.
upper
(),
out_size
)
check_variable_and_dtype
(
x
,
"X"
,
(
"float32"
,
"float64"
,
"int32"
,
"int64"
),
"graph_send_recv"
)
...
...
python/paddle/utils/code_gen/api.yaml
浏览文件 @
6f4bd0ea
...
...
@@ -756,6 +756,17 @@
func
:
gelu
backward
:
gelu_grad
-
api
:
graph_send_recv
args
:
(Tensor x, Tensor src_index, Tensor dst_index, str pool_type = "SUM", int64_t out_size = 0)
output
:
Tensor(out), Tensor(dst_count)
infer_meta
:
func
:
GraphSendRecvInferMeta
kernel
:
func
:
graph_send_recv
data_type
:
x
intermediate
:
dst_count
backward
:
graph_send_recv_grad
-
api
:
greater_equal
args
:
(Tensor x, Tensor y, int axis = -1)
output
:
Tensor
...
...
@@ -1162,7 +1173,7 @@
kernel
:
func
:
mean_all
backward
:
mean_all_grad
-
api
:
meshgrid
args
:
(Tensor[] inputs)
output
:
Tensor[]
...
...
python/paddle/utils/code_gen/backward.yaml
浏览文件 @
6f4bd0ea
...
...
@@ -537,6 +537,17 @@
kernel
:
func
:
gelu_grad
-
backward_api
:
graph_send_recv_grad
forward
:
graph_send_recv (Tensor x, Tensor src_index, Tensor dst_index, str pool_type = "SUM", int64_t out_size = 0) -> Tensor(out), Tensor(dst_count)
args
:
(Tensor x, Tensor src_index, Tensor dst_index, Tensor out, Tensor dst_count, Tensor out_grad, str pool_type = "SUM")
output
:
Tensor(x_grad)
infer_meta
:
func
:
GeneralUnaryGradInferMeta
param
:
[
x
]
kernel
:
func
:
graph_send_recv_grad
optional
:
out, dst_count
-
backward_api
:
hard_shrink_grad
forward
:
hard_shrink (Tensor x, float threshold) -> Tensor(out)
args
:
(Tensor x, Tensor out_grad, float threshold)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录