Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
454eba0c
提交
454eba0c
authored
8月 05, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make Elemwise fusion work inplace
上级
7b8526b6
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
39 行增加
和
5 行删除
+39
-5
basic.py
theano/scalar/basic.py
+15
-1
opt.py
theano/tensor/opt.py
+10
-4
test_opt.py
theano/tensor/tests/test_opt.py
+14
-0
没有找到文件。
theano/scalar/basic.py
浏览文件 @
454eba0c
...
@@ -1669,7 +1669,21 @@ class Composite(ScalarOp):
...
@@ -1669,7 +1669,21 @@ class Composite(ScalarOp):
return
"
%
s{
%
s}"
%
(
self
.
__class__
.
__name__
,
", "
.
join
(
return
"
%
s{
%
s}"
%
(
self
.
__class__
.
__name__
,
", "
.
join
(
"
%
s=
%
s"
%
(
k
,
v
)
for
k
,
v
in
self
.
__dict__
.
items
()
"
%
s=
%
s"
%
(
k
,
v
)
for
k
,
v
in
self
.
__dict__
.
items
()
if
k
not
in
[
"env"
,
"_c_code"
,
"_cmodule_key"
,
"_impls"
,
if
k
not
in
[
"env"
,
"_c_code"
,
"_cmodule_key"
,
"_impls"
,
"_hashval"
]
))
"_hashval"
,
"inputs_type"
]
))
def
make_new_inplace
(
self
,
output_types_preference
=
None
,
name
=
None
):
"""
This op.__init__ fct don't have the same parameter as other scalar op.
This break the insert_inplace_optimizer optimization.
This fct allow fix patch this.
"""
out
=
self
.
__class__
(
self
.
inputs
,
self
.
outputs
)
if
name
:
out
.
name
=
name
else
:
name
=
out
.
name
super
(
Composite
,
out
)
.
__init__
(
output_types_preference
,
name
)
return
out
def
__init__
(
self
,
inputs
,
outputs
):
def
__init__
(
self
,
inputs
,
outputs
):
self
.
inputs
=
copy
(
inputs
)
self
.
inputs
=
copy
(
inputs
)
...
...
theano/tensor/opt.py
浏览文件 @
454eba0c
...
@@ -125,12 +125,18 @@ def insert_inplace_optimizer(env):
...
@@ -125,12 +125,18 @@ def insert_inplace_optimizer(env):
inplace_pattern
=
dict
(
baseline
,
**
{
candidate_output
:
candidate_input
})
inplace_pattern
=
dict
(
baseline
,
**
{
candidate_output
:
candidate_input
})
try
:
try
:
new
=
Elemwise
(
if
hasattr
(
op
.
scalar_op
,
"make_new_inplace"
):
op
.
scalar_op
.
__class__
(
new_scal
=
op
.
scalar_op
.
make_new_inplace
(
scalar
.
transfer_type
(
scalar
.
transfer_type
(
*
[
inplace_pattern
.
get
(
i
,
None
)
\
*
[
inplace_pattern
.
get
(
i
,
None
)
\
for
i
in
xrange
(
len
(
node
.
outputs
))])),
for
i
in
xrange
(
len
(
node
.
outputs
))]))
inplace_pattern
)
.
make_node
(
*
node
.
inputs
)
else
:
new_scal
=
op
.
scalar_op
.
__class__
(
scalar
.
transfer_type
(
*
[
inplace_pattern
.
get
(
i
,
None
)
\
for
i
in
xrange
(
len
(
node
.
outputs
))]))
new
=
Elemwise
(
new_scal
,
inplace_pattern
)
.
make_node
(
*
node
.
inputs
)
env
.
replace_all_validate
(
zip
(
node
.
outputs
,
new
.
outputs
),
env
.
replace_all_validate
(
zip
(
node
.
outputs
,
new
.
outputs
),
reason
=
"insert_inplace_optimizer"
)
reason
=
"insert_inplace_optimizer"
)
except
(
ValueError
,
TypeError
,
InconsistencyError
),
e
:
except
(
ValueError
,
TypeError
,
InconsistencyError
),
e
:
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
454eba0c
...
@@ -886,6 +886,20 @@ class test_fusion(unittest.TestCase):
...
@@ -886,6 +886,20 @@ class test_fusion(unittest.TestCase):
print
d
print
d
print
"min"
,
d
.
min
(),
"argmin"
,
d
.
argmin
(),
"max"
,
d
.
max
(),
"mean"
,
d
.
mean
(),
"std"
,
d
.
std
()
print
"min"
,
d
.
min
(),
"argmin"
,
d
.
argmin
(),
"max"
,
d
.
max
(),
"mean"
,
d
.
mean
(),
"std"
,
d
.
std
()
def
test_fusion_inplace
(
self
):
mode
=
cp
(
compile
.
mode
.
get_default_mode
())
#we need the optimisation enabled and the canonicalize.
#the canonicalize is needed to merge multiplication/addition by constant.
mode
.
_optimizer
=
mode
.
_optimizer
.
including
(
'local_elemwise_fusion'
,
'canonicalize'
,
'inplace'
)
x
,
y
,
z
=
dmatrices
(
'xyz'
)
f
=
theano
.
function
([
x
,
y
,
z
],
dot
(
x
,
y
)
+
x
+
y
+
z
,
mode
=
mode
)
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
2
assert
f
.
maker
.
env
.
toposort
()[
-
1
]
.
op
.
inplace_pattern
f
(
numpy
.
random
.
random
((
5
,
5
)),
numpy
.
random
.
random
((
5
,
5
)),
numpy
.
random
.
random
((
5
,
5
)))
def
speed_fusion_gpu
(
self
):
def
speed_fusion_gpu
(
self
):
import
theano.sandbox.cuda
as
cuda
import
theano.sandbox.cuda
as
cuda
self
.
speed_fusion
(
shared_fn
=
tcn
.
float32_shared_constructor
,
gpu
=
True
,
s
=
slice
(
0
,
15
))
self
.
speed_fusion
(
shared_fn
=
tcn
.
float32_shared_constructor
,
gpu
=
True
,
s
=
slice
(
0
,
15
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论