Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b0050f2d
提交
b0050f2d
authored
7月 20, 2011
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new optimization that merges scan ops
上级
ecc69291
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
87 行增加
和
1 行删除
+87
-1
scan_opt.py
theano/scan_module/scan_opt.py
+87
-1
没有找到文件。
theano/scan_module/scan_opt.py
浏览文件 @
b0050f2d
...
@@ -26,7 +26,7 @@ from theano import config
...
@@ -26,7 +26,7 @@ from theano import config
import
scan_op
import
scan_op
import
scan_utils
import
scan_utils
from
scan_utils
import
clone
,
equal_computations
from
scan_utils
import
clone
,
equal_computations
,
find_up
,
scan_args
from
theano.gof.opt
import
pre_constant_merge
,
pre_greedy_local_optimizer
from
theano.gof.opt
import
pre_constant_merge
,
pre_greedy_local_optimizer
# Logging function for sending warning or info
# Logging function for sending warning or info
...
@@ -757,6 +757,92 @@ optdb.register( 'scanOp_save_mem'
...
@@ -757,6 +757,92 @@ optdb.register( 'scanOp_save_mem'
,
'scan'
)
,
'scan'
)
class
ScanMerge
(
gof
.
Optimizer
):
""" Graph Optimizer that merges different scan ops """
def
add_requirements
(
self
,
env
):
env
.
extend
(
gof
.
toolbox
.
ReplaceValidate
())
def
merge
(
self
,
A
,
B
,
as_while
):
Aargs
=
scan_args
(
A
.
inputs
,
A
.
outputs
,
A
.
op
.
inputs
,
A
.
op
.
outputs
,
A
.
op
.
info
)
Bargs
=
scan_args
(
B
.
inputs
,
B
.
outputs
,
B
.
op
.
inputs
,
B
.
op
.
outputs
,
B
.
op
.
info
)
Margs
=
Aargs
.
merge
(
Bargs
)
# fixup name
info
=
Margs
.
info
info
[
'name'
]
=
A
.
op
.
name
+
'&'
+
B
.
op
.
name
if
as_while
:
Margs_inner_outs
=
Margs
.
inner_outputs
+
Margs
.
cond
else
:
Margs_inner_outs
=
Margs
.
inner_outputs
op
=
scan_op
.
Scan
(
Margs
.
inner_inputs
,
Margs_inner_outs
,
info
)
outputs
=
op
(
*
Margs
.
outer_inputs
)
if
type
(
outputs
)
not
in
(
list
,
tuple
):
outputs
=
[
outputs
]
return
zip
(
Margs
.
outer_outputs
,
outputs
)
def
apply
(
self
,
env
):
nodelist
=
list
(
env
.
toposort
())
scan_nodes
=
filter
(
lambda
s
:
isinstance
(
s
.
op
,
scan_op
.
Scan
),
nodelist
)
nscan
=
dict
()
for
snode
in
scan_nodes
:
n_steps
=
snode
.
inputs
[
0
]
try
:
n_steps
=
int
(
get_constant_value
(
n_steps
))
except
TypeError
:
pass
l
=
nscan
.
get
(
n_steps
)
if
l
is
None
:
nscan
[
n_steps
]
=
[
snode
]
else
:
l
.
append
(
snode
)
for
snodes
in
nscan
.
values
():
if
len
(
snodes
)
>
1
:
# amongst nodes that have the same number of steps
# try to find the ones that can be merged
curnode
=
snodes
[
0
]
for
snode
in
snodes
[
1
:]:
if
(
snode
.
op
.
truncate_gradient
==
curnode
.
op
.
truncate_gradient
and
snode
.
op
.
mode
==
curnode
.
op
.
mode
and
not
find_up
(
snode
,
curnode
)):
if
(
not
snode
.
op
.
as_while
and
not
curnode
.
op
.
as_while
):
proposal
=
self
.
merge
(
curnode
,
snode
,
False
)
env
.
replace_all_validate
(
proposal
,
reason
=
'scan merge'
)
elif
(
snode
.
op
.
as_while
and
curnode
.
op
.
as_while
):
# check if equal computations
correspondance
=
dict
(
zip
(
snode
.
op
.
inputs
,
curnode
.
op
.
inputs
))
if
scan_utils
.
equal_computations
(
[
snode
.
op
.
outputs
[
-
1
]],
[
curnode
.
op
.
outputs
[
-
1
]],
snode
.
op
.
inputs
,
curnode
.
op
.
inputs
):
proposal
=
self
.
merge
(
curnode
,
snode
,
True
)
env
.
replace_all_validate
(
proposal
,
reason
=
'scan_merge'
)
else
:
pass
else
:
pass
# other merges will be done in other passes
break
# after const merge but before stabilize so that we can have identity
# for equivalent nodes but we still have the chance to hoist stuff out
# of the scan later.
optdb
.
register
(
'scanOp_merge'
,
EquilibriumOptimizer
([
ScanMerge
()],
max_use_ratio
=
11
),
1.90
,
'fast_run'
,
'scan'
)
from
theano.sandbox
import
cuda
from
theano.sandbox
import
cuda
if
cuda
.
cuda_available
:
if
cuda
.
cuda_available
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论