Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
08ffec41
提交
08ffec41
authored
9月 10, 2015
作者:
carriepl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Generalize AddNoOutputFromInplace to AddFeatureOptimizer
上级
cc2abb87
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
16 行增加
和
22 行删除
+16
-22
mode.py
theano/compile/mode.py
+5
-14
scan_op.py
theano/scan_module/scan_op.py
+11
-8
没有找到文件。
theano/compile/mode.py
浏览文件 @
08ffec41
...
...
@@ -161,22 +161,16 @@ class AddDestroyHandler(gof.Optimizer):
fgraph
.
attach_feature
(
gof
.
DestroyHandler
())
class
Add
NoOutputFromInplace
(
gof
.
Optimizer
):
class
Add
FeatureOptimizer
(
gof
.
Optimizer
):
"""
This optimizer adds to the fgraph a feature that will prevent outputs
of a fgraph to be created by performing inplace operations on intermediary
variables. This is useful when the outputs of the fgraph are preallocated
to prevent useless copying of the data. Currently, scan preallocates its
outputs
This optimizer adds a provided feature to the function graph.
"""
def
__init__
(
self
,
first_output_idx
=
0
,
last_output_idx
=
None
):
self
.
feature
=
gof
.
NoOutputFromInplace
(
first_output_idx
,
last_output_idx
)
def
__init__
(
self
,
feature
):
self
.
feature
=
feature
def
add_requirements
(
self
,
fgraph
):
super
(
Add
NoOutputFromInplace
,
self
)
.
add_requirements
(
fgraph
)
super
(
Add
FeatureOptimizer
,
self
)
.
add_requirements
(
fgraph
)
fgraph
.
attach_feature
(
self
.
feature
)
...
...
@@ -234,9 +228,6 @@ optdb.register('specialize_device', gof.EquilibriumDB(),
optdb
.
register
(
'merge2'
,
gof
.
MergeOptimizer
(),
49
,
'fast_run'
,
'merge'
)
optdb
.
register
(
'add_no_output_from_inplace'
,
AddNoOutputFromInplace
(),
49.4
)
optdb
.
register
(
'add_destroy_handler'
,
AddDestroyHandler
(),
49.5
,
'fast_run'
,
'inplace'
)
...
...
theano/scan_module/scan_op.py
浏览文件 @
08ffec41
...
...
@@ -68,10 +68,11 @@ from six.moves import xrange
import
theano
from
theano.compat
import
exc_message
from
theano.compile
import
function
,
In
,
Param
,
Out
from
theano.compile.mode
import
Add
NoOutputFromInplace
from
theano.compile.mode
import
Add
FeatureOptimizer
from
theano
import
compile
,
config
,
gradient
,
gof
,
tensor
from
theano.gof
import
PureOp
,
Apply
from
theano.gof.graph
import
io_connection_pattern
from
theano.gof.toolbox
import
NoOutputFromInplace
from
theano.compat
import
OrderedDict
,
izip
from
theano.tensor
import
TensorType
from
theano.tensor.opt
import
Shape_i
...
...
@@ -802,16 +803,18 @@ class Scan(PureOp):
self
.
mitmots_preallocated
=
[
i
in
preallocated_mitmot_outs
for
i
in
range
(
self
.
n_mit_mot_outs
)]
# Add an optimization to the compilation mode to prevent mitsot,
# sitsot and nitsot outputs from being computed inplace (to allow
# their preallocation). This optimization is added such that it
# will run just before the inplace optimizations
# Add an optimization to the compilation mode to attach a feature
# to the function graph just before the inplace optimizations are
# applied. This feature will prevent mitsot, sitsot and nitsot
# outputs from being computed inplace (to allow their
# preallocation).
mitsot_start
=
self
.
n_mit_mot_outs
-
len
(
preallocated_mitmot_outs
)
nitsot_end
=
(
mitsot_start
+
self
.
n_mit_sot
+
self
.
n_sit_sot
+
self
.
n_nit_sot
)
no_inplace_opt
=
AddNoOutputFromInplace
(
mitsot_start
,
nitsot_end
)
compilation_mode
=
self
.
mode_instance
.
register
((
no_inplace_opt
,
49.9
))
feature
=
NoOutputFromInplace
(
mitsot_start
,
nitsot_end
)
opt
=
AddFeatureOptimizer
(
feature
)
compilation_mode
=
self
.
mode_instance
.
register
((
opt
,
49.9
))
else
:
# Output preallocation is not activated. Mark every mitmot output
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论