Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
530f442a
提交
530f442a
authored
5月 09, 2016
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add optional callback on inputs in StackVM.
上级
49590e13
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
25 行增加
和
9 行删除
+25
-9
vm.py
theano/gof/vm.py
+25
-9
没有找到文件。
theano/gof/vm.py
浏览文件 @
530f442a
...
@@ -327,7 +327,7 @@ class Stack(VM):
...
@@ -327,7 +327,7 @@ class Stack(VM):
def
__init__
(
self
,
nodes
,
thunks
,
pre_call_clear
,
def
__init__
(
self
,
nodes
,
thunks
,
pre_call_clear
,
storage_map
,
compute_map
,
fgraph
,
allow_gc
,
storage_map
,
compute_map
,
fgraph
,
allow_gc
,
dependencies
=
None
,
callback
=
None
):
dependencies
=
None
,
callback
=
None
,
callback_input
=
None
):
super
(
Stack
,
self
)
.
__init__
(
nodes
,
thunks
,
pre_call_clear
)
super
(
Stack
,
self
)
.
__init__
(
nodes
,
thunks
,
pre_call_clear
)
self
.
allow_gc
=
allow_gc
self
.
allow_gc
=
allow_gc
...
@@ -340,6 +340,7 @@ class Stack(VM):
...
@@ -340,6 +340,7 @@ class Stack(VM):
self
.
compute_map
=
compute_map
self
.
compute_map
=
compute_map
self
.
node_idx
=
node_idx
=
{}
self
.
node_idx
=
node_idx
=
{}
self
.
callback
=
callback
self
.
callback
=
callback
self
.
callback_input
=
callback_input
ords
=
fgraph
.
orderings
()
ords
=
fgraph
.
orderings
()
...
@@ -406,6 +407,8 @@ class Stack(VM):
...
@@ -406,6 +407,8 @@ class Stack(VM):
for
k
in
self
.
storage_map
:
for
k
in
self
.
storage_map
:
compute_map
[
k
][
0
]
=
(
k
.
owner
is
None
)
compute_map
[
k
][
0
]
=
(
k
.
owner
is
None
)
if
self
.
callback_input
and
compute_map
[
k
][
0
]:
self
.
callback_input
(
k
,
self
.
storage_map
[
k
][
0
])
# apply_stack contains nodes
# apply_stack contains nodes
if
output_subset
is
not
None
:
if
output_subset
is
not
None
:
...
@@ -679,6 +682,10 @@ class VM_Linker(link.LocalLinker):
...
@@ -679,6 +682,10 @@ class VM_Linker(link.LocalLinker):
A callable object to call after each call to a thunk within
A callable object to call after each call to a thunk within
the virtual machine. It will be called with four arguments called
the virtual machine. It will be called with four arguments called
'node', 'thunk', 'storage_map', and 'compute_map'.
'node', 'thunk', 'storage_map', and 'compute_map'.
callback_input
A callable object to call on each input to the graph
(variables with no owner). It will be called with two
arguments: 'var', 'value'.
lazy
lazy
Useful only when use_cloop is False. When lazy is None, use the
Useful only when use_cloop is False. When lazy is None, use the
theano flag vm.lazy value. Then if we have a None (default) we auto
theano flag vm.lazy value. Then if we have a None (default) we auto
...
@@ -695,8 +702,8 @@ class VM_Linker(link.LocalLinker):
...
@@ -695,8 +702,8 @@ class VM_Linker(link.LocalLinker):
"""
"""
def
__init__
(
self
,
allow_gc
=
None
,
use_cloop
=
False
,
callback
=
None
,
def
__init__
(
self
,
allow_gc
=
None
,
use_cloop
=
False
,
callback
=
None
,
lazy
=
None
,
schedule
=
None
,
c_thunks
=
None
,
callback_input
=
None
,
lazy
=
None
,
schedule
=
None
,
allow_partial_eval
=
None
):
c_thunks
=
None
,
allow_partial_eval
=
None
):
# Note: if more parameters are added to __init__, make sure to forward
# Note: if more parameters are added to __init__, make sure to forward
# them in the "type(self)(...)" call in the "accept" method below.
# them in the "type(self)(...)" call in the "accept" method below.
if
allow_gc
is
None
:
if
allow_gc
is
None
:
...
@@ -705,6 +712,7 @@ class VM_Linker(link.LocalLinker):
...
@@ -705,6 +712,7 @@ class VM_Linker(link.LocalLinker):
self
.
allow_gc
=
allow_gc
self
.
allow_gc
=
allow_gc
self
.
use_cloop
=
use_cloop
self
.
use_cloop
=
use_cloop
self
.
callback
=
callback
self
.
callback
=
callback
self
.
callback_input
=
callback_input
self
.
lazy
=
lazy
self
.
lazy
=
lazy
self
.
c_thunks
=
c_thunks
self
.
c_thunks
=
c_thunks
self
.
allow_partial_eval
=
allow_partial_eval
self
.
allow_partial_eval
=
allow_partial_eval
...
@@ -752,9 +760,11 @@ class VM_Linker(link.LocalLinker):
...
@@ -752,9 +760,11 @@ class VM_Linker(link.LocalLinker):
allow_gc
=
self
.
allow_gc
,
allow_gc
=
self
.
allow_gc
,
use_cloop
=
self
.
use_cloop
,
use_cloop
=
self
.
use_cloop
,
callback
=
self
.
callback
,
callback
=
self
.
callback
,
callback_input
=
self
.
callback_input
,
lazy
=
self
.
lazy
,
lazy
=
self
.
lazy
,
schedule
=
self
.
schedule
,
schedule
=
self
.
schedule
,
c_thunks
=
self
.
c_thunks
,
c_thunks
=
self
.
c_thunks
,
allow_partial_eval
=
self
.
allow_partial_eval
)
.
accept
(
fgraph
,
no_recycling
)
)
.
accept
(
fgraph
,
no_recycling
)
self
.
fgraph
=
fgraph
self
.
fgraph
=
fgraph
self
.
no_recycling
=
no_recycling
self
.
no_recycling
=
no_recycling
...
@@ -821,16 +831,17 @@ class VM_Linker(link.LocalLinker):
...
@@ -821,16 +831,17 @@ class VM_Linker(link.LocalLinker):
pre_call_clear
=
[
storage_map
[
v
]
for
v
in
self
.
no_recycling
]
pre_call_clear
=
[
storage_map
[
v
]
for
v
in
self
.
no_recycling
]
if
(
self
.
callback
is
not
None
or
if
(
self
.
callback
is
not
None
or
self
.
callback_input
is
not
None
or
(
config
.
profile
and
config
.
profile_memory
)
or
(
config
.
profile
and
config
.
profile_memory
)
or
getattr
(
self
,
'allow_partial_eval'
,
False
)
):
self
.
allow_partial_eval
):
if
self
.
use_cloop
and
self
.
callback
is
not
None
:
if
self
.
use_cloop
and
(
self
.
callback
is
not
None
or
self
.
callback_input
is
not
None
):
logger
.
warn
(
'CVM does not support callback, using Stack VM.'
)
logger
.
warn
(
'CVM does not support callback, using Stack VM.'
)
if
self
.
use_cloop
and
config
.
profile_memory
:
if
self
.
use_cloop
and
config
.
profile_memory
:
warnings
.
warn
(
warnings
.
warn
(
'CVM does not support memory profile, using Stack VM.'
)
'CVM does not support memory profile, using Stack VM.'
)
if
self
.
use_cloop
and
getattr
(
self
,
'allow_partial_eval'
,
False
)
:
if
self
.
use_cloop
and
self
.
allow_partial_eval
:
warnings
.
warn
(
warnings
.
warn
(
'CVM does not support partial evaluation yet, '
'CVM does not support partial evaluation yet, '
'using Stack VM.'
)
'using Stack VM.'
)
...
@@ -841,7 +852,8 @@ class VM_Linker(link.LocalLinker):
...
@@ -841,7 +852,8 @@ class VM_Linker(link.LocalLinker):
storage_map
,
compute_map
,
storage_map
,
compute_map
,
self
.
fgraph
,
self
.
allow_gc
,
self
.
fgraph
,
self
.
allow_gc
,
dependencies
=
deps
,
dependencies
=
deps
,
callback
=
self
.
callback
)
callback
=
self
.
callback
,
callback_input
=
self
.
callback_input
)
elif
self
.
use_cloop
:
elif
self
.
use_cloop
:
# create a map from nodes to ints and vars to ints
# create a map from nodes to ints and vars to ints
nodes_idx
=
{}
nodes_idx
=
{}
...
@@ -1038,7 +1050,7 @@ class VM_Linker(link.LocalLinker):
...
@@ -1038,7 +1050,7 @@ class VM_Linker(link.LocalLinker):
if
lazy
is
None
:
if
lazy
is
None
:
lazy
=
not
all
([(
not
th
.
lazy
)
for
th
in
thunks
])
lazy
=
not
all
([(
not
th
.
lazy
)
for
th
in
thunks
])
if
not
(
lazy
or
(
config
.
profile
and
config
.
profile_memory
)
or
if
not
(
lazy
or
(
config
.
profile
and
config
.
profile_memory
)
or
self
.
use_cloop
or
self
.
callback
):
self
.
use_cloop
or
self
.
callback
or
self
.
callback_input
):
for
pair
in
itervalues
(
reallocated_info
):
for
pair
in
itervalues
(
reallocated_info
):
storage_map
[
pair
[
1
]]
=
storage_map
[
pair
[
0
]]
storage_map
[
pair
[
1
]]
=
storage_map
[
pair
[
0
]]
...
@@ -1080,3 +1092,7 @@ class VM_Linker(link.LocalLinker):
...
@@ -1080,3 +1092,7 @@ class VM_Linker(link.LocalLinker):
self
.
__dict__
.
update
(
d
)
self
.
__dict__
.
update
(
d
)
if
not
hasattr
(
self
,
'c_thunks'
):
if
not
hasattr
(
self
,
'c_thunks'
):
self
.
c_thunks
=
True
self
.
c_thunks
=
True
if
not
hasattr
(
self
,
'allow_partial_eval'
):
self
.
allow_partial_eval
=
None
if
not
hasattr
(
self
,
'callback_input'
):
self
.
callback_input
=
None
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论