Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c7ba0312
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看板
未验证
提交
c7ba0312
编写于
7月 18, 2023
作者:
H
HongyuJia
提交者:
GitHub
7月 18, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[0D-Tensor] CINN supports softmax and flip, fix infershape (#55470)
上级
922d2481
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
6 deletion
+44
-6
paddle/cinn/hlir/op/nn.cc
paddle/cinn/hlir/op/nn.cc
+3
-6
test/cinn/ops/test_zero_dim_tensor.py
test/cinn/ops/test_zero_dim_tensor.py
+41
-0
未找到文件。
paddle/cinn/hlir/op/nn.cc
浏览文件 @
c7ba0312
...
...
@@ -73,8 +73,7 @@ std::shared_ptr<OpStrategy> StrategyForRelu(
std
::
vector
<
framework
::
shape_t
>
InferShapeForRelu
(
const
std
::
vector
<
framework
::
shape_t
>
&
inputs_shape
,
const
framework
::
AttrMapType
&
attrs
)
{
CHECK
(
!
inputs_shape
.
empty
())
<<
"The input's shape is empty! Please check again."
;
CHECK
(
!
inputs_shape
.
empty
())
<<
"The inputs is empty! Please check again."
;
std
::
vector
<
framework
::
shape_t
>
res
{
inputs_shape
[
0
]};
return
res
;
}
...
...
@@ -1979,8 +1978,7 @@ std::shared_ptr<OpStrategy> StrategyForSoftmax(
std
::
vector
<
std
::
vector
<
int
>>
InferShapeForSoftmax
(
const
std
::
vector
<
std
::
vector
<
int
>>
&
inputs_shape
,
const
framework
::
AttrMapType
&
attrs
)
{
CHECK
(
!
inputs_shape
.
empty
()
&&
!
inputs_shape
[
0
].
empty
())
<<
"The input's shape size is 0! Please check again."
;
CHECK
(
!
inputs_shape
.
empty
())
<<
"The inputs is empty! Please check again."
;
std
::
vector
<
std
::
vector
<
int
>>
res
{
inputs_shape
[
0
]};
return
res
;
}
...
...
@@ -2057,8 +2055,7 @@ std::shared_ptr<OpStrategy> StrategyForDropoutInfer(
std
::
vector
<
std
::
vector
<
int
>>
InferShapeForDropoutInfer
(
const
std
::
vector
<
std
::
vector
<
int
>>
&
inputs_shape
,
const
framework
::
AttrMapType
&
attrs
)
{
CHECK
(
!
inputs_shape
.
empty
())
<<
"The input's shape size is 0! Please check again."
;
CHECK
(
!
inputs_shape
.
empty
())
<<
"The inputs is empty! Please check again."
;
float
dropout_prob
=
0
;
std
::
string
dropout_implementation
=
"downgrade_in_infer"
;
for
(
auto
&
iter
:
attrs
)
{
...
...
test/cinn/ops/test_zero_dim_tensor.py
浏览文件 @
c7ba0312
...
...
@@ -575,6 +575,9 @@ create_unit_test(TestUnaryOp, "abs", paddle.abs, "builder.abs")
create_unit_test
(
TestUnaryOp
,
"reciprocal"
,
paddle
.
reciprocal
,
"builder.reciprocal"
)
create_unit_test
(
TestUnaryOp
,
"softmax"
,
paddle
.
nn
.
functional
.
softmax
,
"builder.softmax"
)
# acosh requires input value > 1.0, specific init_input instead of using create_unit_test
...
...
@@ -1118,5 +1121,43 @@ class TestMatmulOp(OpTest):
self
.
check_outputs_and_grads
()
@
OpTestTool
.
skip_if
(
not
is_compiled_with_cuda
(),
"x86 test will be skipped due to timeout."
)
class
TestFlipOp
(
OpTest
):
def
setUp
(
self
):
np
.
random
.
seed
(
2023
)
self
.
dtype
=
"float32"
self
.
init_input
()
def
init_input
(
self
):
self
.
inputs
=
{
"x"
:
np
.
random
.
randint
(
-
10
,
10
,
[]).
astype
(
self
.
dtype
),
}
self
.
target_shape
=
()
def
build_paddle_program
(
self
,
target
):
x
=
paddle
.
to_tensor
(
self
.
inputs
[
"x"
],
stop_gradient
=
False
)
out
=
paddle
.
flip
(
x
,
axis
=
[])
self
.
paddle_outputs
=
[
out
]
def
build_cinn_program
(
self
,
target
):
builder
=
NetBuilder
(
"flip_op"
)
x
=
builder
.
create_input
(
cinn_dtype_convert
(
self
.
dtype
),
self
.
inputs
[
"x"
].
shape
,
"x"
)
out
=
builder
.
flip
(
x
,
[])
prog
=
builder
.
build
()
res
=
self
.
get_cinn_output
(
prog
,
target
,
[
x
],
[
self
.
inputs
[
"x"
]],
[
out
])
self
.
cinn_outputs
=
res
self
.
assertEqual
(
res
[
0
].
shape
,
self
.
target_shape
)
def
test_check_results
(
self
):
self
.
check_outputs_and_grads
()
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录