Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4be478ff
提交
4be478ff
authored
10月 21, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed test of canonize that was modifying global mode variables
上级
88b0c613
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
27 行增加
和
4 行删除
+27
-4
test_opt.py
theano/tensor/tests/test_opt.py
+27
-4
没有找到文件。
theano/tensor/tests/test_opt.py
浏览文件 @
4be478ff
...
@@ -246,6 +246,8 @@ class test_canonize(unittest.TestCase):
...
@@ -246,6 +246,8 @@ class test_canonize(unittest.TestCase):
#We must be sure that the Canonizer is working, but that we don't have other
#We must be sure that the Canonizer is working, but that we don't have other
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
mode
=
compile
.
mode
.
predefined_modes
[
compile
.
mode
.
default_mode
]
mode
=
compile
.
mode
.
predefined_modes
[
compile
.
mode
.
default_mode
]
old_optimizer
=
mode
.
_optimizer
try
:
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
for
id
,
[
g
,
sym_inputs
,
val_inputs
,
nb_elemwise
,
out_dtype
]
in
enumerate
(
cases
):
for
id
,
[
g
,
sym_inputs
,
val_inputs
,
nb_elemwise
,
out_dtype
]
in
enumerate
(
cases
):
...
@@ -256,6 +258,8 @@ class test_canonize(unittest.TestCase):
...
@@ -256,6 +258,8 @@ class test_canonize(unittest.TestCase):
out
=
f
(
*
val_inputs
)
out
=
f
(
*
val_inputs
)
assert
(
len
(
f
.
maker
.
env
.
toposort
())
==
nb_elemwise
)
assert
(
len
(
f
.
maker
.
env
.
toposort
())
==
nb_elemwise
)
assert
(
out_dtype
==
out
.
dtype
)
assert
(
out_dtype
==
out
.
dtype
)
finally
:
mode
.
_optimizer
=
old_optimizer
def
test_elemwise_multiple_inputs_optimisation2
(
self
):
def
test_elemwise_multiple_inputs_optimisation2
(
self
):
"""
"""
...
@@ -367,6 +371,8 @@ class test_canonize(unittest.TestCase):
...
@@ -367,6 +371,8 @@ class test_canonize(unittest.TestCase):
#We must be sure that the Canonizer is working, but that we don't have other
#We must be sure that the Canonizer is working, but that we don't have other
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
mode
=
compile
.
mode
.
predefined_modes
[
compile
.
mode
.
default_mode
]
mode
=
compile
.
mode
.
predefined_modes
[
compile
.
mode
.
default_mode
]
old_optimizer
=
mode
.
_optimizer
try
:
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
...
@@ -416,7 +422,7 @@ class test_canonize(unittest.TestCase):
...
@@ -416,7 +422,7 @@ class test_canonize(unittest.TestCase):
#must broadcast as their is a dimshuffle in the computation
#must broadcast as their is a dimshuffle in the computation
((
dx
/
dv
)
/
dx
,[
dx
,
dv
],[
dxv
,
dvv
],
2
,
'float64'
),
((
dx
/
dv
)
/
dx
,[
dx
,
dv
],[
dxv
,
dvv
],
2
,
'float64'
),
#topo: [Elemwise{inv,no_inplace}(<TensorType(float64, row)>), Elemwise{second,no_inplace}(x, Elemwise{inv,no_inplace}.0)]
#topo: [Elemwise{inv,no_inplace}(<TensorType(float64, row)>), Elemwise{second,no_inplace}(x, Elemwise{inv,no_inplace}.0)]
((
fx
/
fv
)
/
fx
,[
fx
,
fv
],[
fxv
,
fvv
],
2
,
'float32'
),
((
fx
/
fv
)
/
fx
,[
fx
,
fv
],[
fxv
,
fvv
],
2
,
'float32'
),
#topo:[Elemwise{inv,no_inplace}(<TensorType(float32, row)>), Elemwise{second,no_inplace}(x, Elemwise{inv,no_inplace}.0)]
#topo:[Elemwise{inv,no_inplace}(<TensorType(float32, row)>), Elemwise{second,no_inplace}(x, Elemwise{inv,no_inplace}.0)]
]):
]):
...
@@ -491,6 +497,8 @@ class test_canonize(unittest.TestCase):
...
@@ -491,6 +497,8 @@ class test_canonize(unittest.TestCase):
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
0
assert
len
(
topo
)
==
0
assert
(
out_dtype
==
out
.
dtype
)
assert
(
out_dtype
==
out
.
dtype
)
finally
:
mode
.
_optimizer
=
old_optimizer
def
test_multiple_case_that_fail
(
self
):
def
test_multiple_case_that_fail
(
self
):
...
@@ -510,10 +518,12 @@ class test_canonize(unittest.TestCase):
...
@@ -510,10 +518,12 @@ class test_canonize(unittest.TestCase):
#We must be sure that the Canonizer is working, but that we don't have other
#We must be sure that the Canonizer is working, but that we don't have other
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion
mode
=
compile
.
mode
.
predefined_modes
[
compile
.
mode
.
default_mode
]
mode
=
compile
.
mode
.
predefined_modes
[
compile
.
mode
.
default_mode
]
old_optimizer
=
mode
.
_optimizer
try
:
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
gof
.
Query
([
"canonicalize"
])
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
mode
.
_optimizer
=
mode
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
#test fail!
#test fail!
#test x / y / z -> x / (y * z)
#test x / y / z -> x / (y * z)
for
(
g
,
sym_inputs
,
val_inputs
,
out_dtype
)
in
[
for
(
g
,
sym_inputs
,
val_inputs
,
out_dtype
)
in
[
((
dx
/
dy
)
/
dz
,[
dx
,
dy
,
dz
],[
dxv
,
dyv
,
dzv
],
'float64'
),
((
dx
/
dy
)
/
dz
,[
dx
,
dy
,
dz
],[
dxv
,
dyv
,
dzv
],
'float64'
),
...
@@ -548,6 +558,9 @@ class test_canonize(unittest.TestCase):
...
@@ -548,6 +558,9 @@ class test_canonize(unittest.TestCase):
assert
len
(
topo
[
0
]
.
inputs
)
==
1
assert
len
(
topo
[
0
]
.
inputs
)
==
1
assert
(
out_dtype
==
out
.
dtype
)
assert
(
out_dtype
==
out
.
dtype
)
finally
:
mode
.
_optimizer
=
old_optimizer
def
test_dont_merge_if_multiple_client
(
self
):
def
test_dont_merge_if_multiple_client
(
self
):
""" test those case take from the comment in Canonizer
""" test those case take from the comment in Canonizer
"""
"""
...
@@ -571,9 +584,15 @@ def test_local_shape_lift_dot():
...
@@ -571,9 +584,15 @@ def test_local_shape_lift_dot():
for
y
in
[
fvector
,
fmatrix
]:
for
y
in
[
fvector
,
fmatrix
]:
i
=
x
()
i
=
x
()
j
=
y
()
j
=
y
()
print
'I SHAPE'
,
i
.
type
.
shape
print
'J SHAPE'
,
j
.
type
.
shape
d
=
shape
(
dot
(
i
,
j
))
d
=
shape
(
dot
(
i
,
j
))
if
x
is
fvector
and
y
is
fvector
:
assert
d
==
()
else
:
g
=
Env
([
i
,
j
],
[
d
])
g
=
Env
([
i
,
j
],
[
d
])
gof
.
TopoOptimizer
(
gof
.
LocalOptGroup
(
local_shape_lift_dot
),
order
=
'out_to_in'
)
.
optimize
(
g
)
gof
.
TopoOptimizer
(
gof
.
LocalOptGroup
(
local_shape_lift_dot
),
order
=
'out_to_in'
)
.
optimize
(
g
)
print
pprint
(
g
.
outputs
[
0
]),
args_to_result
[(
x
,
y
)]
assert
pprint
(
g
.
outputs
[
0
])
==
args_to_result
[(
x
,
y
)]
assert
pprint
(
g
.
outputs
[
0
])
==
args_to_result
[(
x
,
y
)]
# def test_plusmin(self):
# def test_plusmin(self):
...
@@ -982,8 +1001,10 @@ class test_fusion(unittest.TestCase):
...
@@ -982,8 +1001,10 @@ class test_fusion(unittest.TestCase):
#Follow up. Clinker do the same... second cause?
#Follow up. Clinker do the same... second cause?
mode2
=
compile
.
Mode
(
linker
(),
copy
.
copy
(
compile
.
mode
.
OPT_FAST_RUN
))
mode2
=
compile
.
Mode
(
linker
(),
copy
.
copy
(
compile
.
mode
.
OPT_FAST_RUN
))
# mode2=copy.copy(compile.mode.predefined_modes['FAST_RUN'])
# mode2=copy.copy(compile.mode.predefined_modes['FAST_RUN'])
old_optimizer
=
mode2
.
_optimizer
try
:
mode2
.
_optimizer
=
mode2
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
mode2
.
_optimizer
=
mode2
.
_optimizer
.
excluding
(
'local_elemwise_fusion'
)
# mode2=compile.Mode(gof.OpWiseCLinker(allow_gc=True), compile.mode.OPT_FAST_COMPILE)
# mode2=compile.Mode(gof.OpWiseCLinker(allow_gc=True), compile.mode.OPT_FAST_COMPILE)
if
s
is
None
:
if
s
is
None
:
s
=
slice
(
0
,
49
)
s
=
slice
(
0
,
49
)
...
@@ -997,8 +1018,10 @@ class test_fusion(unittest.TestCase):
...
@@ -997,8 +1018,10 @@ class test_fusion(unittest.TestCase):
print
"times2 FAST_RUN optimisation without local_elemwise_fusion"
print
"times2 FAST_RUN optimisation without local_elemwise_fusion"
print
times2
,
times2
.
min
(),
times2
.
max
(),
times2
.
sum
()
print
times2
,
times2
.
min
(),
times2
.
max
(),
times2
.
sum
()
d
=
times2
/
times1
d
=
times2
/
times1
# d.sort()
# d.sort()
print
"times2/times1"
,
d
,
d
.
min
(),
d
.
max
(),
d
.
mean
(),
d
.
std
()
print
"times2/times1"
,
d
,
d
.
min
(),
d
.
max
(),
d
.
mean
(),
d
.
std
()
finally
:
mode2
.
_optimizer
=
old_optimizer
def
speed_fusion_gpu
(
self
):
def
speed_fusion_gpu
(
self
):
import
theano_cuda_ndarray
as
tcn
import
theano_cuda_ndarray
as
tcn
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论