Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6f8d49aa
提交
6f8d49aa
authored
11月 24, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[CRASH,ENH]: don't have opt raise error due to mixing conv2d/3d op and make the opt work for conv3d
上级
755f2218
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
94 行增加
和
17 行删除
+94
-17
dnn.py
theano/sandbox/cuda/dnn.py
+12
-13
opt_util.py
theano/sandbox/cuda/opt_util.py
+8
-4
test_dnn.py
theano/sandbox/cuda/tests/test_dnn.py
+74
-0
没有找到文件。
theano/sandbox/cuda/dnn.py
浏览文件 @
6f8d49aa
...
@@ -33,7 +33,6 @@ from theano.tensor.nnet.abstract_conv2d import (AbstractConv2d,
...
@@ -33,7 +33,6 @@ from theano.tensor.nnet.abstract_conv2d import (AbstractConv2d,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
)
AbstractConv2d_gradInputs
)
def
dnn_available
():
def
dnn_available
():
if
dnn_available
.
avail
is
None
:
if
dnn_available
.
avail
is
None
:
if
not
theano
.
sandbox
.
cuda
.
cuda_available
:
if
not
theano
.
sandbox
.
cuda
.
cuda_available
:
...
@@ -2232,43 +2231,43 @@ if True:
...
@@ -2232,43 +2231,43 @@ if True:
70.0
,
'fast_run'
,
'inplace'
,
'gpu'
,
'cudnn'
)
70.0
,
'fast_run'
,
'inplace'
,
'gpu'
,
'cudnn'
)
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@alpha_merge
(
GpuDnnConv
,
alpha_in
=
4
,
beta_in
=
5
,
nd
=
4
)
@alpha_merge
(
GpuDnnConv
,
alpha_in
=
4
,
beta_in
=
5
)
def
local_dnn_conv_alpha_merge
(
node
,
*
inputs
):
def
local_dnn_conv_alpha_merge
(
node
,
*
inputs
):
if
not
dnn_available
()
or
version
()
==
-
1
:
if
not
dnn_available
()
or
version
()
==
-
1
:
return
None
return
None
return
[
GpuDnnConv
(
algo
=
node
.
op
.
algo
)
(
*
inputs
)]
return
[
node
.
op
(
*
inputs
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@alpha_merge
(
GpuDnnConvGradW
,
alpha_in
=
4
,
beta_in
=
5
,
nd
=
4
)
@alpha_merge
(
GpuDnnConvGradW
,
alpha_in
=
4
,
beta_in
=
5
)
def
local_dnn_convw_alpha_merge
(
node
,
*
inputs
):
def
local_dnn_convw_alpha_merge
(
node
,
*
inputs
):
if
not
dnn_available
()
or
version
()
==
-
1
:
if
not
dnn_available
()
or
version
()
==
-
1
:
return
None
return
None
return
[
GpuDnnConvGradW
()
(
*
inputs
)]
return
[
node
.
op
(
*
inputs
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@alpha_merge
(
GpuDnnConvGradI
,
alpha_in
=
4
,
beta_in
=
5
,
nd
=
4
)
@alpha_merge
(
GpuDnnConvGradI
,
alpha_in
=
4
,
beta_in
=
5
)
def
local_dnn_convi_alpha_merge
(
node
,
*
inputs
):
def
local_dnn_convi_alpha_merge
(
node
,
*
inputs
):
if
not
dnn_available
()
or
version
()
==
-
1
:
if
not
dnn_available
()
or
version
()
==
-
1
:
return
None
return
None
return
[
GpuDnnConvGradI
()
(
*
inputs
)]
return
[
node
.
op
(
*
inputs
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@output_merge
(
GpuDnnConv
,
alpha_in
=
4
,
beta_in
=
5
,
out_in
=
2
,
nd
=
4
)
@output_merge
(
GpuDnnConv
,
alpha_in
=
4
,
beta_in
=
5
,
out_in
=
2
)
def
local_dnn_conv_output_merge
(
node
,
*
inputs
):
def
local_dnn_conv_output_merge
(
node
,
*
inputs
):
inputs
=
inputs
[
0
:
2
]
+
(
gpu_contiguous
(
inputs
[
2
]),)
+
inputs
[
3
:]
inputs
=
inputs
[
0
:
2
]
+
(
gpu_contiguous
(
inputs
[
2
]),)
+
inputs
[
3
:]
return
[
GpuDnnConv
(
algo
=
node
.
op
.
algo
)
(
*
inputs
)]
return
[
node
.
op
(
*
inputs
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@output_merge
(
GpuDnnConvGradW
,
alpha_in
=
4
,
beta_in
=
5
,
out_in
=
2
,
nd
=
4
)
@output_merge
(
GpuDnnConvGradW
,
alpha_in
=
4
,
beta_in
=
5
,
out_in
=
2
)
def
local_dnn_convw_output_merge
(
node
,
*
inputs
):
def
local_dnn_convw_output_merge
(
node
,
*
inputs
):
inputs
=
inputs
[
0
:
2
]
+
(
gpu_contiguous
(
inputs
[
2
]),)
+
inputs
[
3
:]
inputs
=
inputs
[
0
:
2
]
+
(
gpu_contiguous
(
inputs
[
2
]),)
+
inputs
[
3
:]
return
[
GpuDnnConvGradW
()
(
*
inputs
)]
return
[
node
.
op
(
*
inputs
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@output_merge
(
GpuDnnConvGradI
,
alpha_in
=
4
,
beta_in
=
5
,
out_in
=
2
,
nd
=
4
)
@output_merge
(
GpuDnnConvGradI
,
alpha_in
=
4
,
beta_in
=
5
,
out_in
=
2
)
def
local_dnn_convi_output_merge
(
node
,
*
inputs
):
def
local_dnn_convi_output_merge
(
node
,
*
inputs
):
inputs
=
inputs
[
0
:
2
]
+
(
gpu_contiguous
(
inputs
[
2
]),)
+
inputs
[
3
:]
inputs
=
inputs
[
0
:
2
]
+
(
gpu_contiguous
(
inputs
[
2
]),)
+
inputs
[
3
:]
return
[
GpuDnnConvGradI
()
(
*
inputs
)]
return
[
node
.
op
(
*
inputs
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@local_optimizer
([
GpuDownsampleFactorMax
])
@local_optimizer
([
GpuDownsampleFactorMax
])
...
...
theano/sandbox/cuda/opt_util.py
浏览文件 @
6f8d49aa
...
@@ -57,7 +57,7 @@ def is_equal(var, val):
...
@@ -57,7 +57,7 @@ def is_equal(var, val):
return
False
return
False
def
alpha_merge
(
cls
,
alpha_in
,
beta_in
,
nd
):
def
alpha_merge
(
cls
,
alpha_in
,
beta_in
):
def
wrapper
(
maker
):
def
wrapper
(
maker
):
@local_optimizer
([
GpuElemwise
])
@local_optimizer
([
GpuElemwise
])
@wraps
(
maker
)
@wraps
(
maker
)
...
@@ -68,9 +68,13 @@ def alpha_merge(cls, alpha_in, beta_in, nd):
...
@@ -68,9 +68,13 @@ def alpha_merge(cls, alpha_in, beta_in, nd):
targ
=
find_node
(
node
.
inputs
[
0
],
cls
)
targ
=
find_node
(
node
.
inputs
[
0
],
cls
)
if
targ
is
None
:
if
targ
is
None
:
targ
=
find_node
(
node
.
inputs
[
1
],
cls
)
targ
=
find_node
(
node
.
inputs
[
1
],
cls
)
lr
=
grab_cpu_scalar
(
node
.
inputs
[
0
],
nd
=
nd
)
if
targ
is
None
:
return
lr
=
grab_cpu_scalar
(
node
.
inputs
[
0
],
nd
=
targ
.
outputs
[
0
]
.
ndim
)
else
:
else
:
lr
=
grab_cpu_scalar
(
node
.
inputs
[
1
],
nd
=
nd
)
lr
=
grab_cpu_scalar
(
node
.
inputs
[
1
],
nd
=
targ
.
outputs
[
0
]
.
ndim
)
if
lr
is
None
or
targ
is
None
:
if
lr
is
None
or
targ
is
None
:
return
None
return
None
inputs
=
list
(
targ
.
inputs
)
inputs
=
list
(
targ
.
inputs
)
...
@@ -93,7 +97,7 @@ def alpha_merge(cls, alpha_in, beta_in, nd):
...
@@ -93,7 +97,7 @@ def alpha_merge(cls, alpha_in, beta_in, nd):
return
wrapper
return
wrapper
def
output_merge
(
cls
,
alpha_in
,
beta_in
,
out_in
,
nd
):
def
output_merge
(
cls
,
alpha_in
,
beta_in
,
out_in
):
def
wrapper
(
maker
):
def
wrapper
(
maker
):
@local_optimizer
([
GpuElemwise
])
@local_optimizer
([
GpuElemwise
])
@wraps
(
maker
)
@wraps
(
maker
)
...
...
theano/sandbox/cuda/tests/test_dnn.py
浏览文件 @
6f8d49aa
...
@@ -1082,6 +1082,80 @@ def test_dnn_conv_alpha_output_merge():
...
@@ -1082,6 +1082,80 @@ def test_dnn_conv_alpha_output_merge():
utt
.
assert_allclose
(
v1
,
v2
)
utt
.
assert_allclose
(
v1
,
v2
)
def
test_dnn_conv3d_alpha_output_merge
():
if
not
cuda
.
dnn
.
dnn_available
():
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
t
=
T
.
TensorType
(
broadcastable
=
(
False
,
False
,
False
,
False
,
False
),
dtype
=
'float32'
)
img
=
t
()
kern
=
t
()
out
=
t
()
b
=
1
c
=
4
f
=
3
it
=
10
ih
=
5
iw
=
8
kt
=
3
kh
=
2
kw
=
6
img_val
=
numpy
.
random
.
random
((
b
,
c
,
it
,
ih
,
iw
))
.
astype
(
'float32'
)
kern_val
=
numpy
.
random
.
random
((
f
,
c
,
kt
,
kh
,
kw
))
.
astype
(
'float32'
)
out_val
=
numpy
.
random
.
random
((
b
,
f
,
it
-
kt
+
1
,
ih
-
kh
+
1
,
iw
-
kw
+
1
))
.
astype
(
'float32'
)
conv
=
dnn
.
dnn_conv3d
(
img
,
kern
)
gw
=
theano
.
grad
(
conv
.
sum
(),
kern
)
gi
=
theano
.
grad
(
conv
.
sum
(),
img
)
lr
=
numpy
.
asarray
(
0.05
,
dtype
=
'float32'
)
if
cuda
.
dnn
.
version
()
==
-
1
:
# Can't merge alpha with cudnn v1
fr
=
conv
+
out
wr
=
kern
+
gw
ir
=
img
+
gi
else
:
fr
=
lr
*
(
conv
+
out
)
wr
=
kern
+
lr
*
gw
ir
=
img
+
lr
*
gi
f1
=
theano
.
function
([
img
,
kern
,
out
],
[
fr
,
wr
,
ir
],
mode
=
mode_with_gpu
)
assert
isinstance
(
f1
.
maker
.
fgraph
.
outputs
[
0
]
.
owner
.
inputs
[
0
]
.
owner
.
op
,
dnn
.
GpuDnnConv
)
assert
isinstance
(
f1
.
maker
.
fgraph
.
outputs
[
1
]
.
owner
.
inputs
[
0
]
.
owner
.
op
,
dnn
.
GpuDnnConvGradW
)
assert
isinstance
(
f1
.
maker
.
fgraph
.
outputs
[
2
]
.
owner
.
inputs
[
0
]
.
owner
.
op
,
dnn
.
GpuDnnConvGradI
)
mode
=
mode_with_gpu
mode
=
mode
.
excluding
(
'local_dnn_conv_alpha_merge'
)
mode
=
mode
.
excluding
(
'local_dnn_convw_alpha_merge'
)
mode
=
mode
.
excluding
(
'local_dnn_convi_alpha_merge'
)
mode
=
mode
.
excluding
(
'local_dnn_conv_output_merge'
)
mode
=
mode
.
excluding
(
'local_dnn_convw_output_merge'
)
mode
=
mode
.
excluding
(
'local_dnn_convi_output_merge'
)
f2
=
theano
.
function
([
img
,
kern
,
out
],
[
fr
,
wr
,
ir
],
mode
=
mode
)
assert
not
isinstance
(
f2
.
maker
.
fgraph
.
outputs
[
0
]
.
owner
.
inputs
[
0
]
.
owner
.
op
,
dnn
.
GpuDnnConv3d
)
assert
not
isinstance
(
f2
.
maker
.
fgraph
.
outputs
[
1
]
.
owner
.
inputs
[
0
]
.
owner
.
op
,
dnn
.
GpuDnnConv3dGradW
)
assert
not
isinstance
(
f2
.
maker
.
fgraph
.
outputs
[
2
]
.
owner
.
inputs
[
0
]
.
owner
.
op
,
dnn
.
GpuDnnConv3dGradI
)
out_f1
=
f1
(
img_val
,
kern_val
,
out_val
)
out_f2
=
f2
(
img_val
,
kern_val
,
out_val
)
assert
len
(
out_f1
)
==
len
(
out_f2
)
for
v1
,
v2
in
zip
(
out_f1
,
out_f2
):
utt
.
assert_allclose
(
v1
,
v2
)
def
test_dnn_conv_merge_mouts
():
def
test_dnn_conv_merge_mouts
():
# make sure it doesn't attempt to output/alpha merge a convolution
# make sure it doesn't attempt to output/alpha merge a convolution
# that has multiple clients.
# that has multiple clients.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论