Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1cef6dac
提交
1cef6dac
authored
6月 08, 2017
作者:
Reyhane Askari
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix for outputGuard
上级
ad23d387
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
26 行增加
和
7 行删除
+26
-7
function_module.py
theano/compile/function_module.py
+0
-1
destroyhandler.py
theano/gof/destroyhandler.py
+26
-6
没有找到文件。
theano/compile/function_module.py
浏览文件 @
1cef6dac
...
...
@@ -136,7 +136,6 @@ class Supervisor:
if
fgraph
.
has_destroyers
(
self
.
protected
):
raise
gof
.
InconsistencyError
(
"Trying to destroy a protected"
"Variable."
)
else
:
return
True
if
not
hasattr
(
fgraph
,
'destroyers'
):
return
True
...
...
theano/gof/destroyhandler.py
浏览文件 @
1cef6dac
...
...
@@ -398,6 +398,7 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa
visited_app_set
=
set
()
def
recursive_destroys_finder
(
protected_var
):
# protected_var is the idx'th input of app.
for
(
app
,
idx
)
in
protected_var
.
clients
:
if
app
in
visited_app_set
:
continue
...
...
@@ -406,16 +407,21 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa
if
app
==
'output'
:
continue
destroy_maps
=
getattr
(
app
.
op
,
'destroy_map'
,
{})
.
values
()
# If True means that the apply node, destroys the protected_var.
if
idx
in
[
dmap
for
sublist
in
destroy_maps
for
dmap
in
sublist
]:
return
True
for
var_idx
in
getattr
(
app
.
op
,
'view_map'
,
{})
.
keys
():
if
idx
in
app
.
op
.
view_map
[
var_idx
]
and
recursive_destroys_finder
(
app
.
outputs
[
var_idx
]):
if
idx
in
app
.
op
.
view_map
[
var_idx
]:
# We need to recursivly check the destroy_map of all the
# outputs that we have a view_map on.
if
recursive_destroys_finder
(
app
.
outputs
[
var_idx
]):
return
True
return
False
for
protected_var
in
protected_list
:
if
recursive_destroys_finder
(
protected_var
):
return
True
return
False
fgraph
.
has_destroyers
=
has_destroyers
...
...
@@ -445,7 +451,7 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa
delattr
(
self
.
fgraph
,
'destroy_handler'
)
self
.
fgraph
=
None
def
fast_destroy
(
self
,
app
,
reason
):
def
fast_destroy
(
self
,
app
,
reason
,
full
=
False
):
"""
Do the check for only 1 level.
...
...
@@ -456,6 +462,7 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa
- But don't allow to destroy view
"""
dm
=
getattr
(
app
.
op
,
'destroy_map'
,
None
)
vm
=
getattr
(
app
.
op
,
'view_map'
,
{})
if
not
dm
:
return
inputs
=
set
(
itertools
.
chain
.
from_iterable
(
dm
.
values
()))
# list of app's destroyed inputs
...
...
@@ -489,6 +496,17 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa
# assert len(v) <= 1
# assert len(d) <= 1
# We don't want this to be a regular check. Full is only enabled when a node is
# attached to the graph and at the end of validation. We check a rare case where
# an apply node has a dmap and vmap on the same input. Right now the only case
# of this pattern is when app is the OutputGuard.
if
full
:
d_inputs
=
set
(
dmap
for
sublist
in
dm
.
values
()
for
dmap
in
sublist
)
v_inputs
=
set
(
vmap
for
sublist
in
vm
.
values
()
for
vmap
in
sublist
)
if
d_inputs
.
intersection
(
v_inputs
):
self
.
fail_validate
[
app
]
=
theano
.
gof
.
InconsistencyError
(
"
\
Destroyed variable has both view_map and destroy_map. "
+
str
(
reason
))
def
on_import
(
self
,
fgraph
,
app
,
reason
):
"""
Add Apply instance to set which must be computed.
...
...
@@ -500,13 +518,15 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa
# print 'DH IMPORT', app, id(app), id(self), len(self.debug_all_apps)
# If it's a destructive op, add it to our watch list
if
getattr
(
app
.
op
,
'destroy_map'
,
None
):
dmap
=
getattr
(
app
.
op
,
'destroy_map'
,
None
)
vmap
=
getattr
(
app
.
op
,
'view_map'
,
{})
if
dmap
:
self
.
destroyers
.
add
(
app
)
if
self
.
algo
==
'fast'
:
self
.
fast_destroy
(
app
,
reason
)
self
.
fast_destroy
(
app
,
reason
,
full
=
True
)
# add this symbol to the forward and backward maps
for
o_idx
,
i_idx_list
in
iteritems
(
getattr
(
app
.
op
,
'view_map'
,
{})
):
for
o_idx
,
i_idx_list
in
iteritems
(
vmap
):
if
len
(
i_idx_list
)
>
1
:
raise
NotImplementedError
(
'destroying this output invalidates multiple inputs'
,
...
...
@@ -635,7 +655,7 @@ class DestroyHandler(toolbox.Bookkeeper): # noqa
# double check here.
for
app
in
app_err_pairs
:
if
app
in
fgraph
.
apply_nodes
:
self
.
fast_destroy
(
app
,
'validate'
)
self
.
fast_destroy
(
app
,
'validate'
,
full
=
True
)
if
self
.
fail_validate
:
self
.
fail_validate
=
app_err_pairs
raise
app_err_pairs
[
app
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论