Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
625e30b7
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,发现更多精彩内容 >>
未验证
提交
625e30b7
编写于
3月 03, 2023
作者:
W
wangxiaoning
提交者:
GitHub
3月 03, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add gather_nd_comp_grad composite rule (#50966)
* comp gather_nd_grad * fix * test no cinn * fix * fix cinn
上级
792531b6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
28 addition
and
6 deletion
+28
-6
paddle/fluid/prim/api/composite_backward/composite_backward_api.h
...luid/prim/api/composite_backward/composite_backward_api.h
+11
-0
paddle/phi/api/yaml/backward.yaml
paddle/phi/api/yaml/backward.yaml
+1
-0
python/paddle/fluid/tests/unittests/CMakeLists.txt
python/paddle/fluid/tests/unittests/CMakeLists.txt
+2
-1
python/paddle/fluid/tests/unittests/test_gather_nd_op.py
python/paddle/fluid/tests/unittests/test_gather_nd_op.py
+14
-5
未找到文件。
paddle/fluid/prim/api/composite_backward/composite_backward_api.h
浏览文件 @
625e30b7
...
...
@@ -786,7 +786,18 @@ void topk_grad(const Tensor& x,
if
(
x_grad
)
{
auto
zero_tensor
=
full
<
T
>
(
phi
::
vectorize
(
x
.
dims
()),
0.0
,
x
.
dtype
());
auto
x_grad_tmp
=
put_along_axis
<
T
>
(
zero_tensor
,
indices
,
out_grad
,
axis
);
set_output
<
T
>
(
x_grad_tmp
,
x_grad
);
}
}
template
<
typename
T
>
void
gather_nd_grad
(
const
Tensor
&
x
,
const
Tensor
&
index
,
const
Tensor
&
out_grad
,
Tensor
*
x_grad
)
{
if
(
x_grad
)
{
auto
zero_tensor
=
full
<
T
>
(
phi
::
vectorize
(
x
.
dims
()),
0.0
,
x
.
dtype
());
auto
x_grad_tmp
=
scatter_nd_add
<
T
>
(
zero_tensor
,
index
,
out_grad
);
set_output
<
T
>
(
x_grad_tmp
,
x_grad
);
}
}
...
...
paddle/phi/api/yaml/backward.yaml
浏览文件 @
625e30b7
...
...
@@ -565,6 +565,7 @@
func
:
GatherNdGradInferMeta
kernel
:
func
:
gather_nd_grad
composite
:
gather_nd_grad(x, index, out_grad, x_grad)
no_need_buffer
:
x
-
backward_op
:
gelu_grad
...
...
python/paddle/fluid/tests/unittests/CMakeLists.txt
浏览文件 @
625e30b7
...
...
@@ -1215,7 +1215,8 @@ set(TEST_CINN_OPS
test_elementwise_add_op
test_elementwise_sub_op
test_elementwise_div_op
test_elementwise_mul_op
)
test_elementwise_mul_op
test_gather_nd_op
)
foreach
(
TEST_CINN_OPS
${
TEST_CINN_OPS
}
)
if
(
WITH_CINN
)
...
...
python/paddle/fluid/tests/unittests/test_gather_nd_op.py
浏览文件 @
625e30b7
...
...
@@ -26,6 +26,7 @@ class TestGatherNdOpWithEmptyIndex(OpTest):
def
setUp
(
self
):
self
.
op_type
=
"gather_nd"
self
.
prim_op_type
=
"prim"
self
.
python_api
=
paddle
.
gather_nd
xnp
=
np
.
random
.
random
((
5
,
20
)).
astype
(
"float64"
)
self
.
inputs
=
{
'X'
:
xnp
,
'Index'
:
np
.
array
([[],
[]]).
astype
(
"int32"
)}
...
...
@@ -37,12 +38,13 @@ class TestGatherNdOpWithEmptyIndex(OpTest):
self
.
check_output
(
check_eager
=
False
)
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
False
)
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
False
,
check_prim
=
True
)
class
TestGatherNdOpWithIndex1
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"gather_nd"
self
.
prim_op_type
=
"prim"
self
.
python_api
=
paddle
.
gather_nd
xnp
=
np
.
random
.
random
((
5
,
20
)).
astype
(
"float64"
)
self
.
inputs
=
{
'X'
:
xnp
,
'Index'
:
np
.
array
([
1
]).
astype
(
"int32"
)}
...
...
@@ -60,7 +62,9 @@ class TestGatherNdOpWithLowIndex(OpTest):
def
setUp
(
self
):
self
.
op_type
=
"gather_nd"
self
.
prim_op_type
=
"prim"
self
.
python_api
=
paddle
.
gather_nd
self
.
enable_cinn
=
False
xnp
=
np
.
random
.
uniform
(
0
,
100
,
(
10
,
10
)).
astype
(
"float64"
)
index
=
np
.
array
([[
1
],
[
2
]]).
astype
(
"int64"
)
...
...
@@ -74,7 +78,7 @@ class TestGatherNdOpWithLowIndex(OpTest):
self
.
check_output
(
check_eager
=
False
)
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
False
)
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
False
,
check_prim
=
True
)
class
TestGatherNdOpIndex1
(
OpTest
):
...
...
@@ -82,6 +86,7 @@ class TestGatherNdOpIndex1(OpTest):
def
setUp
(
self
):
self
.
op_type
=
"gather_nd"
self
.
prim_op_type
=
"prim"
self
.
python_api
=
paddle
.
gather_nd
xnp
=
np
.
random
.
uniform
(
0
,
100
,
(
10
,
10
)).
astype
(
"float64"
)
index
=
np
.
array
([
1
,
2
]).
astype
(
"int32"
)
...
...
@@ -102,7 +107,9 @@ class TestGatherNdOpWithSameIndexAsX(OpTest):
def
setUp
(
self
):
self
.
op_type
=
"gather_nd"
self
.
prim_op_type
=
"prim"
self
.
python_api
=
paddle
.
gather_nd
self
.
enable_cinn
=
False
xnp
=
np
.
random
.
uniform
(
0
,
100
,
(
10
,
10
)).
astype
(
"float64"
)
index
=
np
.
array
([[
1
,
1
],
[
2
,
1
]]).
astype
(
"int64"
)
...
...
@@ -113,7 +120,7 @@ class TestGatherNdOpWithSameIndexAsX(OpTest):
self
.
check_output
(
check_eager
=
False
)
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
False
)
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
False
,
check_prim
=
True
)
class
TestGatherNdOpWithHighRankSame
(
OpTest
):
...
...
@@ -121,6 +128,7 @@ class TestGatherNdOpWithHighRankSame(OpTest):
def
setUp
(
self
):
self
.
op_type
=
"gather_nd"
self
.
prim_op_type
=
"prim"
self
.
python_api
=
paddle
.
gather_nd
shape
=
(
5
,
2
,
3
,
1
,
10
)
xnp
=
np
.
random
.
rand
(
*
shape
).
astype
(
"float64"
)
...
...
@@ -133,7 +141,7 @@ class TestGatherNdOpWithHighRankSame(OpTest):
self
.
check_output
(
check_eager
=
False
)
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
False
)
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
False
,
check_prim
=
True
)
class
TestGatherNdOpWithHighRankDiff
(
OpTest
):
...
...
@@ -141,6 +149,7 @@ class TestGatherNdOpWithHighRankDiff(OpTest):
def
setUp
(
self
):
self
.
op_type
=
"gather_nd"
self
.
prim_op_type
=
"prim"
self
.
python_api
=
paddle
.
gather_nd
shape
=
(
2
,
3
,
4
,
1
,
10
)
xnp
=
np
.
random
.
rand
(
*
shape
).
astype
(
"float64"
)
...
...
@@ -154,7 +163,7 @@ class TestGatherNdOpWithHighRankDiff(OpTest):
self
.
check_output
(
check_eager
=
False
)
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
False
)
self
.
check_grad
([
'X'
],
'Out'
,
check_eager
=
False
,
check_prim
=
True
)
# Test Python API
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录