Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b0bacd7b
提交
b0bacd7b
authored
9月 26, 2014
作者:
Nicolas Ballas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add GpuCorr3d optimization tests
上级
affc0f7f
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
86 行增加
和
8 行删除
+86
-8
opt.py
theano/sandbox/cuda/opt.py
+4
-7
test_gemmcorr3d.py
theano/sandbox/cuda/tests/test_gemmcorr3d.py
+82
-1
没有找到文件。
theano/sandbox/cuda/opt.py
浏览文件 @
b0bacd7b
...
@@ -1371,21 +1371,19 @@ def local_convgrad3d_gemm(node):
...
@@ -1371,21 +1371,19 @@ def local_convgrad3d_gemm(node):
except
tensor
.
NotScalarConstantError
:
except
tensor
.
NotScalarConstantError
:
return
False
return
False
if
isinstance
(
node
.
op
,
ConvGrad3D
):
if
isinstance
(
node
.
op
,
ConvGrad3D
):
# Shuffle inputs signal from (b, 0, 1, t, c) to (b, c, 0, 1, t)
# Shuffle inputs signal from (b, 0, 1, t, c) to (b, c, 0, 1, t)
x
=
node
.
inputs
[
0
]
x
=
node
.
inputs
[
0
]
x
=
gpu_contiguous
(
x
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
x
=
gpu_contiguous
(
x
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
# Shuffle dCdH from (b, 0, 1, t, oc) to (oc, b, 0, 1, t)
# Shuffle dCdH from (b, 0, 1, t, oc) to (oc, b, 0, 1, t)
f
=
node
.
input
[
3
]
f
=
node
.
input
s
[
3
]
f
=
gpu_contiguous
(
f
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
f
=
gpu_contiguous
(
f
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
f
=
node
.
inputs
[
3
]
rval
=
GpuCorr3dMM_gradWeights
(
subsample
=
(
sx
,
sy
,
sz
))(
x
,
f
,
f
=
f
.
dimshuffle
(
4
,
0
,
1
,
2
,
3
)
rval
=
Gpucorr3dMM_gradWeights
(
subsample
=
(
sx
,
sy
,
sz
))(
x
,
f
,
shape
=
node
.
inputs
[
2
])
shape
=
node
.
inputs
[
2
])
# Shuffle from (ic, oc, 0, 1, t) to (oc, 0, 1, t, ic)
# Shuffle from (ic, oc, 0, 1, t) to (oc, 0, 1, t, ic)
return
[
rval
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)]
return
[
rval
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)]
gpu_optimizer
.
register
(
"convgrad3d_gemm"
,
local_convgrad3d_gemm
)
gpu_optimizer
.
register
(
"convgrad3d_gemm"
,
local_convgrad3d_gemm
)
@local_optimizer
([
ConvTransp3D
])
@local_optimizer
([
ConvTransp3D
])
...
@@ -1403,8 +1401,7 @@ def local_convtransp3d_gemm(node):
...
@@ -1403,8 +1401,7 @@ def local_convtransp3d_gemm(node):
# Shuffle dCdH from (b, 0, 1, t, oc) to (b, oc, 0, 1, t)
# Shuffle dCdH from (b, 0, 1, t, oc) to (b, oc, 0, 1, t)
f
=
node
.
inputs
[
3
]
f
=
node
.
inputs
[
3
]
f
=
gpu_contiguous
(
f
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
f
=
gpu_contiguous
(
f
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
# filter flip
rval
=
GpuCorr3dMM_gradInputs
(
subsample
=
(
sx
,
sy
,
sz
))(
kern
=
x
,
topgrad
=
f
)
rval
=
GpuCorr3DMM
(
border_mode
=
'full'
,
subsample
=
(
sx
,
sy
,
sz
))(
f
,
x
)
# Shuffle from (ic, b, 0, 1, t) to (b, 0, 1, t, ic)
# Shuffle from (ic, b, 0, 1, t) to (b, 0, 1, t, ic)
return
[
rval
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
+
node
.
inputs
[
1
]]
return
[
rval
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
+
node
.
inputs
[
1
]]
...
...
theano/sandbox/cuda/tests/test_gemmcorr3d.py
浏览文件 @
b0bacd7b
...
@@ -10,7 +10,7 @@ import theano.sandbox.cuda as cuda_ndarray
...
@@ -10,7 +10,7 @@ import theano.sandbox.cuda as cuda_ndarray
if
not
cuda_ndarray
.
cuda_available
:
if
not
cuda_ndarray
.
cuda_available
:
raise
SkipTest
(
'Optional package cuda not available'
)
raise
SkipTest
(
'Optional package cuda not available'
)
from
theano.sandbox.cuda
import
float32_shared_constructor
as
shared
from
theano.sandbox.cuda
import
float32_shared_constructor
as
shared
from
theano.sandbox.cuda.blas
import
GpuCorr3dMM
,
GpuCorr3dMM_gradWeights
,
GpuCorr3dMM_gradInputs
,
GpuCorr3dMM_gradInputs
from
theano.sandbox.cuda.blas
import
GpuCorr3dMM
,
GpuCorr3dMM_gradWeights
,
GpuCorr3dMM_gradInputs
from
theano.sandbox.cuda.basic_ops
import
gpu_contiguous
from
theano.sandbox.cuda.basic_ops
import
gpu_contiguous
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
...
@@ -157,3 +157,84 @@ class TestCorr3DMM(unittest.TestCase):
...
@@ -157,3 +157,84 @@ class TestCorr3DMM(unittest.TestCase):
filters_shape
=
(
10
,
6
,
12
,
4
,
1
),
filters_shape
=
(
10
,
6
,
12
,
4
,
1
),
subsample
=
(
3
,
1
,
2
))
subsample
=
(
3
,
1
,
2
))
def
test_opt_conv3d_gemm
(
self
):
inputs_shape
=
(
16
,
20
,
32
,
16
,
1
)
filters_shape
=
(
10
,
6
,
12
,
4
,
1
)
inputs_val
=
numpy
.
random
.
random
(
inputs_shape
)
.
astype
(
'float32'
)
filters_val
=
numpy
.
random
.
random
(
filters_shape
)
.
astype
(
'float32'
)
inputs
=
shared
(
inputs_val
)
filters
=
shared
(
filters_val
)
bias
=
shared
(
numpy
.
zeros
(
filters_shape
[
0
])
.
astype
(
'float32'
))
conv
=
theano
.
tensor
.
nnet
.
conv3D
(
V
=
inputs
,
W
=
filters
,
b
=
bias
,
d
=
(
1
,
1
,
1
))
mode
=
mode_with_gpu
.
including
(
'conv3d_gemm'
)
f_ref
=
theano
.
function
([],
conv
)
f_gemm
=
theano
.
function
([],
conv
,
mode
=
mode
)
# make sure we inserted the gemm trickery
topo
=
f_gemm
.
maker
.
fgraph
.
toposort
()
assert
sum
(
isinstance
(
n
.
op
,
GpuCorr3dMM
)
for
n
in
topo
)
>
0
res_ref
=
f_ref
()
res_gemm
=
f_gemm
()
utt
.
assert_allclose
(
res_ref
,
res_gemm
)
def
test_opt_convgrad3d_gemm
(
self
):
inputs_shape
=
(
16
,
20
,
32
,
16
,
1
)
filters_shape
=
(
10
,
6
,
12
,
4
,
1
)
dCdH_shape
=
(
16
,
15
,
21
,
13
,
10
)
inputs_val
=
numpy
.
random
.
random
(
inputs_shape
)
.
astype
(
'float32'
)
dCdH_val
=
numpy
.
random
.
random
(
dCdH_shape
)
.
astype
(
'float32'
)
inputs
=
shared
(
inputs_val
)
dCdH
=
shared
(
dCdH_val
)
conv
=
theano
.
tensor
.
nnet
.
convGrad3D
(
V
=
inputs
,
dCdH
=
dCdH
,
WShape
=
filters_shape
,
d
=
(
1
,
1
,
1
))
mode
=
mode_with_gpu
.
including
(
'convgrad3d_gemm'
)
f_ref
=
theano
.
function
([],
conv
)
f_gemm
=
theano
.
function
([],
conv
,
mode
=
mode
)
# make sure we inserted the gemm trickery
topo
=
f_gemm
.
maker
.
fgraph
.
toposort
()
assert
sum
(
isinstance
(
n
.
op
,
GpuCorr3dMM_gradWeights
)
for
n
in
topo
)
>
0
res_ref
=
f_ref
()
res_gemm
=
f_gemm
()
utt
.
assert_allclose
(
res_ref
,
res_gemm
,
rtol
=
1e-04
,
atol
=
1e-04
)
def
test_opt_convtransp3d_gemm
(
self
):
inputs_shape
=
(
16
,
15
,
21
,
12
,
10
)
filters_shape
=
(
10
,
6
,
12
,
4
,
1
)
inputs_val
=
numpy
.
random
.
random
(
inputs_shape
)
.
astype
(
'float32'
)
filters_val
=
numpy
.
random
.
random
(
filters_shape
)
.
astype
(
'float32'
)
bias
=
shared
(
numpy
.
zeros
(
filters_shape
[
4
])
.
astype
(
'float32'
))
inputs
=
shared
(
inputs_val
)
filters
=
shared
(
filters_val
)
conv
=
theano
.
tensor
.
nnet
.
convTransp3D
(
W
=
filters
,
b
=
bias
,
d
=
(
1
,
1
,
1
),
H
=
inputs
)
mode
=
mode_with_gpu
.
including
(
'convtransp3d_gemm'
)
f_ref
=
theano
.
function
([],
conv
)
f_gemm
=
theano
.
function
([],
conv
,
mode
=
mode
)
# make sure we inserted the gemm trickery
topo
=
f_gemm
.
maker
.
fgraph
.
toposort
()
assert
sum
(
isinstance
(
n
.
op
,
GpuCorr3dMM_gradInputs
)
for
n
in
topo
)
>
0
res_ref
=
f_ref
()
res_gemm
=
f_gemm
()
utt
.
assert_allclose
(
res_ref
,
res_gemm
,
rtol
=
1e-04
,
atol
=
1e-04
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论