Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
482508a3
提交
482508a3
authored
11月 06, 2012
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
re-order optimizations
上级
90040b7d
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
112 行增加
和
48 行删除
+112
-48
scan_opt.py
theano/scan_module/scan_opt.py
+112
-48
没有找到文件。
theano/scan_module/scan_opt.py
浏览文件 @
482508a3
...
@@ -147,17 +147,6 @@ def remove_constants_and_unused_inputs_scan(node):
...
@@ -147,17 +147,6 @@ def remove_constants_and_unused_inputs_scan(node):
else
:
else
:
return
False
return
False
scan_seqopt
=
theano
.
gof
.
SequenceDB
()
# We run before blas opt at 1.7 and specialize 2.0
# but after stabilize at 1.5. Should we put it before stabilize?
optdb
.
register
(
'scan_seqopt'
,
scan_seqopt
,
1.6
,
'fast_run'
,
'scan'
)
scan_seqopt
.
register
(
'scanOp_remove_constants_and_unused_inputs'
,
opt
.
in2out
(
remove_constants_and_unused_inputs_scan
,
ignore_newtrees
=
True
),
5
,
'fast_run'
,
'scan'
)
# This is a global opt for historical reason
# This is a global opt for historical reason
# It should be possible to change it to a local opt.
# It should be possible to change it to a local opt.
...
@@ -319,11 +308,6 @@ class PushOutNonSeqScan(gof.Optimizer):
...
@@ -319,11 +308,6 @@ class PushOutNonSeqScan(gof.Optimizer):
return
False
return
False
scan_seqopt
.
register
(
'scanOp_pushout_nonseqs_ops'
,
PushOutNonSeqScan
(),
1
,
'fast_run'
,
'scan'
)
# This is a global opt for historical reason
# This is a global opt for historical reason
# It should be possible to change it to a local opt.
# It should be possible to change it to a local opt.
class
PushOutSeqScan
(
gof
.
Optimizer
):
class
PushOutSeqScan
(
gof
.
Optimizer
):
...
@@ -579,14 +563,6 @@ class ScanInplaceOptimizer(Optimizer):
...
@@ -579,14 +563,6 @@ class ScanInplaceOptimizer(Optimizer):
# Failed moving output to be comptued inplace
# Failed moving output to be comptued inplace
pass
pass
optdb
.
register
(
'scanOp_make_inplace'
,
ScanInplaceOptimizer
(
typeConstructor
=
None
,
gpu_flag
=
False
),
75
,
'fast_run'
,
'inplace'
,
'scan'
)
class
ScanSaveMem
(
gof
.
Optimizer
):
class
ScanSaveMem
(
gof
.
Optimizer
):
""" Graph Optimizer that reduces scan memory consumption """
""" Graph Optimizer that reduces scan memory consumption """
...
@@ -1064,15 +1040,6 @@ class ScanSaveMem(gof.Optimizer):
...
@@ -1064,15 +1040,6 @@ class ScanSaveMem(gof.Optimizer):
if
not
hasattr
(
node
.
op
,
'_scan_savemem_visited'
):
if
not
hasattr
(
node
.
op
,
'_scan_savemem_visited'
):
self
.
process_node
(
fgraph
,
node
)
self
.
process_node
(
fgraph
,
node
)
# Just before specialize to have the other optimization
# like constant folding being applied
# This don't introduce inplace.
scan_seqopt
.
register
(
'scanOp_save_mem'
,
ScanSaveMem
(),
4
,
'fast_run'
,
'scan'
)
class
ScanMerge
(
gof
.
Optimizer
):
class
ScanMerge
(
gof
.
Optimizer
):
""" Graph Optimizer that merges different scan ops """
""" Graph Optimizer that merges different scan ops """
...
@@ -1254,16 +1221,6 @@ class ScanMerge(gof.Optimizer):
...
@@ -1254,16 +1221,6 @@ class ScanMerge(gof.Optimizer):
reason
=
'scan_merge'
)
reason
=
'scan_merge'
)
# 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.
scan_seqopt
.
register
(
'scanOp_merge'
,
ScanMerge
(),
2
,
'fast_run'
,
'scan'
)
def
has_duplicates
(
l
):
def
has_duplicates
(
l
):
"""returns true if l has any duplicates (according to __eq__)."""
"""returns true if l has any duplicates (according to __eq__)."""
return
len
(
set
(
l
))
<
len
(
l
)
return
len
(
set
(
l
))
<
len
(
l
)
...
@@ -1451,11 +1408,6 @@ def scan_merge_inouts(node):
...
@@ -1451,11 +1408,6 @@ def scan_merge_inouts(node):
return
na
.
outer_outputs
return
na
.
outer_outputs
scan_seqopt
.
register
(
'scanOp_merge_inouts'
,
opt
.
in2out
(
scan_merge_inouts
,
ignore_newtrees
=
True
),
3
,
'fast_run'
,
'scan'
)
@gof.local_optimizer
([
None
])
@gof.local_optimizer
([
None
])
def
scan_pushout_dot1
(
node
):
def
scan_pushout_dot1
(
node
):
...
@@ -1671,3 +1623,115 @@ def scan_pushout_dot1(node):
...
@@ -1671,3 +1623,115 @@ def scan_pushout_dot1(node):
return
False
return
False
# I've added an equilibrium because later scan optimization in the sequence
# can make it such that earlier optimizations should apply. However, in
# general I do not expect the sequence to run more then once
scan_eqopt1
=
theano
.
gof
.
EquilibriumDB
()
scan_seqopt1
=
theano
.
gof
.
SequenceDB
()
scan_eqopt2
=
theano
.
gof
.
EquilibriumDB
()
scan_seqopt2
=
theano
.
gof
.
EquilibriumDB
()
# We run before blas opt at 1.7 and specialize 2.0
# but after stabilize at 1.5. Should we put it before stabilize?
optdb
.
register
(
'scan_eqopt1'
,
scan_eqopt1
,
.
1
,
'fast_run'
,
'scan'
)
optdb
.
register
(
'scan_eqopt2'
,
scan_eqopt2
,
1.6
,
'fast_run'
,
'scan'
)
optdb
.
register
(
'scanOp_make_inplace'
,
ScanInplaceOptimizer
(
typeConstructor
=
None
,
gpu_flag
=
False
),
75
,
'fast_run'
,
'inplace'
,
'scan'
)
scan_eqopt2
.
register
(
'all_scan_opts'
,
scan_seqopt2
,
1
,
'fast_run'
,
'scan'
)
scan_eqopt1
.
register
(
'all_pushout_opt'
,
scan_seqopt1
,
1
,
'fast_run'
,
'scan'
)
scan_seqopt1
.
register
(
'scanOp_remove_constants_and_unused_inputs0'
,
opt
.
in2out
(
remove_constants_and_unused_inputs_scan
,
ignore_newtrees
=
True
),
1
,
'fast_run'
,
'scan'
)
scan_seqopt1
.
register
(
'scanOp_pushout_nonseqs_ops'
,
PushOutNonSeqScan
(),
2
,
'fast_run'
,
'scan'
)
scan_seqopt1
.
register
(
'scanOp_pushout_seqs_ops'
,
PushOutSeqScan
(),
3
,
'fast_run'
,
'scan'
)
scan_seqopt1
.
register
(
'scan_pushout_dot1'
,
opt
.
in2out
(
scan_pushout_dot1
,
ignore_newtrees
=
True
),
4
,
'fast_run'
,
'more_mem'
,
'scan'
)
scan_seqopt2
.
register
(
'constant_folding_for_scan2'
,
opt
.
in2out
(
tensor
.
opt
.
constant_folding
,
ignore_newtrees
=
True
),
1
,
'fast_run'
,
'scan'
)
scan_seqopt2
.
register
(
'scanOp_remove_constants_and_unused_inputs0'
,
opt
.
in2out
(
remove_constants_and_unused_inputs_scan
,
ignore_newtrees
=
True
),
2
,
'fast_run'
,
'scan'
)
# 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.
scan_seqopt2
.
register
(
'scanOp_merge'
,
ScanMerge
(),
4
,
'fast_run'
,
'scan'
)
# After Merge optimization
scan_seqopt2
.
register
(
'scanop_remove_constants_and_unused_inputs2'
,
opt
.
in2out
(
remove_constants_and_unused_inputs_scan
,
ignore_newtrees
=
True
),
5
,
'fast_run'
,
'scan'
)
scan_seqopt2
.
register
(
'scanOp_merge_inouts'
,
opt
.
in2out
(
scan_merge_inouts
,
ignore_newtrees
=
True
),
6
,
'fast_run'
,
'scan'
)
# Just before specialize to have the other optimization
# like constant folding being applied
# This don't introduce inplace.
scan_seqopt2
.
register
(
'scanOp_save_mem'
,
ScanSaveMem
(),
7
,
'fast_run'
,
'scan'
)
# After everything else
scan_seqopt2
.
register
(
'scanOp_remove_constants_and_unused_inputs3'
,
opt
.
in2out
(
remove_constants_and_unused_inputs_scan
,
ignore_newtrees
=
True
),
8
,
'fast_run'
,
'scan'
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论