Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cc1a1cbb
提交
cc1a1cbb
authored
6月 21, 2024
作者:
Virgile Andreani
提交者:
Ricardo Vieira
7月 03, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use defaultdict and Counter in profiling.py
上级
6e7a4310
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
23 行增加
和
42 行删除
+23
-42
profiling.py
pytensor/compile/profiling.py
+23
-40
vm.py
pytensor/link/vm.py
+0
-2
没有找到文件。
pytensor/compile/profiling.py
浏览文件 @
cc1a1cbb
...
@@ -14,9 +14,9 @@ import logging
...
@@ -14,9 +14,9 @@ import logging
import
operator
import
operator
import
sys
import
sys
import
time
import
time
from
collections
import
defaultdict
from
collections
import
Counter
,
defaultdict
from
contextlib
import
contextmanager
from
contextlib
import
contextmanager
from
typing
import
TYPE_CHECKING
,
Any
,
Union
from
typing
import
TYPE_CHECKING
,
Any
import
numpy
as
np
import
numpy
as
np
...
@@ -204,8 +204,8 @@ class ProfileStats:
...
@@ -204,8 +204,8 @@ class ProfileStats:
self
.
fct_call_time
=
0.0
self
.
fct_call_time
=
0.0
self
.
fct_callcount
=
0
self
.
fct_callcount
=
0
self
.
vm_call_time
=
0.0
self
.
vm_call_time
=
0.0
self
.
apply_time
=
{}
self
.
apply_time
=
defaultdict
(
float
)
self
.
apply_callcount
=
{}
self
.
apply_callcount
=
Counter
()
# self.apply_cimpl = None
# self.apply_cimpl = None
# self.message = None
# self.message = None
...
@@ -234,9 +234,9 @@ class ProfileStats:
...
@@ -234,9 +234,9 @@ class ProfileStats:
# Total time spent in Function.vm.__call__
# Total time spent in Function.vm.__call__
#
#
apply_time
:
dict
[
Union
[
"FunctionGraph"
,
Variable
],
float
]
|
None
=
None
apply_time
:
dict
[
tuple
[
"FunctionGraph"
,
Apply
],
float
]
apply_callcount
:
dict
[
Union
[
"FunctionGraph"
,
Variable
],
int
]
|
None
=
None
apply_callcount
:
dict
[
tuple
[
"FunctionGraph"
,
Apply
],
int
]
apply_cimpl
:
dict
[
Apply
,
bool
]
|
None
=
None
apply_cimpl
:
dict
[
Apply
,
bool
]
|
None
=
None
# dict from node -> bool (1 if c, 0 if py)
# dict from node -> bool (1 if c, 0 if py)
...
@@ -292,10 +292,9 @@ class ProfileStats:
...
@@ -292,10 +292,9 @@ class ProfileStats:
# param is called flag_time_thunks because most other attributes with time
# param is called flag_time_thunks because most other attributes with time
# in the name are times *of* something, rather than configuration flags.
# in the name are times *of* something, rather than configuration flags.
def
__init__
(
self
,
atexit_print
=
True
,
flag_time_thunks
=
None
,
**
kwargs
):
def
__init__
(
self
,
atexit_print
=
True
,
flag_time_thunks
=
None
,
**
kwargs
):
self
.
apply_callcount
=
{}
self
.
apply_callcount
=
Counter
()
self
.
output_size
=
{}
self
.
output_size
=
{}
# Keys are `(FunctionGraph, Variable)`
self
.
apply_time
=
defaultdict
(
float
)
self
.
apply_time
=
{}
self
.
apply_cimpl
=
{}
self
.
apply_cimpl
=
{}
self
.
variable_shape
=
{}
self
.
variable_shape
=
{}
self
.
variable_strides
=
{}
self
.
variable_strides
=
{}
...
@@ -320,12 +319,10 @@ class ProfileStats:
...
@@ -320,12 +319,10 @@ class ProfileStats:
"""
"""
# timing is stored by node, we compute timing by class on demand
# timing is stored by node, we compute timing by class on demand
rval
=
{}
rval
=
defaultdict
(
float
)
for
(
fgraph
,
node
),
t
in
self
.
apply_time
.
items
():
for
(
_fgraph
,
node
),
t
in
self
.
apply_time
.
items
():
typ
=
type
(
node
.
op
)
rval
[
type
(
node
.
op
)]
+=
t
rval
.
setdefault
(
typ
,
0
)
return
dict
(
rval
)
rval
[
typ
]
+=
t
return
rval
def
class_callcount
(
self
):
def
class_callcount
(
self
):
"""
"""
...
@@ -333,24 +330,18 @@ class ProfileStats:
...
@@ -333,24 +330,18 @@ class ProfileStats:
"""
"""
# timing is stored by node, we compute timing by class on demand
# timing is stored by node, we compute timing by class on demand
rval
=
{}
rval
=
Counter
()
for
(
fgraph
,
node
),
count
in
self
.
apply_callcount
.
items
():
for
(
_fgraph
,
node
),
count
in
self
.
apply_callcount
.
items
():
typ
=
type
(
node
.
op
)
rval
[
type
(
node
.
op
)]
+=
count
rval
.
setdefault
(
typ
,
0
)
rval
[
typ
]
+=
count
return
rval
return
rval
def
class_nodes
(
self
):
def
class_nodes
(
self
)
->
Counter
:
"""
"""
dict op -> total number of nodes
dict op -> total number of nodes
"""
"""
# timing is stored by node, we compute timing by class on demand
# timing is stored by node, we compute timing by class on demand
rval
=
{}
rval
=
Counter
(
type
(
node
.
op
)
for
_fgraph
,
node
in
self
.
apply_callcount
)
for
(
fgraph
,
node
),
count
in
self
.
apply_callcount
.
items
():
typ
=
type
(
node
.
op
)
rval
.
setdefault
(
typ
,
0
)
rval
[
typ
]
+=
1
return
rval
return
rval
def
class_impl
(
self
):
def
class_impl
(
self
):
...
@@ -360,12 +351,9 @@ class ProfileStats:
...
@@ -360,12 +351,9 @@ class ProfileStats:
"""
"""
# timing is stored by node, we compute timing by class on demand
# timing is stored by node, we compute timing by class on demand
rval
=
{}
rval
=
{}
for
fgraph
,
node
in
self
.
apply_callcount
:
for
_
fgraph
,
node
in
self
.
apply_callcount
:
typ
=
type
(
node
.
op
)
typ
=
type
(
node
.
op
)
if
self
.
apply_cimpl
[
node
]:
impl
=
"C "
if
self
.
apply_cimpl
[
node
]
else
"Py"
impl
=
"C "
else
:
impl
=
"Py"
rval
.
setdefault
(
typ
,
impl
)
rval
.
setdefault
(
typ
,
impl
)
if
rval
[
typ
]
!=
impl
and
len
(
rval
[
typ
])
==
2
:
if
rval
[
typ
]
!=
impl
and
len
(
rval
[
typ
])
==
2
:
rval
[
typ
]
+=
impl
rval
[
typ
]
+=
impl
...
@@ -377,11 +365,10 @@ class ProfileStats:
...
@@ -377,11 +365,10 @@ class ProfileStats:
"""
"""
# timing is stored by node, we compute timing by Op on demand
# timing is stored by node, we compute timing by Op on demand
rval
=
{}
rval
=
defaultdict
(
float
)
for
(
fgraph
,
node
),
t
in
self
.
apply_time
.
items
():
for
(
fgraph
,
node
),
t
in
self
.
apply_time
.
items
():
rval
.
setdefault
(
node
.
op
,
0
)
rval
[
node
.
op
]
+=
t
rval
[
node
.
op
]
+=
t
return
rval
return
dict
(
rval
)
def
fill_node_total_time
(
self
,
fgraph
,
node
,
total_times
):
def
fill_node_total_time
(
self
,
fgraph
,
node
,
total_times
):
"""
"""
...
@@ -414,9 +401,8 @@ class ProfileStats:
...
@@ -414,9 +401,8 @@ class ProfileStats:
"""
"""
# timing is stored by node, we compute timing by Op on demand
# timing is stored by node, we compute timing by Op on demand
rval
=
{}
rval
=
Counter
()
for
(
fgraph
,
node
),
count
in
self
.
apply_callcount
.
items
():
for
(
fgraph
,
node
),
count
in
self
.
apply_callcount
.
items
():
rval
.
setdefault
(
node
.
op
,
0
)
rval
[
node
.
op
]
+=
count
rval
[
node
.
op
]
+=
count
return
rval
return
rval
...
@@ -426,10 +412,7 @@ class ProfileStats:
...
@@ -426,10 +412,7 @@ class ProfileStats:
"""
"""
# timing is stored by node, we compute timing by Op on demand
# timing is stored by node, we compute timing by Op on demand
rval
=
{}
rval
=
Counter
(
node
.
op
for
_fgraph
,
node
in
self
.
apply_callcount
)
for
(
fgraph
,
node
),
count
in
self
.
apply_callcount
.
items
():
rval
.
setdefault
(
node
.
op
,
0
)
rval
[
node
.
op
]
+=
1
return
rval
return
rval
def
op_impl
(
self
):
def
op_impl
(
self
):
...
...
pytensor/link/vm.py
浏览文件 @
cc1a1cbb
...
@@ -246,10 +246,8 @@ class VM(ABC):
...
@@ -246,10 +246,8 @@ class VM(ABC):
for
node
,
thunk
,
t
,
c
in
zip
(
for
node
,
thunk
,
t
,
c
in
zip
(
self
.
nodes
,
self
.
thunks
,
self
.
call_times
,
self
.
call_counts
self
.
nodes
,
self
.
thunks
,
self
.
call_times
,
self
.
call_counts
):
):
profile
.
apply_time
.
setdefault
((
self
.
fgraph
,
node
),
0.0
)
profile
.
apply_time
[(
self
.
fgraph
,
node
)]
+=
t
profile
.
apply_time
[(
self
.
fgraph
,
node
)]
+=
t
profile
.
apply_callcount
.
setdefault
((
self
.
fgraph
,
node
),
0
)
profile
.
apply_callcount
[(
self
.
fgraph
,
node
)]
+=
c
profile
.
apply_callcount
[(
self
.
fgraph
,
node
)]
+=
c
profile
.
apply_cimpl
[
node
]
=
hasattr
(
thunk
,
"cthunk"
)
profile
.
apply_cimpl
[
node
]
=
hasattr
(
thunk
,
"cthunk"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论