Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d2677090
提交
d2677090
authored
7月 28, 2017
作者:
affanv14
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add basic tests
上级
0f4eb0e1
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
133 行增加
和
0 行删除
+133
-0
test_opt.py
theano/gpuarray/tests/test_opt.py
+133
-0
没有找到文件。
theano/gpuarray/tests/test_opt.py
浏览文件 @
d2677090
...
@@ -22,6 +22,30 @@ from ..subtensor import GpuSubtensor
...
@@ -22,6 +22,30 @@ from ..subtensor import GpuSubtensor
from
..linalg
import
GpuCusolverSolve
,
cusolver_available
,
GpuCholesky
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
from
theano.tensor.nnet.abstract_conv
import
(
AbstractConv2d
,
AbstractConv2d_gradInputs
,
AbstractConv2d_gradWeights
,
AbstractConv3d
,
AbstractConv3d_gradWeights
,
AbstractConv3d_gradInputs
,
conv2d
,
conv2d_grad_wrt_weights
,
conv2d_grad_wrt_inputs
,
conv3d
,
conv3d_grad_wrt_weights
,
conv3d_grad_wrt_inputs
)
from
theano.gpuarray.opt
import
(
local_abstractconv_gemm_alternative
,
local_abstractconv_gemm_gradweights_alt
,
local_abstractconv_gradinputs_gemm_alt
,
local_abstractconv_cudnn_alternative
,
local_abstractconv3d2d
,
local_abstractconv3d_alt
,
local_abstractconv3d_gemm_gradweights_alt
,
local_abstractconv3d_gradinputs_gemm_alt
,
local_abstractconv3d_cudnn_alternative
,
local_conv_gpu_conv
)
def
test_local_assert
():
def
test_local_assert
():
...
@@ -699,3 +723,112 @@ def test_crossentropycategorical1hot_lifter():
...
@@ -699,3 +723,112 @@ def test_crossentropycategorical1hot_lifter():
for
n
in
f
.
maker
.
fgraph
.
apply_nodes
)
for
n
in
f
.
maker
.
fgraph
.
apply_nodes
)
f
(
rng
.
uniform
(
0.1
,
0.9
,
(
13
,
5
))
.
astype
(
theano
.
config
.
floatX
),
f
(
rng
.
uniform
(
0.1
,
0.9
,
(
13
,
5
))
.
astype
(
theano
.
config
.
floatX
),
rng
.
randint
(
5
,
size
=
(
13
,)))
rng
.
randint
(
5
,
size
=
(
13
,)))
class
Conv_opt_test
(
unittest
.
TestCase
):
def
optimizer_2d
(
self
,
input_shapes
,
direction
,
optimizer
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
filter_dilation
=
(
1
,
1
)):
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
))
if
(
direction
==
0
):
abstract_op
=
AbstractConv2d
conv_op
=
conv2d
(
inp1
,
inp2
,
border_mode
=
border_mode
,
subsample
=
subsample
,
filter_dilation
=
filter_dilation
)
if
(
direction
==
1
):
abstract_op
=
AbstractConv2d_gradWeights
conv_op
=
conv2d_grad_wrt_weights
(
inp1
,
inp2
,
input_shapes
[
2
],
border_mode
=
border_mode
,
subsample
=
subsample
,
filter_dilation
=
filter_dilation
)
if
(
direction
==
2
):
abstract_op
=
AbstractConv2d_gradInputs
conv_op
=
conv2d_grad_wrt_inputs
(
inp1
,
inp2
,
input_shapes
[
2
],
border_mode
=
border_mode
,
subsample
=
subsample
,
filter_dilation
=
filter_dilation
)
ref_func
=
theano
.
function
([],
conv_op
)
conv_node
=
conv_op
.
owner
if
isinstance
(
conv_node
.
op
,
abstract_op
):
conv_op
=
local_conv_gpu_conv
.
transform
(
conv_node
)
if
isinstance
(
conv_node
.
op
,
abstract_op
):
conv_op
=
optimizer
.
transform
(
conv_op
[
0
]
.
owner
.
inputs
[
0
]
.
owner
)
conv_func
=
theano
.
function
([],
conv_op
[
0
])
assert
not
any
([
isinstance
(
node
.
op
,
abstract_op
)
for
node
in
conv_func
.
maker
.
fgraph
.
toposort
()])
utt
.
assert_allclose
(
conv_func
(),
ref_func
())
def
optimizer_3d
(
self
,
input_shapes
,
direction
,
optimizer
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
,
1
),
filter_dilation
=
(
1
,
1
,
1
)):
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
))
if
(
direction
==
0
):
abstract_op
=
AbstractConv3d
conv_op
=
conv3d
(
inp1
,
inp2
)
if
(
direction
==
1
):
abstract_op
=
AbstractConv3d_gradWeights
conv_op
=
conv3d_grad_wrt_weights
(
inp1
,
inp2
,
input_shapes
[
2
])
if
(
direction
==
2
):
abstract_op
=
AbstractConv3d_gradInputs
conv_op
=
conv3d_grad_wrt_inputs
(
inp1
,
inp2
,
input_shapes
[
2
])
ref_func
=
theano
.
function
([],
conv_op
)
conv_node
=
conv_op
.
owner
if
isinstance
(
conv_node
.
op
,
abstract_op
):
conv_op
=
local_conv_gpu_conv
.
transform
(
conv_node
)
if
isinstance
(
conv_node
.
op
,
abstract_op
):
conv_op
=
optimizer
.
transform
(
conv_op
[
0
]
.
owner
.
inputs
[
0
]
.
owner
)
conv_func
=
theano
.
function
([],
conv_op
[
0
])
assert
not
any
([
isinstance
(
node
.
op
,
abstract_op
)
for
node
in
conv_func
.
maker
.
fgraph
.
toposort
()])
utt
.
assert_allclose
(
conv_func
(),
ref_func
())
def
test_optimizers
(
self
):
self
.
optimizer_2d
([(
2
,
3
,
5
,
5
),
(
4
,
3
,
3
,
3
),
(
2
,
4
,
3
,
3
)],
0
,
local_abstractconv_gemm_alternative
)
self
.
optimizer_2d
([(
2
,
3
,
5
,
5
),
(
2
,
4
,
3
,
3
),
(
4
,
3
,
3
,
3
)],
1
,
local_abstractconv_gemm_gradweights_alt
)
self
.
optimizer_2d
([(
2
,
4
,
3
,
3
),
(
4
,
3
,
3
,
3
),
(
2
,
3
,
5
,
5
)],
2
,
local_abstractconv_gradinputs_gemm_alt
)
self
.
optimizer_2d
([(
2
,
3
,
5
,
5
),
(
4
,
3
,
3
,
3
),
(
2
,
4
,
3
,
3
)],
0
,
local_abstractconv_cudnn_alternative
)
self
.
optimizer_2d
([(
2
,
3
,
5
,
5
),
(
2
,
4
,
3
,
3
),
(
4
,
3
,
3
,
3
)],
1
,
local_abstractconv_cudnn_alternative
)
self
.
optimizer_2d
([(
2
,
4
,
3
,
3
),
(
4
,
3
,
3
,
3
),
(
2
,
3
,
5
,
5
)],
2
,
local_abstractconv_cudnn_alternative
)
self
.
optimizer_3d
([(
2
,
3
,
5
,
5
,
5
),
(
4
,
3
,
3
,
3
,
3
),
(
2
,
4
,
3
,
3
,
3
)],
0
,
local_abstractconv3d_alt
)
self
.
optimizer_3d
([(
2
,
3
,
5
,
5
,
5
),
(
4
,
3
,
3
,
3
,
3
),
(
2
,
4
,
3
,
3
,
3
)],
0
,
local_abstractconv3d2d
)
self
.
optimizer_3d
([(
2
,
3
,
5
,
5
,
5
),
(
2
,
4
,
3
,
3
,
3
),
(
4
,
3
,
3
,
3
,
3
)],
1
,
local_abstractconv3d_gemm_gradweights_alt
)
self
.
optimizer_3d
([(
2
,
4
,
3
,
3
,
3
),
(
4
,
3
,
3
,
3
,
3
),
(
2
,
3
,
5
,
5
,
5
)],
2
,
local_abstractconv3d_gradinputs_gemm_alt
)
'''
will fail until bug is fixed
self.optimizer_3d([(2, 3, 5, 5, 5), (4, 3, 3, 3, 3), (2, 4, 3, 3, 3)], 0,
local_abstractconv3d_cudnn_alternative)
'''
self
.
optimizer_3d
([(
2
,
3
,
5
,
5
,
5
),
(
2
,
4
,
3
,
3
,
3
),
(
4
,
3
,
3
,
3
,
3
)],
1
,
local_abstractconv3d_cudnn_alternative
)
self
.
optimizer_3d
([(
2
,
4
,
3
,
3
,
3
),
(
4
,
3
,
3
,
3
,
3
),
(
2
,
3
,
5
,
5
,
5
)],
2
,
local_abstractconv3d_cudnn_alternative
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论