Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
644d8bce
提交
644d8bce
authored
5月 11, 2016
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
inplace elemwise optimizer speed up.
上级
fce0b82f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
34 行增加
和
19 行删除
+34
-19
opt.py
theano/tensor/opt.py
+34
-19
没有找到文件。
theano/tensor/opt.py
浏览文件 @
644d8bce
...
...
@@ -237,6 +237,11 @@ def inplace_elemwise_optimizer_op(OP):
else
:
update_outs
=
[]
protected_inputs
=
[
f
.
protected
for
f
in
fgraph
.
_features
if
isinstance
(
f
,
theano
.
compile
.
function_module
.
Supervisor
)]
protected_inputs
=
sum
(
protected_inputs
,
[])
# flatten the list
protected_inputs
.
extend
(
fgraph
.
outputs
)
for
node
in
list
(
graph
.
io_toposort
(
fgraph
.
inputs
,
fgraph
.
outputs
)):
op
=
node
.
op
# gpuarray GpuElemwise inherit from Elemwise
...
...
@@ -245,27 +250,37 @@ def inplace_elemwise_optimizer_op(OP):
# If big graph and the outputs are scalar, do not make it
# inplace.
if
(
check_each_change
!=
1
and
all
([
getattr
(
o
.
type
,
'ndim'
,
-
1
)
==
0
for
o
in
node
.
outputs
])):
# If multiple outputs, they must all have the same size,
# so only check the first.
getattr
(
node
.
outputs
[
0
]
.
type
,
'ndim'
,
-
1
)
==
0
):
continue
baseline
=
op
.
inplace_pattern
protected_inputs
=
[
f
.
protected
for
f
in
node
.
fgraph
.
_features
if
isinstance
(
f
,
theano
.
compile
.
function_module
.
Supervisor
)]
protected_inputs
=
sum
(
protected_inputs
,
[])
# flatten the list
protected_inputs
.
extend
(
fgraph
.
outputs
)
candidate_outputs
=
[
i
for
i
in
xrange
(
len
(
node
.
outputs
))
if
i
not
in
baseline
]
# node inputs that are Constant, already destroyed,
# fgraph protected inputs and fgraph outputs can't be used as inplace
# target.
# Remove here as faster.
candidate_inputs
=
[
i
for
i
in
xrange
(
len
(
node
.
inputs
))
if
i
not
in
baseline
.
values
()
and
not
isinstance
(
node
.
inputs
[
i
],
Constant
)
and
not
fgraph
.
destroyers
(
node
.
inputs
[
i
])
and
node
.
inputs
[
i
]
not
in
protected_inputs
]
if
op
.
inplace_pattern
:
baseline
=
op
.
inplace_pattern
candidate_outputs
=
[
i
for
i
in
xrange
(
len
(
node
.
outputs
))
if
i
not
in
baseline
]
# node inputs that are Constant, already destroyed,
# or fgraph protected inputs and fgraph outputs can't be used as
# inplace target.
# Remove here as faster.
candidate_inputs
=
[
i
for
i
in
xrange
(
len
(
node
.
inputs
))
if
i
not
in
baseline
.
values
()
and
not
isinstance
(
node
.
inputs
[
i
],
Constant
)
and
# Is next line costly?
not
fgraph
.
destroyers
(
node
.
inputs
[
i
])
and
node
.
inputs
[
i
]
not
in
protected_inputs
]
else
:
baseline
=
[]
candidate_outputs
=
list
(
range
(
len
(
node
.
outputs
)))
# node inputs that are Constant, already destroyed,
# fgraph protected inputs and fgraph outputs can't be used as inplace
# target.
# Remove here as faster.
candidate_inputs
=
[
i
for
i
in
xrange
(
len
(
node
.
inputs
))
if
not
isinstance
(
node
.
inputs
[
i
],
Constant
)
and
not
fgraph
.
destroyers
(
node
.
inputs
[
i
])
and
node
.
inputs
[
i
]
not
in
protected_inputs
]
verbose
=
False
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论