Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0d9b26fc
提交
0d9b26fc
authored
10月 13, 2009
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new version of elemwise fusion. Bug fix and work for more then 2 elemwise.
上级
774a8ba1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
33 行增加
和
35 行删除
+33
-35
opt.py
theano/tensor/opt.py
+33
-35
没有找到文件。
theano/tensor/opt.py
浏览文件 @
0d9b26fc
...
@@ -1231,72 +1231,70 @@ register_canonicalize(local_transposed_dot, name='local_transposed_dot')
...
@@ -1231,72 +1231,70 @@ register_canonicalize(local_transposed_dot, name='local_transposed_dot')
def
local_elemwise_fusion
(
node
):
def
local_elemwise_fusion
(
node
):
"""As part of specialisation, we fusion two consecutif elemwise op of the same shape.
"""As part of specialisation, we fusion two consecutif elemwise op of the same shape.
"""
"""
TODO
:
implement
Composite
.
__eq__
by
using
CLinker
.
cmodule_key
()
to
compare
the
graph
.
# TODO:implement Composite.__eq__ by using CLinker.cmodule_key() to compare the graph.
#TODO: check dtype and broadcastable(type)
#TODO: test nb_clients?
if
not
isinstance
(
node
.
op
,
T
.
Elemwise
):
if
not
isinstance
(
node
.
op
,
T
.
Elemwise
):
return
False
return
False
if
isinstance
(
node
.
op
.
scalar_op
,
scalar
.
Composite
):
print
"local_elemwise_fusion of Composite"
nb_elemwise
=
0
nb_elemwise
=
0
inputs
=
[]
inputs
=
[]
#inputs of the new Elemwise op.
s_inputs
=
[]
s_inputs
=
[]
#inputs of the new scalar op.
s_g
=
[]
#graph of scalar, what will by done in the inner loop.
s_g
=
[]
#graph of scalar, what will by done in the inner loop.
for
i
in
node
.
inputs
:
for
i
in
node
.
inputs
:
if
i
.
owner
and
isinstance
(
i
.
owner
.
op
,
T
.
Elemwise
):
if
i
.
owner
and
isinstance
(
i
.
owner
.
op
,
T
.
Elemwise
):
if
False
and
len
(
i
.
owner
.
inputs
)
!=
2
:
print
"local_elemwise_fusion: Elemwise inputs have more then 2 inputs"
return
False
if
len
(
i
.
clients
)
>
1
:
if
len
(
i
.
clients
)
>
1
:
#should we put this in the first if, then we would go to the elif to don't fuse it?
print
"local_elemwise_fusion: Elemwise inputs have more then 1 client. Don't optimise for now"
print
"local_elemwise_fusion: Elemwise inputs have more then 1 client. Don't optimise for now"
return
False
return
False
if
False
and
i
.
owner
.
inputs
[
0
]
.
owner
!=
None
:
print
"local_elemwise_fusion: Elemwise inputs inputs[0] have an owner"
return
False
if
i
.
owner
.
inputs
[
1
]
.
owner
!=
None
:
print
"local_elemwise_fusion: Elemwise inputs inputs[1] have an owner"
return
False
nb_elemwise
+=
1
nb_elemwise
+=
1
inputs
.
extend
(
i
.
owner
.
inputs
)
inputs
.
extend
(
i
.
owner
.
inputs
)
s_input
=
[
scalar
.
Scalar
(
x
.
dtype
)
.
make_variable
()
for
x
in
i
.
owner
.
inputs
]
s_input
=
[
scalar
.
Scalar
(
x
.
dtype
)
.
make_variable
()
for
x
in
i
.
owner
.
inputs
]
s_inputs
.
extend
(
s_input
)
s_inputs
.
extend
(
s_input
)
# print s_input
# print i.owner.op.scalar_op, type(i.owner.op.scalar_op)
s_op
=
i
.
owner
.
op
.
scalar_op
(
*
s_input
)
s_op
=
i
.
owner
.
op
.
scalar_op
(
*
s_input
)
s_g
.
append
(
s_op
)
s_g
.
append
(
s_op
)
# s_g.append(scalar.Mul(*s_input))
elif
not
i
.
owner
:
elif
not
i
.
owner
:
inputs
.
append
(
i
)
inputs
.
append
(
i
)
s_inputs
.
append
(
scalar
.
Scalar
(
i
.
dtype
)
.
make_variable
())
s
=
scalar
.
Scalar
(
i
.
dtype
)
.
make_variable
()
s_inputs
.
append
(
s
)
s_g
.
append
(
s
)
else
:
else
:
print
"local_elemwise_fusion: have an owner."
print
"local_elemwise_fusion: have an owner
that is not an Elemwise
."
return
False
return
False
#TODO: test nb_clients?
if
len
(
node
.
inputs
)
!=
2
:
if
nb_elemwise
==
0
:
print
"local_elemwise_fusion: node have more then 2 inputs."
# print "local_elemwise_fusion: node have no elemwise in inputs. Nothing to fuse."
return
False
if
nb_elemwise
!=
1
:
print
"local_elemwise_fusion: node have more then 1 elemwise in its inputs."
return
False
return
False
if
any
([
len
(
x
.
clients
)
!=
1
for
x
in
node
.
inputs
]):
#len(node.inputs[0].clients)!=1:
print
"local_elemwise_fusion: node have more then 1 clients."
#if one of the inputs have more then 1 clients and it is an intermediate result. We don't fuse.
if
any
([
len
(
x
.
clients
)
!=
1
and
x
.
owner
for
x
in
node
.
inputs
]):
#len(node.inputs[0].clients)!=1:
print
"local_elemwise_fusion: node have more then 1 clients."
,
[
x
.
clients
for
x
in
node
.
inputs
]
return
False
return
False
otype
=
node
.
outputs
[
0
]
.
type
otype
=
node
.
outputs
[
0
]
.
type
# print "local_elemwise_fusion"
# print "local_elemwise_fusion"
# print [type(x) for x in s_inputs]
# print [type(x) for x in s_inputs]
new_out
=
node
.
op
.
scalar_op
(
*
s_g
)
# print "node",node
#print "s_g",s_g,"new_out",new_out, type(new_out), new_out.owner.op, new_out.owner.inputs
# print "node.inputs",node.inputs
# print "node.inputs[0].op",node.inputs[0].op
# print "node.inputs[1].op",node.inputs[1].op
# print "node.outputs",node.outputs
# print "s_g",s_g, [type(x) for x in s_g]
# print "s_inpust",s_inputs
s_new_out
=
node
.
op
.
scalar_op
(
*
s_g
)
# print "s_new_out",s_new_out
#create the composite op.
#create the composite op.
#print "Composite",s_inputs, new_out
C
=
scalar
.
Composite
(
s_inputs
,[
s_new_out
])
C
=
scalar
.
Composite
(
s_inputs
,[
new_out
])
#print "inputs",inputs
#create the new node.
#print type(T.Elemwise(C))
n
=
T
.
Elemwise
(
C
)
.
make_node
(
*
inputs
)
n
=
T
.
Elemwise
(
C
)
.
make_node
(
*
inputs
)
# print n, n.outputs
assert
len
(
n
.
outputs
)
==
1
assert
len
(
n
.
outputs
)
==
1
assert
node
.
outputs
[
0
]
.
dtype
==
n
.
outputs
[
0
]
.
dtype
assert
node
.
outputs
[
0
]
.
dtype
==
n
.
outputs
[
0
]
.
dtype
# print "local_elemwise_fusion: FUSED some elements!"
return
n
.
outputs
return
n
.
outputs
#TODO: check dtype and broadcastable(type)
#register_specialize(local_elemwise_fusion)
#register_specialize(local_elemwise_fusion)
# def make_composite(inputs, outputs):
# def make_composite(inputs, outputs):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论