Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ed19d37f
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,发现更多精彩内容 >>
未验证
提交
ed19d37f
编写于
3月 13, 2023
作者:
M
mengziheng
提交者:
GitHub
3月 13, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Unsqueeze op composite rule (#51527)
* first test * add unsqueeze_op
上级
b76ab792
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
29 addition
and
2 deletion
+29
-2
python/paddle/fluid/tests/unittests/CMakeLists.txt
python/paddle/fluid/tests/unittests/CMakeLists.txt
+2
-1
python/paddle/fluid/tests/unittests/test_unsqueeze2_op.py
python/paddle/fluid/tests/unittests/test_unsqueeze2_op.py
+7
-1
python/paddle/incubate/autograd/composite_rules.py
python/paddle/incubate/autograd/composite_rules.py
+20
-0
未找到文件。
python/paddle/fluid/tests/unittests/CMakeLists.txt
浏览文件 @
ed19d37f
...
...
@@ -1215,7 +1215,8 @@ set(TEST_CINN_OPS
test_elementwise_pow_op
test_transpose_op
test_reshape_op
test_mean_op
)
test_mean_op
test_unsqueeze2_op
)
foreach
(
TEST_CINN_OPS
${
TEST_CINN_OPS
}
)
if
(
WITH_CINN
)
...
...
python/paddle/fluid/tests/unittests/test_unsqueeze2_op.py
浏览文件 @
ed19d37f
...
...
@@ -36,9 +36,12 @@ class TestUnsqueezeOp(OpTest):
"Out"
:
self
.
inputs
[
"X"
].
reshape
(
self
.
new_shape
),
"XShape"
:
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
"float64"
),
}
self
.
prim_op_type
=
"comp"
def
test_check_output
(
self
):
self
.
check_output
(
no_check_set
=
[
"XShape"
],
check_eager
=
True
)
self
.
check_output
(
no_check_set
=
[
"XShape"
],
check_eager
=
True
,
check_prim
=
True
)
def
test_check_grad
(
self
):
self
.
check_grad
([
"X"
],
"Out"
,
check_eager
=
True
)
...
...
@@ -89,6 +92,7 @@ class TestUnsqueezeOp_ZeroDim1(TestUnsqueezeOp):
self
.
ori_shape
=
()
self
.
axes
=
(
-
1
,)
self
.
new_shape
=
1
self
.
enable_cinn
=
False
class
TestUnsqueezeOp_ZeroDim2
(
TestUnsqueezeOp
):
...
...
@@ -96,6 +100,7 @@ class TestUnsqueezeOp_ZeroDim2(TestUnsqueezeOp):
self
.
ori_shape
=
()
self
.
axes
=
(
-
1
,
1
)
self
.
new_shape
=
(
1
,
1
)
self
.
enable_cinn
=
False
class
TestUnsqueezeOp_ZeroDim3
(
TestUnsqueezeOp
):
...
...
@@ -103,6 +108,7 @@ class TestUnsqueezeOp_ZeroDim3(TestUnsqueezeOp):
self
.
ori_shape
=
()
self
.
axes
=
(
0
,
1
,
2
)
self
.
new_shape
=
(
1
,
1
,
1
)
self
.
enable_cinn
=
False
# axes is a list(with tensor)
...
...
python/paddle/incubate/autograd/composite_rules.py
浏览文件 @
ed19d37f
...
...
@@ -371,3 +371,23 @@ def relu_composite(x):
"""define composite rule of op relu."""
# relu(x) = max(x, 0)
return
maximum
(
x
,
zeros_like
(
x
))
@
REGISTER_COMPOSITE
(
'unsqueeze2'
)
def
unsqueeze_composite
(
x
,
axis
):
"""define composite rule of op unsqueeze"""
"""using reshape to implement unsqueeze op"""
x_shape
=
list
(
x
.
shape
)
axis_list
=
list
(
axis
)
for
i
in
axis_list
:
if
i
<
0
:
i
+=
len
(
x_shape
)
+
1
x_shape
=
(
x_shape
[:
i
]
+
[
1
,
]
+
x_shape
[
i
:]
)
out
=
reshape
(
x
,
x_shape
)
return
[
out
,
None
]
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录