Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
d33e99fe
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
d33e99fe
编写于
11月 04, 2021
作者:
H
huangxu96
提交者:
GitHub
11月 04, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
static cost model (#36775)
Add Static CostModel. Static data is based on op benchmark system
上级
bf2839f5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
81 addition
and
9 deletion
+81
-9
python/paddle/cost_model/__init__.py
python/paddle/cost_model/__init__.py
+16
-0
python/paddle/cost_model/cost_model.py
python/paddle/cost_model/cost_model.py
+26
-9
python/paddle/cost_model/static_op_benchmark.json
python/paddle/cost_model/static_op_benchmark.json
+1
-0
python/paddle/fluid/tests/unittests/test_cost_model.py
python/paddle/fluid/tests/unittests/test_cost_model.py
+36
-0
python/setup.py.in
python/setup.py.in
+2
-0
未找到文件。
python/paddle/cost_model/__init__.py
0 → 100644
浏览文件 @
d33e99fe
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
.cost_model
import
CostModel
# noqa: F401
__all__
=
[
'CostModel'
]
python/paddle/cost_model/cost_model.py
浏览文件 @
d33e99fe
...
...
@@ -15,6 +15,8 @@
import
paddle
import
paddle.static
as
static
import
numpy
as
np
import
json
import
os
from
paddle.fluid
import
core
...
...
@@ -36,7 +38,6 @@ class CostModel():
paddle
.
optimizer
.
SGD
(
learning_rate
=
0.01
).
minimize
(
loss
)
print
(
"main program is: {}"
.
format
(
main_program
))
#print("start up program is: {}".format(startup_program))
return
startup_program
,
main_program
...
...
@@ -44,7 +45,7 @@ class CostModel():
startup_program
,
main_program
,
device
=
'gpu'
,
fetch_cost_list
=
[
'time'
,
'memory'
]):
fetch_cost_list
=
[
'time'
]):
place
=
paddle
.
set_device
(
'gpu'
)
x
=
np
.
random
.
random
(
size
=
(
10
,
1
)).
astype
(
'float32'
)
...
...
@@ -53,17 +54,33 @@ class CostModel():
exe
.
run
(
startup_program
)
paddle
.
fluid
.
profiler
.
start_profiler
(
"All"
)
exe
.
run
(
main_program
,
feed
=
{
"X"
:
x
},
fetch_list
=
[])
# core.CostModel.ProfileMeasure(main_program, device)
print
(
"core:<<<<<<<"
)
cost_model
=
core
.
CostModel
()
cost_data
=
cost_model
.
ProfileMeasure
(
device
)
# cost_list = self.stop_cost_model()
# return cost_list
def
static_cost_data
(
self
):
static_cost_data_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"static_op_benchmark.json"
)
with
open
(
static_cost_data_path
,
'r'
)
as
load_f
:
load_dict
=
json
.
load
(
load_f
)
self
.
_static_cost_data
=
load_dict
# return all static cost data
return
load_dict
cost_model
=
CostModel
()
def
get_static_op_time
(
self
,
op_name
,
forward
=
True
,
dtype
=
"float32"
):
# if forward is True, return op forward time, otherwise return op backward time.
if
op_name
==
None
:
raise
ValueError
(
'op_name should not be empty when you want to get static op time'
)
startup_program
,
main_program
=
cost_model
.
build_program
()
op_cost
=
{}
for
op_data
in
self
.
_static_cost_data
:
if
(
op_data
[
"op"
]
==
op_name
)
and
(
dtype
in
op_data
[
"config"
]):
if
(
forward
):
op_cost
[
"op_time"
]
=
op_data
[
"paddle_gpu_time"
]
else
:
op_cost
[
"op_time"
]
=
op_data
[
"paddle_gpu_time_backward"
]
op_cost
[
"config"
]
=
op_data
[
"config"
]
cost_model
.
profile_measure
(
startup_program
,
main_program
)
return
op_cost
python/paddle/cost_model/static_op_benchmark.json
0 → 100644
浏览文件 @
d33e99fe
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
python/paddle/fluid/tests/unittests/test_cost_model.py
浏览文件 @
d33e99fe
...
...
@@ -18,6 +18,7 @@ import unittest
import
paddle
import
paddle.fluid.core
as
core
from
paddle.cost_model
import
CostModel
paddle
.
enable_static
()
...
...
@@ -51,6 +52,41 @@ class TestCostModel(unittest.TestCase):
self
.
assertGreaterEqual
(
cost_data
.
get_whole_time_ms
(),
fc_op_time
+
mean_op_time
)
def
test_static_op_benchmark_cost_model
(
self
):
op_name
=
"abs"
cost_model
=
CostModel
()
# init static data
cost_model
.
static_cost_data
()
op_name
=
"abs"
abs_op_cost
=
cost_model
.
get_static_op_time
(
op_name
)
abs_op_time
=
abs_op_cost
[
"op_time"
]
abs_op_config
=
abs_op_cost
[
"config"
]
print
(
"abs_op_time:"
,
abs_op_time
)
print
(
"abs_op_config:"
,
abs_op_config
)
self
.
assertGreater
(
float
(
abs_op_time
),
0
)
conv2d_op_cost
=
cost_model
.
get_static_op_time
(
"conv2d"
)
conv2d_op_time
=
conv2d_op_cost
[
"op_time"
]
conv2d_op_config
=
conv2d_op_cost
[
"config"
]
self
.
assertGreater
(
float
(
conv2d_op_time
),
0
)
print
(
"conv2d_op_time:"
,
conv2d_op_time
)
print
(
"conv2d_op_config:"
,
conv2d_op_config
)
conv2d_backward_op_cost
=
cost_model
.
get_static_op_time
(
"conv2d"
,
forward
=
False
)
conv2d_backward_op_time
=
conv2d_backward_op_cost
[
"op_time"
]
conv2d_backward_op_config
=
conv2d_backward_op_cost
[
"config"
]
self
.
assertGreater
(
float
(
conv2d_backward_op_time
),
0
)
print
(
"conv2d_backward_op_time:"
,
conv2d_backward_op_time
)
print
(
"conv2d_backward_op_config:"
,
conv2d_backward_op_config
)
conv2d_fp16_op_cost
=
cost_model
.
get_static_op_time
(
"conv2d"
,
dtype
=
"float16"
)
conv2d_fp16_op_time
=
conv2d_fp16_op_cost
[
"op_time"
]
conv2d_fp16_op_config
=
conv2d_fp16_op_cost
[
"config"
]
self
.
assertGreater
(
float
(
conv2d_fp16_op_time
),
0
)
print
(
"conv2d_fp16_op_time:"
,
conv2d_fp16_op_time
)
print
(
"conv2d_fp16_op_config:"
,
conv2d_fp16_op_config
)
if
__name__
==
'__main__'
:
unittest
.
main
()
python/setup.py.in
浏览文件 @
d33e99fe
...
...
@@ -334,6 +334,7 @@ packages=['paddle',
'paddle.fluid.incubate.fleet.collective',
'paddle.fluid.incubate.fleet.utils',
'paddle.amp',
'paddle.cost_model',
'paddle.hapi',
'paddle.vision',
'paddle.vision.models',
...
...
@@ -404,6 +405,7 @@ if os.name != 'nt':
else:
package_data={'paddle.fluid': ['${FLUID_CORE_NAME}' + '.pyd', '${FLUID_CORE_NAME}' + '.lib']}
package_data['paddle.fluid'] += ['${PADDLE_BINARY_DIR}/python/paddle/cost_model/static_op_benchmark.json']
if '${HAS_NOAVX_CORE}' == 'ON':
package_data['paddle.fluid'] += ['core_noavx' + ('.so' if os.name != 'nt' else '.pyd')]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录