Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
deba0d19
提交
deba0d19
authored
3月 09, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
First version of memory_profile to the new profiler
上级
f62a038d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
93 行增加
和
3 行删除
+93
-3
profiling.py
theano/compile/profiling.py
+91
-2
vm.py
theano/gof/vm.py
+2
-1
没有找到文件。
theano/compile/profiling.py
浏览文件 @
deba0d19
...
...
@@ -555,6 +555,92 @@ class ProfileStats(object):
# The validation time is a subset of optimizer_time
assert
self
.
validate_time
<
self
.
optimizer_time
def
summary_memory
(
self
,
file
,
N
=
None
):
fct_memory
=
{}
# fgraph->dict(node->(outputs size))
var_mem
=
{}
for
node
,
val
in
self
.
outputs_size
.
items
():
fct_memory
.
setdefault
(
node
.
fgraph
,
{})
fct_memory
[
node
.
fgraph
][
node
]
=
val
for
out
,
v
in
zip
(
node
.
outputs
,
val
):
var_mem
[
out
]
=
v
print
print
"Profile of Theano functions memory:"
for
fgraph
,
nodes_mem
in
fct_memory
.
iteritems
():
size_sum
=
sum
([
sum
(
val
)
for
key
,
val
in
nodes_mem
.
iteritems
()])
print
" Max without gc, inplace and view (KB)"
,
size_sum
/
1024
node_memory_size
=
0
node_memory_saved_by_view
=
0
node_memory_saved_by_inplace
=
0
running_memory_size
=
0
running_max_memory_size
=
0
post_thunk_old_storage
=
[]
items
=
nodes_mem
.
items
()
items
.
sort
(
key
=
lambda
a
:
a
[
1
])
items
.
reverse
()
order
=
fgraph
.
toposort
()
computed
,
last_user
=
theano
.
gof
.
link
.
gc_helper
(
order
)
for
node
in
order
:
post_thunk_old_storage
.
append
([
input_idx
for
input_idx
,
input
in
enumerate
(
node
.
inputs
)
if
(
input
in
computed
)
and
(
input
not
in
fgraph
.
outputs
)
and
node
==
last_user
[
input
]])
for
node
,
val
in
items
[:
N
]:
dmap
=
getattr
(
node
.
op
,
'destroy_map'
,
None
)
vmap
=
getattr
(
node
.
op
,
'view_map'
,
None
)
for
idx
,
v
in
enumerate
(
val
):
# TODO check the op returned a view
if
dmap
and
idx
in
dmap
:
node_memory_saved_by_inplace
+=
v
# TODO check the op returned a view
elif
vmap
and
idx
in
vmap
:
node_memory_saved_by_view
+=
v
else
:
node_memory_size
+=
v
running_memory_size
+=
v
if
running_memory_size
>
running_max_memory_size
:
running_max_memory_size
=
running_memory_size
old_storage
=
post_thunk_old_storage
[
order
.
index
(
node
)]
for
old_s
in
old_storage
:
running_memory_size
-=
var_mem
[
node
.
inputs
[
old_s
]]
pass
pass
print
" Max FAST_RUN_NO_GC (KB)"
,
node_memory_size
/
1024
print
" Max FAST_RUN (KB)"
,
running_max_memory_size
/
1024
print
" Memory saved by view (KB)"
,
(
node_memory_saved_by_view
/
1024
)
print
" Memory saved by inplace (KB)"
,
(
node_memory_saved_by_inplace
/
1024
)
print
" Memory saved by GC (KB)"
,
(
node_memory_size
-
running_max_memory_size
)
/
1024
N
+=
10
# TODO remove this line
print
print
" <Sum apply outputs (bytes)> <Apply outputs memory size(bytes)> <created/inplace/view> <Apply node>"
print
" <created/inplace/view> is taked from the op declaration."
print
" Use DebugMode for warnings about inplace/view declaration being respected."
for
key
,
val
in
items
[:
N
]:
code
=
[
'c'
]
*
len
(
node
.
outputs
)
for
out
,
inp
in
getattr
(
key
.
op
,
'destroy_map'
,
{})
.
iteritems
():
code
[
out
]
=
"i"
for
out
,
inp
in
getattr
(
key
.
op
,
'view_map'
,
{})
.
iteritems
():
code
[
out
]
=
"v"
print
'
%9
dB
%
s
%
s
%
s'
%
(
sum
(
val
),
str
(
val
),
' '
.
join
(
code
),
key
)
sum_remaining
=
sum
(
sum
(
val
)
for
key
,
val
in
items
[
N
:])
print
(
' ... (remaining
%
i Apply account for
%.2
f
%%
(
%.2
fs) of'
' the runtime)'
)
%
(
max
(
0
,
len
(
nodes_mem
)
-
N
),
sum_remaining
,
sum_remaining
/
size_sum
)
def
summary
(
self
,
file
=
sys
.
stderr
,
n_ops_to_print
=
20
,
n_applies_to_print
=
20
):
self
.
summary_function
(
file
)
...
...
@@ -566,10 +652,13 @@ class ProfileStats(object):
elif
self
.
fct_callcount
>
0
:
print
>>
file
,
(
" No node time accumulated "
"(hint: try config profiling.time_thunks=1)"
)
if
self
.
outputs_size
:
self
.
summary_memory
(
file
,
n_ops_to_print
)
if
self
.
optimizer_profile
:
print
"Optimizer Profile"
print
"-----------------"
self
.
optimizer_profile
[
0
]
.
print_profile
(
file
,
self
.
optimizer_profile
[
1
])
self
.
optimizer_profile
[
0
]
.
print_profile
(
file
,
self
.
optimizer_profile
[
1
])
if
0
:
# old code still to be ported from ProfileMode
...
...
@@ -727,7 +816,7 @@ if 0: # old code still to be ported from ProfileMode
items
.
reverse
()
order
=
fgraph
.
toposort
()
computed
,
last_user
=
gc_helper
(
order
)
computed
,
last_user
=
theano
.
gof
.
link
.
gc_helper
(
order
)
for
node
in
order
:
post_thunk_old_storage
.
append
([
input_idx
for
input_idx
,
input
in
enumerate
(
node
.
inputs
)
...
...
theano/gof/vm.py
浏览文件 @
deba0d19
...
...
@@ -130,6 +130,8 @@ class VM(object):
profile
.
apply_cimpl
[
node
]
=
hasattr
(
thunk
,
'cthunk'
)
profile
.
outputs_size
[
node
]
=
self
.
outputs_size
[
node
]
# clear the timer info out of the buffers
for
i
in
xrange
(
len
(
self
.
call_times
)):
self
.
call_times
[
i
]
=
0.0
...
...
@@ -283,7 +285,6 @@ class Stack(VM):
if
config
.
profile
:
self
.
memory_size_map
=
{
"nt8"
:
1
,
"t16"
:
2
,
"t32"
:
4
,
"t64"
:
8
,
"128"
:
16
}
atexit
.
register
(
self
.
atexit_print_all
)
def
run_thunk_of_node
(
self
,
node
):
"""Run the thunk corresponding to Apply instance `node`
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论