Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c1ed99b1
提交
c1ed99b1
authored
8月 20, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more pep8
上级
acc19605
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
35 行增加
和
22 行删除
+35
-22
profiling.py
theano/compile/profiling.py
+35
-22
没有找到文件。
theano/compile/profiling.py
浏览文件 @
c1ed99b1
...
...
@@ -784,12 +784,12 @@ class ProfileStats(object):
executable_nodes
.
add
(
c
)
# two data structure used to mimic Python gc
viewed_by
=
{}
# {var1: [vars that view var1]}
viewed_by
=
{}
# {var1: [vars that view var1]}
# The len of the list is the value of python ref count. But we use a list, not just the ref count value.
# This is more safe to help detect potential bug in the algo
for
var
in
fgraph
.
variables
:
viewed_by
[
var
]
=
[]
view_of
=
{}
# {var1: original var viewed by var1}
view_of
=
{}
# {var1: original var viewed by var1}
# The orignal mean that we don't keep trac of all the intermediate relationship in the view.
def
min_memory_generator
(
executable_nodes
,
viewed_by
,
view_of
):
...
...
@@ -823,15 +823,19 @@ class ProfileStats(object):
vmap
=
getattr
(
node
.
op
,
'view_map'
,
None
)
idx
=
0
# Update the Python emulating dicts and add the memory allocated by the node
# Update the Python emulating dicts and add the
# memory allocated by the node
for
out
in
node
.
outputs
:
if
(
dmap
and
idx
in
dmap
)
or
(
vmap
and
idx
in
vmap
):
# This is needed for destroy_map in case it return a partial view that is destroyed.
# So the output could be different then the input.
# This is needed for destroy_map in case it
# return a partial view that is destroyed. So
# the output could be different then the
# input.
for
ins
in
node
.
inputs
:
assert
isinstance
(
ins
,
theano
.
Variable
)
view_of_temp
[
out
]
=
view_of_temp
.
get
(
ins
,
ins
)
# This get make that we keep trac of view only again the original
viewed_by_temp
[
ins
]
.
append
(
out
)
# We keep trac of view only again the original
view_of_temp
[
out
]
=
view_of_temp
.
get
(
ins
,
ins
)
viewed_by_temp
[
ins
]
.
append
(
out
)
else
:
mem_created
+=
var_mem
[
out
]
idx
+=
1
...
...
@@ -841,8 +845,9 @@ class ProfileStats(object):
# Mimic the combination of Theano and Python gc.
for
ins
in
node
.
inputs
:
assert
not
(
ins
in
view_of_temp
and
viewed_by_temp
[
ins
])
# we keep track of the original var, so this shouldn't happen
assert
not
(
ins
in
view_of_temp
and
viewed_by_temp
[
ins
])
# We track of the original var, so this shouldn't happen
if
dependencies
[
ins
]
and
ins
not
in
fgraph
.
outputs
and
ins
.
owner
:
if
all
(
compute_map
[
v
]
for
v
in
dependencies
[
ins
]):
if
ins
not
in
view_of_temp
and
not
viewed_by_temp
.
get
(
ins
,
[]):
...
...
@@ -853,7 +858,8 @@ class ProfileStats(object):
if
not
viewed_by_temp
[
origin
]
and
origin
not
in
fgraph
.
inputs
:
mem_freed
+=
var_mem
[
origin
]
else
:
# ins is viewed_by something else, so its memory isn't freed
# ins is viewed_by something else, so its
# memory isn't freed
pass
mem_count
-=
mem_freed
...
...
@@ -865,13 +871,15 @@ class ProfileStats(object):
if
not
new_exec_nodes
:
yield
[
node
]
#Check and Update mem_bound
#
Check and Update mem_bound
if
max_mem_count
<
mem_bound
:
mem_bound
=
max_mem_count
else
:
for
p
in
min_memory_generator
(
new_exec_nodes
,
viewed_by_temp
,
view_of_temp
):
for
p
in
min_memory_generator
(
new_exec_nodes
,
viewed_by_temp
,
view_of_temp
):
yield
[
node
]
+
p
# Reset track variables
mem_count
-=
mem_created
max_mem_count
=
max_storage
...
...
@@ -880,7 +888,9 @@ class ProfileStats(object):
compute_map
[
var
][
0
]
=
0
# Loop all valid orders and find min peak(store in mem_bound)
for
order
in
min_memory_generator
(
executable_nodes
,
viewed_by
,
view_of
):
for
order
in
min_memory_generator
(
executable_nodes
,
viewed_by
,
view_of
):
continue
return
mem_bound
...
...
@@ -888,7 +898,7 @@ class ProfileStats(object):
for
fgraph
,
nodes_mem
in
fct_memory
.
iteritems
():
# Sum of the size of all variables in bytes
sum_size
=
sum
([
sum
([
v
for
v
in
val
if
not
isinstance
(
v
,
str
)])
for
key
,
val
in
nodes_mem
.
iteritems
()])
for
key
,
val
in
nodes_mem
.
iteritems
()])
order
=
fgraph
.
toposort
()
# A list of intermediate variable that are not need
...
...
@@ -901,24 +911,27 @@ class ProfileStats(object):
new_order
=
fgraph
.
profile
.
node_executed_order
# A list of new executed node order
new_running_memory
=
count_running_memory
(
new_order
,
fgraph
,
nodes_mem
)
new_running_memory
=
count_running_memory
(
new_order
,
fgraph
,
nodes_mem
)
# Store the max of some stats by any function in this profile.
max_sum_size
=
max
(
max_sum_size
,
sum_size
)
max_node_memory_size
=
max
(
max_node_memory_size
,
old_running_memory
[
0
])
max_node_memory_size
=
max
(
max_node_memory_size
,
old_running_memory
[
0
])
max_running_max_memory_size
=
max
(
max_running_max_memory_size
,
old_running_memory
[
2
])
old_running_memory
[
2
])
max_node_memory_saved_by_view
=
max
(
max_node_memory_saved_by_view
,
old_running_memory
[
4
])
max_node_memory_saved_by_inplace
=
max
(
max_node_memory_saved_by_inplace
,
old_running_memory
[
3
])
# Store max of some stats with new order
new_max_node_memory_size
=
max
(
new_max_node_memory_size
,
new_running_memory
[
0
])
new_max_node_memory_size
=
max
(
new_max_node_memory_size
,
new_running_memory
[
0
])
new_max_running_max_memory_size
=
max
(
new_max_running_max_memory_size
,
new_running_memory
[
2
])
new_running_memory
[
2
])
new_max_node_memory_saved_by_view
=
max
(
new_max_node_memory_saved_by_view
,
new_running_memory
[
4
])
new_running_memory
[
4
])
new_max_node_memory_saved_by_inplace
=
max
(
new_max_node_memory_saved_by_inplace
,
new_running_memory
[
3
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论