Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
d3f95e5a
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
d3f95e5a
编写于
4月 19, 2022
作者:
C
chenjian
提交者:
GitHub
4月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reduce performance influence by RecordEvent in Python (#41822)
* reduce performance influence * add unit test * fix
上级
c9f4fcf3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
14 addition
and
0 deletion
+14
-0
python/paddle/fluid/tests/unittests/test_newprofiler.py
python/paddle/fluid/tests/unittests/test_newprofiler.py
+7
-0
python/paddle/profiler/profiler.py
python/paddle/profiler/profiler.py
+3
-0
python/paddle/profiler/utils.py
python/paddle/profiler/utils.py
+4
-0
未找到文件。
python/paddle/fluid/tests/unittests/test_newprofiler.py
浏览文件 @
d3f95e5a
...
...
@@ -20,6 +20,7 @@ import tempfile
import
paddle
import
paddle.profiler
as
profiler
import
paddle.profiler.utils
as
utils
import
paddle.nn
as
nn
import
paddle.nn.functional
as
F
from
paddle.io
import
Dataset
,
DataLoader
...
...
@@ -40,11 +41,17 @@ class TestProfiler(unittest.TestCase):
with
profiler
.
Profiler
(
targets
=
[
profiler
.
ProfilerTarget
.
CPU
],
)
as
prof
:
y
=
x
/
2.0
prof
=
None
self
.
assertEqual
(
utils
.
_is_profiler_used
,
False
)
with
profiler
.
RecordEvent
(
name
=
'test'
):
y
=
x
/
2.0
with
profiler
.
Profiler
(
targets
=
[
profiler
.
ProfilerTarget
.
CPU
],
scheduler
=
(
1
,
2
))
as
prof
:
self
.
assertEqual
(
utils
.
_is_profiler_used
,
True
)
with
profiler
.
RecordEvent
(
name
=
'test'
):
y
=
x
/
2.0
prof
=
None
with
profiler
.
Profiler
(
targets
=
[
profiler
.
ProfilerTarget
.
CPU
],
...
...
python/paddle/profiler/profiler.py
浏览文件 @
d3f95e5a
...
...
@@ -27,6 +27,7 @@ from paddle.fluid.core import (_Profiler, _ProfilerResult, ProfilerOptions,
from
.utils
import
RecordEvent
,
wrap_optimizers
from
.profiler_statistic
import
StatisticData
,
_build_table
,
SortedKeys
from
paddle.profiler
import
utils
from
.timer
import
benchmark
...
...
@@ -482,6 +483,7 @@ class Profiler:
if
self
.
timer_only
:
return
# CLOSED -> self.current_state
utils
.
_is_profiler_used
=
True
if
self
.
current_state
==
ProfilerState
.
READY
:
self
.
profiler
.
prepare
()
elif
self
.
current_state
==
ProfilerState
.
RECORD
:
...
...
@@ -534,6 +536,7 @@ class Profiler:
self
.
profiler_result
=
self
.
profiler
.
stop
()
if
self
.
on_trace_ready
:
self
.
on_trace_ready
(
self
)
utils
.
_is_profiler_used
=
False
def
step
(
self
,
num_samples
:
Optional
[
int
]
=
None
):
r
"""
...
...
python/paddle/profiler/utils.py
浏览文件 @
d3f95e5a
...
...
@@ -20,6 +20,8 @@ from contextlib import ContextDecorator
from
paddle.fluid
import
core
from
paddle.fluid.core
import
(
_RecordEvent
,
TracerEventType
)
_is_profiler_used
=
False
_AllowedEventTypeList
=
[
TracerEventType
.
Dataloader
,
TracerEventType
.
ProfileStep
,
TracerEventType
.
UserDefined
,
TracerEventType
.
Forward
,
...
...
@@ -91,6 +93,8 @@ class RecordEvent(ContextDecorator):
result = data1 - data2
record_event.end()
"""
if
not
_is_profiler_used
:
return
if
self
.
event_type
not
in
_AllowedEventTypeList
:
warn
(
"Only TracerEvent Type in [{}, {}, {}, {}, {}, {},{}]
\
can be recorded."
.
format
(
*
_AllowedEventTypeList
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录