Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2a03db63
提交
2a03db63
authored
12月 17, 2012
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
transform optimization in a global one to deal with some issues
上级
63353634
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
27 行增加
和
20 行删除
+27
-20
scan_opt.py
theano/scan_module/scan_opt.py
+27
-20
没有找到文件。
theano/scan_module/scan_opt.py
浏览文件 @
2a03db63
...
@@ -1410,10 +1410,23 @@ def scan_merge_inouts(node):
...
@@ -1410,10 +1410,23 @@ def scan_merge_inouts(node):
return
na
.
outer_outputs
return
na
.
outer_outputs
@gof.local_optimizer
([
None
])
class
PushOutDot1
(
gof
.
Optimizer
):
def
scan_pushout_dot1
(
node
):
"""Graph optimizer for Scan(makes it run inplace)"""
if
not
isinstance
(
node
.
op
,
scan_op
.
Scan
):
def
__init__
(
self
):
return
False
Optimizer
.
__init__
(
self
)
def
add_requirements
(
self
,
fgraph
):
fgraph
.
attach_feature
(
toolbox
.
ReplaceValidate
())
fgraph
.
attach_feature
(
DestroyHandler
())
def
apply
(
self
,
fgraph
):
nodes
=
fgraph
.
toposort
()
scan_nodes
=
[
x
for
x
in
nodes
if
(
isinstance
(
x
.
op
,
scan_op
.
Scan
))]
for
node
in
scan_nodes
:
self
.
apply_opt
(
fgraph
,
node
)
def
apply_opt
(
self
,
fgraph
,
node
):
# Replace pattern of the form
# Replace pattern of the form
# x[t] = x[t-1] + dot(seq[t], value)
# x[t] = x[t-1] + dot(seq[t], value)
# with Sequence.reshape((-1, seq.shape[2])) \dot Value
# with Sequence.reshape((-1, seq.shape[2])) \dot Value
...
@@ -1520,6 +1533,7 @@ def scan_pushout_dot1(node):
...
@@ -1520,6 +1533,7 @@ def scan_pushout_dot1(node):
outer_nitsot
+
outer_nitsot
+
[
node
.
inputs
[
0
]]
+
[
node
.
inputs
[
0
]]
+
outer_non_seqs
)
outer_non_seqs
)
new_outs
=
new_op
(
*
_scan_inputs
)
new_outs
=
new_op
(
*
_scan_inputs
)
# We need now to pair correctly the new outputs with the
# We need now to pair correctly the new outputs with the
...
@@ -1547,8 +1561,6 @@ def scan_pushout_dot1(node):
...
@@ -1547,8 +1561,6 @@ def scan_pushout_dot1(node):
val
=
_val
.
reshape
((
sh0
*
sh1
,
sh2
))
val
=
_val
.
reshape
((
sh0
*
sh1
,
sh2
))
new_out
=
tensor
.
dot
(
out_seq
,
val
)
new_out
=
tensor
.
dot
(
out_seq
,
val
)
new_out
=
tensor
.
unbroadcast
(
new_out
.
dimshuffle
(
'x'
,
0
,
1
),
0
)
else
:
else
:
_out_seq
=
op
.
outer_seqs
(
node
)[
seqs
.
index
(
inp2
)]
_out_seq
=
op
.
outer_seqs
(
node
)[
seqs
.
index
(
inp2
)]
out_seq
=
_out_seq
.
reshape
(
out_seq
=
_out_seq
.
reshape
(
...
@@ -1559,21 +1571,16 @@ def scan_pushout_dot1(node):
...
@@ -1559,21 +1571,16 @@ def scan_pushout_dot1(node):
(
_val
.
shape
[
1
],
(
_val
.
shape
[
1
],
_val
.
shape
[
0
]
*
_val
.
shape
[
2
]))
_val
.
shape
[
0
]
*
_val
.
shape
[
2
]))
new_out
=
tensor
.
dot
(
val
,
out_seq
)
new_out
=
tensor
.
dot
(
val
,
out_seq
)
new_out
=
tensor
.
unbroadcast
(
new_out
.
dimshuffle
(
'x'
,
0
,
1
),
0
)
outer_sitsot_outs
=
(
outer_sitsot_outs
[:
idx
]
+
[
new_out
]
+
outer_sitsot_outs
[
idx
:])
final_outs
=
(
outer_mitmot_outs
+
outer_mitsot_outs
+
outer_sitsot_outs
+
outer_nitsot_outs
+
outer_shared_outs
)
return
final_outs
pos
=
node
.
outputs
.
index
(
outer_out
)
old_new
=
zip
(
node
.
outputs
[:
pos
],
new_outs
[:
pos
])
old
=
node
.
outputs
[
pos
]
.
clients
[
0
][
0
]
.
outputs
[
0
]
old_new
.
append
((
old
,
new_out
))
old_new
+=
zip
(
node
.
outputs
[
pos
+
1
:],
new_outs
[
pos
:])
fgraph
.
replace_all_validate_remove
(
old_new
,
remove
=
[
node
],
reason
=
'PushOutDot1'
)
return
False
# I've added an equilibrium because later scan optimization in the sequence
# I've added an equilibrium because later scan optimization in the sequence
...
@@ -1625,7 +1632,7 @@ scan_seqopt1.register('scanOp_pushout_seqs_ops',
...
@@ -1625,7 +1632,7 @@ scan_seqopt1.register('scanOp_pushout_seqs_ops',
scan_seqopt1
.
register
(
'scan_pushout_dot1'
,
scan_seqopt1
.
register
(
'scan_pushout_dot1'
,
opt
.
in2out
(
scan_pushout_dot1
,
ignore_newtrees
=
True
),
PushOutDot1
(
),
4
,
4
,
'fast_run'
,
'fast_run'
,
'more_mem'
,
'more_mem'
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论