Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a3f8d397
提交
a3f8d397
authored
9月 06, 2017
作者:
affanv14
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Speed up tests by calling optimiser directly
上级
9b3f6351
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
123 行增加
和
106 行删除
+123
-106
test_opt.py
theano/gpuarray/tests/test_opt.py
+123
-106
没有找到文件。
theano/gpuarray/tests/test_opt.py
浏览文件 @
a3f8d397
...
@@ -25,7 +25,7 @@ from ..linalg import GpuCusolverSolve, cusolver_available, GpuCholesky
...
@@ -25,7 +25,7 @@ from ..linalg import GpuCusolverSolve, cusolver_available, GpuCholesky
from
.config
import
mode_with_gpu
,
mode_without_gpu
,
test_ctx_name
,
SkipTest
from
.config
import
mode_with_gpu
,
mode_without_gpu
,
test_ctx_name
,
SkipTest
import
unittest
import
unittest
from
theano.tensor.nnet
import
abstract_conv
from
theano.tensor.nnet
import
abstract_conv
from
theano.gpuarray
import
dnn
,
blas
from
theano.gpuarray
import
dnn
,
blas
,
opt
def
_check_stack_trace
(
thing
):
def
_check_stack_trace
(
thing
):
...
@@ -773,55 +773,53 @@ class Conv_opt_test(unittest.TestCase):
...
@@ -773,55 +773,53 @@ class Conv_opt_test(unittest.TestCase):
def
optimizer_2d
(
self
,
input_shapes
,
direction
,
include_tags
,
exclude_tags
,
def
optimizer_2d
(
self
,
input_shapes
,
direction
,
include_tags
,
exclude_tags
,
op
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
op
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
filter_dilation
=
(
1
,
1
),
num_groups
=
1
):
filter_dilation
=
(
1
,
1
),
num_groups
=
1
,
optimiser
=
None
):
inp1
=
theano
.
shared
(
np
.
random
.
random
(
input_shapes
[
0
])
.
astype
(
theano
.
config
.
floatX
))
inp1
=
theano
.
shared
(
np
.
random
.
random
(
input_shapes
[
0
])
.
astype
(
theano
.
config
.
floatX
))
inp2
=
theano
.
shared
(
np
.
random
.
random
(
input_shapes
[
1
])
.
astype
(
theano
.
config
.
floatX
))
inp2
=
theano
.
shared
(
np
.
random
.
random
(
input_shapes
[
1
])
.
astype
(
theano
.
config
.
floatX
))
if
op
is
None
:
inp1
=
basic_ops
.
as_gpuarray_variable
(
inp1
,
test_ctx_name
)
inp2
=
basic_ops
.
as_gpuarray_variable
(
inp2
,
test_ctx_name
)
if
(
direction
==
0
):
if
(
direction
==
0
):
conv_op
=
abstract_conv
.
conv2d
(
inp1
,
conv_op
=
abstract_conv
.
AbstractConv2d
(
input_shapes
[
0
],
inp2
,
input_shapes
[
1
],
input_shapes
[
0
],
border_mode
=
border_mode
,
input_shapes
[
1
],
subsample
=
subsample
,
border_mode
=
border_mode
,
filter_dilation
=
filter_dilation
,
subsample
=
subsample
,
num_groups
=
num_groups
)(
inp1
,
inp2
)
filter_dilation
=
filter_dilation
,
num_groups
=
num_groups
)
if
(
direction
==
1
):
if
(
direction
==
1
):
conv_op
=
abstract_conv
.
conv2d_grad_wrt_weights
(
inp1
,
conv_op
=
abstract_conv
.
AbstractConv2d_gradWeights
(
imshp
=
input_shapes
[
0
]
,
inp2
,
kshp
=
input_shapes
[
2
]
,
input_shapes
[
2
]
,
border_mode
=
border_mode
,
input_shapes
[
0
]
,
subsample
=
subsample
,
border_mode
=
border_mode
,
filter_dilation
=
filter_dilation
,
subsample
=
subsample
,
num_groups
=
num_groups
)(
inp1
,
filter_dilation
=
filter_dilation
,
inp2
,
num_groups
=
num_groups
)
input_shapes
[
2
][
-
2
:]
)
if
(
direction
==
2
):
if
(
direction
==
2
):
conv_op
=
abstract_conv
.
conv2d_grad_wrt_inputs
(
inp1
,
conv_op
=
abstract_conv
.
AbstractConv2d_gradInputs
(
imshp
=
input_shapes
[
2
]
,
inp2
,
kshp
=
input_shapes
[
1
]
,
input_shapes
[
2
]
,
border_mode
=
border_mode
,
input_shapes
[
1
]
,
subsample
=
subsample
,
border_mode
=
border_mode
,
filter_dilation
=
filter_dilation
,
subsample
=
subsample
,
num_groups
=
num_groups
)(
inp2
,
filter_dilation
=
filter_dilation
,
inp1
,
num_groups
=
num_groups
)
input_shapes
[
2
][
-
2
:]
)
theano
.
config
.
metaopt
.
optimizer_including
=
include_tags
theano
.
config
.
metaopt
.
optimizer_including
=
include_tags
theano
.
config
.
metaopt
.
optimizer_excluding
=
exclude_tags
theano
.
config
.
metaopt
.
optimizer_excluding
=
exclude_tags
mode
=
mode_with_gpu
.
including
(
'conv_meta'
)
.
excluding
(
'conv_dnn'
)
.
excluding
(
'conv_gemm'
)
mode
=
mode_with_gpu
.
including
(
'conv_meta'
)
.
excluding
(
'conv_dnn'
)
.
excluding
(
'conv_gemm'
)
ref_func
=
theano
.
function
([],
conv_op
,
mode
=
mode_with_gpu
)
# All meta optimizer compile a new function. This need to know
# All meta optimizer compile a new function. This need to know
# the current linker, but this information is not available,
# the current linker, but this information is not available,
# so it use the default mode.
# so it use the default mode.
if
op
is
None
:
if
op
is
None
:
# No convolutions optimization takes place
# No convolutions optimization takes place
with
theano
.
change_flags
(
mode
=
mode
):
assert
optimiser
.
transform
(
conv_op
.
owner
)
is
None
with
self
.
assertRaises
(
AssertionError
):
theano
.
function
([],
conv_op
,
mode
=
mode
)
return
else
:
else
:
ref_func
=
theano
.
function
([],
conv_op
,
mode
=
mode_with_gpu
)
with
theano
.
change_flags
(
mode
=
mode
):
with
theano
.
change_flags
(
mode
=
mode
):
conv_func
=
theano
.
function
([],
conv_op
,
mode
=
mode
)
conv_func
=
theano
.
function
([],
conv_op
,
mode
=
mode
)
assert
any
([
isinstance
(
node
.
op
,
op
)
assert
any
([
isinstance
(
node
.
op
,
op
)
...
@@ -830,52 +828,51 @@ class Conv_opt_test(unittest.TestCase):
...
@@ -830,52 +828,51 @@ class Conv_opt_test(unittest.TestCase):
def
optimizer_3d
(
self
,
input_shapes
,
direction
,
include_tags
,
exclude_tags
,
def
optimizer_3d
(
self
,
input_shapes
,
direction
,
include_tags
,
exclude_tags
,
op
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
,
1
),
op
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
,
1
),
filter_dilation
=
(
1
,
1
,
1
),
num_groups
=
1
):
filter_dilation
=
(
1
,
1
,
1
),
num_groups
=
1
,
optimiser
=
None
):
inp1
=
theano
.
shared
(
np
.
random
.
random
(
input_shapes
[
0
])
.
astype
(
theano
.
config
.
floatX
))
inp1
=
theano
.
shared
(
np
.
random
.
random
(
input_shapes
[
0
])
.
astype
(
theano
.
config
.
floatX
))
inp2
=
theano
.
shared
(
np
.
random
.
random
(
input_shapes
[
1
])
.
astype
(
theano
.
config
.
floatX
))
inp2
=
theano
.
shared
(
np
.
random
.
random
(
input_shapes
[
1
])
.
astype
(
theano
.
config
.
floatX
))
if
op
is
None
:
inp1
=
basic_ops
.
as_gpuarray_variable
(
inp1
,
None
)
inp2
=
basic_ops
.
as_gpuarray_variable
(
inp2
,
None
)
if
(
direction
==
0
):
if
(
direction
==
0
):
conv_op
=
abstract_conv
.
conv3d
(
inp1
,
conv_op
=
abstract_conv
.
AbstractConv3d
(
input_shapes
[
0
],
inp2
,
input_shapes
[
1
],
input_shapes
[
0
],
border_mode
=
border_mode
,
input_shapes
[
1
],
subsample
=
subsample
,
border_mode
=
border_mode
,
filter_dilation
=
filter_dilation
,
subsample
=
subsample
,
num_groups
=
num_groups
)(
inp1
,
inp2
)
filter_dilation
=
filter_dilation
,
num_groups
=
num_groups
)
if
(
direction
==
1
):
if
(
direction
==
1
):
conv_op
=
abstract_conv
.
conv3d_grad_wrt_weights
(
inp1
,
conv_op
=
abstract_conv
.
AbstractConv3d_gradWeights
(
input_shapes
[
0
]
,
inp2
,
input_shapes
[
2
]
,
input_shapes
[
2
]
,
border_mode
=
border_mode
,
input_shapes
[
0
]
,
subsample
=
subsample
,
border_mode
=
border_mode
,
filter_dilation
=
filter_dilation
,
subsample
=
subsample
,
num_groups
=
num_groups
)(
inp1
,
filter_dilation
=
filter_dilation
,
inp2
,
num_groups
=
num_groups
)
input_shapes
[
2
][
-
3
:]
)
if
(
direction
==
2
):
if
(
direction
==
2
):
conv_op
=
abstract_conv
.
conv3d_grad_wrt_inputs
(
inp1
,
conv_op
=
abstract_conv
.
AbstractConv3d_gradInputs
(
input_shapes
[
2
]
,
inp2
,
input_shapes
[
1
]
,
input_shapes
[
2
]
,
border_mode
=
border_mode
,
input_shapes
[
1
]
,
subsample
=
subsample
,
border_mode
=
border_mode
,
filter_dilation
=
filter_dilation
,
subsample
=
subsample
,
num_groups
=
num_groups
)(
inp2
,
filter_dilation
=
filter_dilation
,
inp1
,
num_groups
=
num_groups
)
input_shapes
[
2
][
-
3
:]
)
theano
.
config
.
metaopt
.
optimizer_including
=
include_tags
theano
.
config
.
metaopt
.
optimizer_including
=
include_tags
theano
.
config
.
metaopt
.
optimizer_excluding
=
exclude_tags
theano
.
config
.
metaopt
.
optimizer_excluding
=
exclude_tags
mode
=
mode_with_gpu
.
including
(
'conv_meta'
)
.
excluding
(
'conv_dnn'
)
.
excluding
(
'conv_gemm'
)
mode
=
mode_with_gpu
.
including
(
'conv_meta'
)
.
excluding
(
'conv_dnn'
)
.
excluding
(
'conv_gemm'
)
ref_func
=
theano
.
function
([],
conv_op
,
mode
=
mode_with_gpu
)
# All meta optimizer compile a new function. This need to know
# All meta optimizer compile a new function. This need to know
# the current linker, but this information is not available,
# the current linker, but this information is not available,
# so it use the default mode.
# so it use the default mode.
if
op
is
None
:
if
op
is
None
:
# No convolutions optimization takes place
# No convolutions optimization takes place
with
theano
.
change_flags
(
mode
=
mode
):
assert
optimiser
.
transform
(
conv_op
.
owner
)
is
None
with
self
.
assertRaises
(
AssertionError
):
theano
.
function
([],
conv_op
,
mode
=
mode
)
return
return
elif
op
!=
'conv3d2d'
:
elif
op
!=
'conv3d2d'
:
with
theano
.
change_flags
(
mode
=
mode
):
with
theano
.
change_flags
(
mode
=
mode
):
...
@@ -887,7 +884,7 @@ class Conv_opt_test(unittest.TestCase):
...
@@ -887,7 +884,7 @@ class Conv_opt_test(unittest.TestCase):
conv_func
=
theano
.
function
(
conv_func
=
theano
.
function
(
[],
conv_op
,
[],
conv_op
,
mode
=
mode_with_gpu
.
including
(
'conv_meta'
))
mode
=
mode_with_gpu
.
including
(
'conv_meta'
))
ref_func
=
theano
.
function
([],
conv_op
,
mode
=
mode_with_gpu
)
utt
.
assert_allclose
(
conv_func
(),
ref_func
())
utt
.
assert_allclose
(
conv_func
(),
ref_func
())
def
test_optimizers_2d
(
self
):
def
test_optimizers_2d
(
self
):
...
@@ -1158,91 +1155,111 @@ class Conv_opt_test(unittest.TestCase):
...
@@ -1158,91 +1155,111 @@ class Conv_opt_test(unittest.TestCase):
dnn
.
GpuDnnConvGradI
,
dnn
.
GpuDnnConvGradI
,
num_groups
=
groups
)
num_groups
=
groups
)
def
test_returns_none
(
self
):
def
test_returns_none
_2d
(
self
):
if
theano
.
config
.
cxx
==
""
:
if
theano
.
config
.
cxx
==
""
:
raise
SkipTest
(
"Need a c compiler."
)
raise
SkipTest
(
"Need a c compiler."
)
# values given dont matter since it returns None
# values given dont matter since it returns None
imshp
=
(
2
,
3
,
5
,
5
)
imshp
=
(
2
,
3
,
5
,
5
)
kshp
=
(
4
,
3
,
3
,
3
)
kshp
=
(
4
,
3
,
3
,
3
)
tshp
=
(
2
,
4
,
3
,
3
)
tshp
=
(
2
,
4
,
3
,
3
)
exclude_string
=
[
'conv_dnn:default'
,
'conv_gemm:default'
]
conv_direction
=
[
0
,
1
,
2
]
conv_direction
=
[
0
,
1
,
2
]
optimisers
=
[[
opt
.
local_abstractconv_gemm_alt
,
opt
.
local_abstractconv_cudnn_alt
],
[
opt
.
local_abstractconv_gemm_gradweights_alt
,
opt
.
local_abstractconv_cudnn_alt
],
[
opt
.
local_abstractconv_gradinputs_gemm_alt
,
opt
.
local_abstractconv_cudnn_alt
]]
# test that non default subsample returns None
# test that non default subsample returns None
for
string
in
exclude_string
:
for
opt_direction
,
direction
in
zip
(
optimisers
,
conv_direction
)
:
for
direction
in
conv
_direction
:
for
optimiser
in
opt
_direction
:
self
.
optimizer_2d
([
imshp
,
kshp
,
tshp
],
self
.
optimizer_2d
([
imshp
,
kshp
,
tshp
],
direction
,
direction
,
'
alternative
'
,
''
,
string
,
''
,
None
,
None
,
subsample
=
(
2
,
2
))
subsample
=
(
2
,
2
),
optimiser
=
optimiser
)
# test that non default num_groups returns None
# test that non default num_groups returns None
for
string
in
exclude_string
:
for
opt_direction
,
direction
in
zip
(
optimisers
,
conv_direction
)
:
for
direction
in
conv
_direction
:
for
optimiser
in
opt
_direction
:
self
.
optimizer_2d
([
imshp
,
kshp
,
tshp
],
self
.
optimizer_2d
([
imshp
,
kshp
,
tshp
],
direction
,
direction
,
'
alternative
'
,
''
,
string
,
''
,
None
,
None
,
num_groups
=
3
)
num_groups
=
3
,
optimiser
=
optimiser
)
# test that border_mode=half returns None
# test that border_mode=half returns None
for
string
in
exclude_string
:
for
opt_direction
,
direction
in
zip
(
optimisers
,
conv_direction
)
:
for
direction
in
conv
_direction
:
for
optimiser
in
opt
_direction
:
self
.
optimizer_2d
([
imshp
,
kshp
,
tshp
],
self
.
optimizer_2d
([
imshp
,
kshp
,
tshp
],
direction
,
direction
,
'
alternative
'
,
''
,
string
,
''
,
None
,
None
,
border_mode
=
'half'
)
border_mode
=
'half'
,
optimiser
=
optimiser
)
# test that Non-default filter dilation return None for
# test that Non-default filter dilation return None for
# direction 1
# direction 1
for
string
in
exclude_string
:
for
optimiser
in
optimisers
[
1
]:
direction
=
1
self
.
optimizer_2d
([
imshp
,
kshp
,
tshp
],
self
.
optimizer_2d
([
imshp
,
kshp
,
tshp
],
direction
,
1
,
'
alternative
'
,
''
,
'
conv_dnn:default
'
,
''
,
None
,
None
,
filter_dilation
=
(
2
,
2
))
filter_dilation
=
(
2
,
2
),
optimiser
=
optimiser
)
def
test_returns_none_3d
(
self
):
if
theano
.
config
.
cxx
==
""
:
raise
SkipTest
(
"Need a c compiler."
)
imshp
=
(
2
,
3
,
5
,
5
,
5
)
imshp
=
(
2
,
3
,
5
,
5
,
5
)
kshp
=
(
4
,
3
,
3
,
3
,
3
)
kshp
=
(
4
,
3
,
3
,
3
,
3
)
tshp
=
(
2
,
4
,
3
,
3
,
3
)
tshp
=
(
2
,
4
,
3
,
3
,
3
)
exclude_string
=
[
'conv_dnn:default'
,
'conv_gemm:default'
]
conv_direction
=
[
0
,
1
,
2
]
optimisers
=
[[
opt
.
local_abstractconv3d_alt
,
opt
.
local_abstractconv3d_cudnn_alt
],
[
opt
.
local_abstractconv3d_gemm_gradweights_alt
,
opt
.
local_abstractconv3d_cudnn_alt
],
[
opt
.
local_abstractconv3d_gradinputs_gemm_alt
,
opt
.
local_abstractconv3d_cudnn_alt
]]
# test that non default subsample returns None
# test that non default subsample returns None
for
string
in
exclude_string
:
for
opt_direction
,
direction
in
zip
(
optimisers
,
conv_direction
)
:
for
direction
in
conv
_direction
:
for
optimiser
in
opt
_direction
:
self
.
optimizer_3d
([
imshp
,
kshp
,
tshp
],
self
.
optimizer_3d
([
imshp
,
kshp
,
tshp
],
direction
,
direction
,
'
alternative
'
,
''
,
string
,
''
,
None
,
None
,
subsample
=
(
2
,
2
,
2
))
subsample
=
(
2
,
2
,
2
),
optimiser
=
optimiser
)
# test that non default num_groups returns None
# test that non default num_groups returns None
for
string
in
exclude_string
:
for
opt_direction
,
direction
in
zip
(
optimisers
,
conv_direction
)
:
for
direction
in
conv
_direction
:
for
optimiser
in
opt
_direction
:
self
.
optimizer_3d
([
imshp
,
kshp
,
tshp
],
self
.
optimizer_3d
([
imshp
,
kshp
,
tshp
],
direction
,
direction
,
'
alternative
'
,
''
,
string
,
''
,
None
,
None
,
num_groups
=
3
)
num_groups
=
3
,
optimiser
=
optimiser
)
# test that border_mode=half returns None
# test that border_mode=half returns None
for
string
in
exclude_string
:
for
opt_direction
,
direction
in
zip
(
optimisers
,
conv_direction
)
:
for
direction
in
conv
_direction
:
for
optimiser
in
opt
_direction
:
self
.
optimizer_3d
([
imshp
,
kshp
,
tshp
],
self
.
optimizer_3d
([
imshp
,
kshp
,
tshp
],
direction
,
direction
,
'
alternative
'
,
''
,
string
,
''
,
None
,
None
,
border_mode
=
'half'
)
border_mode
=
'half'
,
optimiser
=
optimiser
)
# test that Non-default filter dilation return None for
# test that Non-default filter dilation return None for
# direction 1
# direction 1
for
string
in
exclude_string
:
for
optimiser
in
optimisers
[
1
]:
direction
=
1
self
.
optimizer_3d
([
imshp
,
kshp
,
tshp
],
self
.
optimizer_3d
([
imshp
,
kshp
,
tshp
],
direction
,
1
,
'
alternative
'
,
''
,
string
,
''
,
None
,
None
,
filter_dilation
=
(
2
,
2
,
2
))
filter_dilation
=
(
2
,
2
,
2
),
optimiser
=
optimiser
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论