Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
619dd9d3
提交
619dd9d3
authored
1月 09, 2015
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2383 from nouiz/tests
Fix tests that cause error in the daily buildbot.
上级
1a369c4d
595b29c0
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
46 行增加
和
41 行删除
+46
-41
test_dnn.py
theano/sandbox/cuda/tests/test_dnn.py
+22
-22
test_opt.py
theano/sandbox/cuda/tests/test_opt.py
+1
-1
opt.py
theano/tensor/opt.py
+23
-18
没有找到文件。
theano/sandbox/cuda/tests/test_dnn.py
浏览文件 @
619dd9d3
...
@@ -201,10 +201,10 @@ class TestDnnInferShapes(utt.InferShapeTester):
...
@@ -201,10 +201,10 @@ class TestDnnInferShapes(utt.InferShapeTester):
super
(
TestDnnInferShapes
,
self
)
.
setUp
()
super
(
TestDnnInferShapes
,
self
)
.
setUp
()
def
test_softmax
(
self
):
def
test_softmax
(
self
):
t
=
T
.
tensor4
(
't'
)
t
=
T
.
f
tensor4
(
't'
)
rand_tensor
=
numpy
.
asarray
(
rand_tensor
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
5
,
4
,
3
,
2
),
numpy
.
random
.
rand
(
5
,
4
,
3
,
2
),
dtype
=
theano
.
config
.
floatX
dtype
=
'float32'
)
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
t
],
[
t
],
...
@@ -230,15 +230,15 @@ class TestDnnInferShapes(utt.InferShapeTester):
...
@@ -230,15 +230,15 @@ class TestDnnInferShapes(utt.InferShapeTester):
)
)
def
test_conv
(
self
):
def
test_conv
(
self
):
img
=
T
.
tensor4
(
'img'
)
img
=
T
.
f
tensor4
(
'img'
)
kerns
=
T
.
tensor4
(
'kerns'
)
kerns
=
T
.
f
tensor4
(
'kerns'
)
img_val
=
numpy
.
asarray
(
img_val
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
3
,
4
,
5
,
6
),
numpy
.
random
.
rand
(
3
,
4
,
5
,
6
),
dtype
=
theano
.
config
.
floatX
dtype
=
'float32'
)
)
kern_vals
=
numpy
.
asarray
(
kern_vals
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
3
,
4
,
5
,
6
),
numpy
.
random
.
rand
(
3
,
4
,
5
,
6
),
dtype
=
theano
.
config
.
floatX
dtype
=
'float32'
)
)
for
params
in
product
(
for
params
in
product
(
...
@@ -260,15 +260,15 @@ class TestDnnInferShapes(utt.InferShapeTester):
...
@@ -260,15 +260,15 @@ class TestDnnInferShapes(utt.InferShapeTester):
)
)
def
test_conv_gradw
(
self
):
def
test_conv_gradw
(
self
):
img
=
T
.
tensor4
(
'img'
)
img
=
T
.
f
tensor4
(
'img'
)
kerns
=
T
.
tensor4
(
'kerns'
)
kerns
=
T
.
f
tensor4
(
'kerns'
)
img_val
=
numpy
.
asarray
(
img_val
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
3
,
4
,
5
,
6
),
numpy
.
random
.
rand
(
3
,
4
,
5
,
6
),
dtype
=
theano
.
config
.
floatX
dtype
=
'float32'
)
)
kern_vals
=
numpy
.
asarray
(
kern_vals
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
3
,
4
,
5
,
6
),
numpy
.
random
.
rand
(
3
,
4
,
5
,
6
),
dtype
=
theano
.
config
.
floatX
dtype
=
'float32'
)
)
for
params
in
product
(
for
params
in
product
(
...
@@ -306,15 +306,15 @@ class TestDnnInferShapes(utt.InferShapeTester):
...
@@ -306,15 +306,15 @@ class TestDnnInferShapes(utt.InferShapeTester):
)
)
def
test_conv_gradi
(
self
):
def
test_conv_gradi
(
self
):
img
=
T
.
tensor4
(
'img'
)
img
=
T
.
f
tensor4
(
'img'
)
kerns
=
T
.
tensor4
(
'kerns'
)
kerns
=
T
.
f
tensor4
(
'kerns'
)
img_val
=
numpy
.
asarray
(
img_val
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
3
,
4
,
5
,
6
),
numpy
.
random
.
rand
(
3
,
4
,
5
,
6
),
dtype
=
theano
.
config
.
floatX
dtype
=
'float32'
)
)
kern_vals
=
numpy
.
asarray
(
kern_vals
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
3
,
4
,
5
,
6
),
numpy
.
random
.
rand
(
3
,
4
,
5
,
6
),
dtype
=
theano
.
config
.
floatX
dtype
=
'float32'
)
)
for
params
in
product
(
for
params
in
product
(
...
@@ -349,10 +349,10 @@ class TestDnnInferShapes(utt.InferShapeTester):
...
@@ -349,10 +349,10 @@ class TestDnnInferShapes(utt.InferShapeTester):
)
)
def
test_pool
(
self
):
def
test_pool
(
self
):
img
=
T
.
tensor4
(
'img'
)
img
=
T
.
f
tensor4
(
'img'
)
img_val
=
numpy
.
asarray
(
img_val
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
2
,
3
,
4
,
5
),
numpy
.
random
.
rand
(
2
,
3
,
4
,
5
),
dtype
=
theano
.
config
.
floatX
dtype
=
'float32'
)
)
for
params
in
product
(
for
params
in
product
(
[(
1
,
1
),
(
2
,
2
),
(
3
,
3
)],
[(
1
,
1
),
(
2
,
2
),
(
3
,
3
)],
...
@@ -372,20 +372,20 @@ class TestDnnInferShapes(utt.InferShapeTester):
...
@@ -372,20 +372,20 @@ class TestDnnInferShapes(utt.InferShapeTester):
)
)
def
test_pool_grad
(
self
):
def
test_pool_grad
(
self
):
img
=
T
.
tensor4
(
'img'
)
img
=
T
.
f
tensor4
(
'img'
)
img_grad
=
T
.
tensor4
(
'img_grad'
)
img_grad
=
T
.
f
tensor4
(
'img_grad'
)
out
=
T
.
tensor4
(
'out'
)
out
=
T
.
f
tensor4
(
'out'
)
img_val
=
numpy
.
asarray
(
img_val
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
2
,
3
,
4
,
5
),
numpy
.
random
.
rand
(
2
,
3
,
4
,
5
),
dtype
=
theano
.
config
.
floatX
dtype
=
'float32'
)
)
img_grad_val
=
numpy
.
asarray
(
img_grad_val
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
2
,
3
,
4
,
5
),
numpy
.
random
.
rand
(
2
,
3
,
4
,
5
),
dtype
=
theano
.
config
.
floatX
dtype
=
'float32'
)
)
out_val
=
numpy
.
asarray
(
out_val
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
2
,
3
,
4
,
5
),
numpy
.
random
.
rand
(
2
,
3
,
4
,
5
),
dtype
=
theano
.
config
.
floatX
dtype
=
'float32'
)
)
for
params
in
product
(
for
params
in
product
(
...
...
theano/sandbox/cuda/tests/test_opt.py
浏览文件 @
619dd9d3
...
@@ -81,7 +81,7 @@ def test_gpualloc():
...
@@ -81,7 +81,7 @@ def test_gpualloc():
m
=
(
x
)
.
dimshuffle
([
'x'
,
0
])
m
=
(
x
)
.
dimshuffle
([
'x'
,
0
])
v
=
tensor
.
alloc
(
1.
,
*
m
.
shape
)
v
=
tensor
.
alloc
(
1.
,
*
m
.
shape
)
f
=
theano
.
function
([],
v
+
x
,
f
=
theano
.
function
([],
v
+
x
,
mode
=
mode_with_gpu
.
excluding
(
"local_
alloc_elemwise
"
))
mode
=
mode_with_gpu
.
excluding
(
"local_
elemwise_alloc
"
))
l
=
f
.
maker
.
fgraph
.
toposort
()
l
=
f
.
maker
.
fgraph
.
toposort
()
assert
numpy
.
any
([
isinstance
(
x
.
op
,
cuda
.
GpuAlloc
)
for
x
in
l
])
assert
numpy
.
any
([
isinstance
(
x
.
op
,
cuda
.
GpuAlloc
)
for
x
in
l
])
...
...
theano/tensor/opt.py
浏览文件 @
619dd9d3
...
@@ -1606,6 +1606,7 @@ compile.optdb['specialize'].register('local_remove_all_assert',
...
@@ -1606,6 +1606,7 @@ compile.optdb['specialize'].register('local_remove_all_assert',
local_remove_all_assert
,
local_remove_all_assert
,
use_db_name_as_tag
=
False
)
use_db_name_as_tag
=
False
)
def
local_elemwise_alloc_op
(
ElemwiseOP
,
AllocOP
,
DimShuffleOP
):
def
local_elemwise_alloc_op
(
ElemwiseOP
,
AllocOP
,
DimShuffleOP
):
def
local_elemwise_alloc
(
node
):
def
local_elemwise_alloc
(
node
):
"""
"""
...
@@ -1633,8 +1634,8 @@ def local_elemwise_alloc_op(ElemwiseOP, AllocOP, DimShuffleOP):
...
@@ -1633,8 +1634,8 @@ def local_elemwise_alloc_op(ElemwiseOP, AllocOP, DimShuffleOP):
node
.
outputs
[
0
]
.
type
.
broadcastable
for
o
in
node
.
outputs
[
0
]
.
type
.
broadcastable
for
o
in
node
.
outputs
[
1
:]])
node
.
outputs
[
1
:]])
# The broadcast pattern of the ouptut must match the broadcast
pattern of
# The broadcast pattern of the ouptut must match the broadcast
# at least one of the inputs.
#
pattern of
at least one of the inputs.
if
not
any
([
i
.
type
.
broadcastable
==
if
not
any
([
i
.
type
.
broadcastable
==
node
.
outputs
[
0
]
.
type
.
broadcastable
for
i
in
node
.
inputs
]):
node
.
outputs
[
0
]
.
type
.
broadcastable
for
i
in
node
.
inputs
]):
return
False
return
False
...
@@ -1648,11 +1649,12 @@ def local_elemwise_alloc_op(ElemwiseOP, AllocOP, DimShuffleOP):
...
@@ -1648,11 +1649,12 @@ def local_elemwise_alloc_op(ElemwiseOP, AllocOP, DimShuffleOP):
# DimShuffleOP with an owner that is a AllocOP -- otherwise there is
# DimShuffleOP with an owner that is a AllocOP -- otherwise there is
# nothing to optimize.
# nothing to optimize.
if
not
any
([
i
.
owner
if
not
any
([
i
.
owner
and
(
isinstance
(
i
.
owner
.
op
,
AllocOP
)
or
dimshuffled_alloc
(
i
))
and
(
isinstance
(
i
.
owner
.
op
,
AllocOP
)
or
dimshuffled_alloc
(
i
))
for
i
in
node
.
inputs
]):
for
i
in
node
.
inputs
]):
return
False
return
False
#
#
Search for input that we can use as a baseline for the dimensions.
# Search for input that we can use as a baseline for the dimensions.
assert_op_idx
=
-
1
assert_op_idx
=
-
1
for
idx
,
i
in
enumerate
(
node
.
inputs
):
for
idx
,
i
in
enumerate
(
node
.
inputs
):
if
i
.
type
.
broadcastable
==
node
.
outputs
[
0
]
.
type
.
broadcastable
:
if
i
.
type
.
broadcastable
==
node
.
outputs
[
0
]
.
type
.
broadcastable
:
...
@@ -1666,19 +1668,20 @@ def local_elemwise_alloc_op(ElemwiseOP, AllocOP, DimShuffleOP):
...
@@ -1666,19 +1668,20 @@ def local_elemwise_alloc_op(ElemwiseOP, AllocOP, DimShuffleOP):
# It may be the case that only AllocOP and DimShuffleOP of AllocOP exist.
# It may be the case that only AllocOP and DimShuffleOP of AllocOP exist.
if
assert_op_idx
<
0
:
if
assert_op_idx
<
0
:
# We want to optimize as many allocs as possible. When
there is more
# We want to optimize as many allocs as possible. When
# th
an one then do all but one.
# th
ere is more than one then do all but one. number of
#
number of
inputs with alloc or dimshuffle alloc
# inputs with alloc or dimshuffle alloc
l2
=
[
i
for
i
in
node
.
inputs
l2
=
[
i
for
i
in
node
.
inputs
if
(
i
.
owner
and
(
isinstance
(
i
.
owner
.
op
,
AllocOP
)
if
(
i
.
owner
and
(
isinstance
(
i
.
owner
.
op
,
AllocOP
)
or
dimshuffled_alloc
(
i
)))]
or
dimshuffled_alloc
(
i
)))]
# If only 1 alloc or dimshuffle alloc, it is the one we
will use for the shape
# If only 1 alloc or dimshuffle alloc, it is the one we
# So no alloc would be removed.
#
will use for the shape.
So no alloc would be removed.
if
len
(
l2
)
>
1
:
if
len
(
l2
)
>
1
:
# l containt inputs with alloc or dimshuffle alloc only.
# l containt inputs with alloc or dimshuffle alloc
# Its length will always be at least one, as we checked that before
# only. Its length will always be at least one, as we
# checked that before
l
=
[
idx
for
idx
,
i
in
enumerate
(
node
.
inputs
)
l
=
[
idx
for
idx
,
i
in
enumerate
(
node
.
inputs
)
if
i
.
type
.
broadcastable
==
node
.
outputs
[
0
]
.
type
.
broadcastable
]
if
i
.
broadcastable
==
node
.
outputs
[
0
]
.
broadcastable
]
assert_op_idx
=
l
[
0
]
# The first one is as good as any to use.
assert_op_idx
=
l
[
0
]
# The first one is as good as any to use.
else
:
else
:
# Nothing would be optimized!
# Nothing would be optimized!
...
@@ -1719,7 +1722,8 @@ def local_elemwise_alloc_op(ElemwiseOP, AllocOP, DimShuffleOP):
...
@@ -1719,7 +1722,8 @@ def local_elemwise_alloc_op(ElemwiseOP, AllocOP, DimShuffleOP):
# We add a dimshuffle to add them.
# We add a dimshuffle to add them.
# We let later optimization merge the multiple dimshuffle
# We let later optimization merge the multiple dimshuffle
nb_dim_to_add
=
i
.
owner
.
inputs
[
0
]
.
ndim
-
alloc_input
.
ndim
nb_dim_to_add
=
i
.
owner
.
inputs
[
0
]
.
ndim
-
alloc_input
.
ndim
alloc_input
=
alloc_input
.
dimshuffle
([
'x'
]
*
nb_dim_to_add
+
alloc_input
=
alloc_input
.
dimshuffle
(
[
'x'
]
*
nb_dim_to_add
+
range
(
alloc_input
.
ndim
))
range
(
alloc_input
.
ndim
))
# We need to keep the dimshuffle. It could swap axes or
# We need to keep the dimshuffle. It could swap axes or
...
@@ -1733,13 +1737,14 @@ def local_elemwise_alloc_op(ElemwiseOP, AllocOP, DimShuffleOP):
...
@@ -1733,13 +1737,14 @@ def local_elemwise_alloc_op(ElemwiseOP, AllocOP, DimShuffleOP):
return
local_elemwise_alloc
return
local_elemwise_alloc
#TODO, global optimizer that lift the assert to the beginning of the graph.
#
TODO, global optimizer that lift the assert to the beginning of the graph.
#TODO, optimize all inputs when possible -- currently when all inputs have
#
TODO, optimize all inputs when possible -- currently when all inputs have
# an alloc all but one is optimized.
# an alloc all but one is optimized.
local_elemwise_alloc
=
register_specialize
(
gof
.
local_optimizer
([
T
.
Elemwise
])(
local_elemwise_alloc
=
register_specialize
(
local_elemwise_alloc_op
(
T
.
Elemwise
,
T
.
Alloc
,
T
.
DimShuffle
)
gof
.
local_optimizer
([
T
.
Elemwise
])(
))
local_elemwise_alloc_op
(
T
.
Elemwise
,
T
.
Alloc
,
T
.
DimShuffle
)),
'local_alloc_elemwise'
)
theano
.
configparser
.
AddConfigVar
(
'experimental.local_alloc_elemwise'
,
theano
.
configparser
.
AddConfigVar
(
'experimental.local_alloc_elemwise'
,
"DEPRECATED: If True, enable the experimental"
"DEPRECATED: If True, enable the experimental"
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论