Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c5137b22
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
c5137b22
编写于
1月 03, 2023
作者:
J
Jianghai
提交者:
GitHub
1月 03, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Auto Parallel] Add All Relu Flops (#48083)
* relu flops all * add annotations and tests * revision for codestyle
上级
18c0a002
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
87 addition
and
10 deletion
+87
-10
python/paddle/fluid/tests/unittests/test_profiler.py
python/paddle/fluid/tests/unittests/test_profiler.py
+50
-3
python/paddle/utils/flops.py
python/paddle/utils/flops.py
+37
-7
未找到文件。
python/paddle/fluid/tests/unittests/test_profiler.py
浏览文件 @
c5137b22
...
...
@@ -293,9 +293,6 @@ class TestFLOPSAPI(unittest.TestCase):
)
==
3
*
12
*
12
*
12
*
2
*
8
)
self
.
assertTrue
(
flops
(
'relu'
,
{
'X'
:
[[
12
,
12
,
12
]]},
{})
==
12
*
12
*
12
)
self
.
assertTrue
(
flops
(
'softmax'
,
{
'X'
:
[[
12
,
12
,
12
]]},
{})
==
3
*
12
*
12
*
12
)
...
...
@@ -303,6 +300,56 @@ class TestFLOPSAPI(unittest.TestCase):
flops
(
'c_embedding'
,
{
'Ids'
:
[[
12
,
12
]],
'W'
:
[[
12
,
12
,
3
]]},
{})
==
0
)
self
.
assertTrue
(
flops
(
'elu'
,
{
'X'
:
[[
12
,
12
]],
},
{},
)
==
144
)
self
.
assertTrue
(
flops
(
'leaky_relu'
,
{
'X'
:
[[
12
,
12
]],
},
{},
)
==
144
)
self
.
assertTrue
(
flops
(
'prelu'
,
{
'X'
:
[[
12
,
12
]],
},
{},
)
==
144
)
self
.
assertTrue
(
flops
(
'relu6'
,
{
'X'
:
[[
12
,
12
]],
},
{},
)
==
144
)
self
.
assertTrue
(
flops
(
'silu'
,
{
'X'
:
[[
12
,
12
]],
},
{},
)
==
144
)
if
__name__
==
'__main__'
:
...
...
python/paddle/utils/flops.py
浏览文件 @
c5137b22
...
...
@@ -73,7 +73,7 @@ def _c_embedding_flops(input_shapes, attrs):
def
_dropout_flops
(
input_shapes
,
attrs
):
"""FLOPs computation for dropout op.
For dropout(input):
equation: flops = 0
equation: flops = 0
"""
return
0
...
...
@@ -191,7 +191,7 @@ def _matmul_v2_flops(input_shapes, attrs):
"""FLOPs computation for matmul_v2 op.
For matmul_v2(input,other):
input_shapes = [shape_of_input, shape_of_ohther]
shape_of_input = [dim1, dim2 ...dim_n_1, dim_n] length:n
shape_of_input =
[dim1, dim2 ...dim_n_1, dim_n] length:n
shape_of_other = [odim1, odim2 ... odim(n-m) ... odim_m_1, dim_m] length:m
suppose n > m and dim_n = odim_m_1:
shape_of_output = [dim1, dim2 ... max(dim(n-m), odim(n-m)), max(dim(n-m+1), odim(n-m+1))...dim_n_1, dim_m]
...
...
@@ -216,13 +216,43 @@ def _matmul_v2_flops(input_shapes, attrs):
return
2
*
macs
@
register_flops
(
"relu"
)
def
_relu_flops
(
input_shapes
,
attrs
):
"""FLOPs computation for relu op.
For relu(input):
def
_relu_class_flops
(
input_shapes
,
attrs
):
"""FLOPs computation for relu_like ops.
For elu/leaky_relu/prelu/relu/relu6/silu (input):
equation: flops = (numel)total number of elements in the input tensor.
"""
return
prod
(
input_shapes
.
get
(
'X'
)[
0
])
input
=
input_shapes
.
get
(
'X'
)[
0
]
return
prod
(
input
)
@
register_flops
(
"elu"
)
def
_elu_flops
(
input_shapes
,
attrs
):
return
_relu_class_flops
(
input_shapes
,
attrs
)
@
register_flops
(
"leaky_relu"
)
def
_leaky_relu_flops
(
input_shapes
,
attrs
):
return
_relu_class_flops
(
input_shapes
,
attrs
)
@
register_flops
(
"prelu"
)
def
_prelu_flops
(
input_shapes
,
attrs
):
return
_relu_class_flops
(
input_shapes
,
attrs
)
@
register_flops
(
"relu"
)
def
_relu_flops
(
input_shapes
,
attrs
):
return
_relu_class_flops
(
input_shapes
,
attrs
)
@
register_flops
(
"relu6"
)
def
_relu6_flops
(
input_shapes
,
attrs
):
return
_relu_class_flops
(
input_shapes
,
attrs
)
@
register_flops
(
"silu"
)
def
_silu_flops
(
input_shapes
,
attrs
):
return
_relu_class_flops
(
input_shapes
,
attrs
)
@
register_flops
(
"reshape2"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录