Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b9d546a9
提交
b9d546a9
authored
11月 12, 2014
作者:
Dustin Webb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added optimization that converts SoftmaxGrad to DnnSoftmaxGrad and associated…
Added optimization that converts SoftmaxGrad to DnnSoftmaxGrad and associated test to make sure it is applied correctly.
上级
1625e634
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
76 行增加
和
7 行删除
+76
-7
dnn.py
theano/sandbox/cuda/dnn.py
+27
-2
test_nnet.py
theano/sandbox/cuda/tests/test_nnet.py
+49
-5
没有找到文件。
theano/sandbox/cuda/dnn.py
浏览文件 @
b9d546a9
...
@@ -5,11 +5,12 @@ from theano import Apply, gof, tensor
...
@@ -5,11 +5,12 @@ from theano import Apply, gof, tensor
from
theano.gof
import
Optimizer
from
theano.gof
import
Optimizer
from
theano.gof.type
import
CDataType
from
theano.gof.type
import
CDataType
from
theano.compat
import
PY3
from
theano.compat
import
PY3
from
theano.tensor.nnet
import
SoftmaxGrad
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda
import
(
GpuOp
,
cuda_available
,
active_device_number
,
from
theano.sandbox.cuda
import
(
GpuOp
,
cuda_available
,
active_device_number
,
device_properties
)
device_properties
)
from
theano.sandbox.cuda.basic_ops
import
(
as_cuda_ndarray_variable
,
from
theano.sandbox.cuda.basic_ops
import
(
as_cuda_ndarray_variable
,
gpu_contiguous
)
gpu_contiguous
,
HostFromGpu
)
from
theano.sandbox.cuda.blas
import
(
GpuConv
,
GpuDownsampleFactorMax
,
from
theano.sandbox.cuda.blas
import
(
GpuConv
,
GpuDownsampleFactorMax
,
GpuDownsampleFactorMaxGrad
)
GpuDownsampleFactorMaxGrad
)
from
theano.sandbox.cuda.nnet
import
GpuSoftmax
from
theano.sandbox.cuda.nnet
import
GpuSoftmax
...
@@ -887,7 +888,7 @@ cudnnTensor4dDescriptor_t %(name)s_%(id)d;
...
@@ -887,7 +888,7 @@ cudnnTensor4dDescriptor_t %(name)s_%(id)d;
%(name)
s_
%(id)
d = NULL;
%(name)
s_
%(id)
d = NULL;
if ((err
%(id)
d = cudnnCreateTensor4dDescriptor(&
%(name)
s_
%(id)
d)) != CUDNN_STATUS_SUCCESS) {
if ((err
%(id)
d = cudnnCreateTensor4dDescriptor(&
%(name)
s_
%(id)
d)) != CUDNN_STATUS_SUCCESS) {
PyErr_Format(PyExc_MemoryError, "could not allocate tensor4d descriptor "
PyErr_Format(PyExc_MemoryError, "could not allocate tensor4d descriptor "
"
%%
s", cudnnGetErrorString(err
%(id)
d));
"
:
%%
s", cudnnGetErrorString(err
%(id)
d));
%(fail)
s
%(fail)
s
}
}
"""
%
dict
(
name
=
name
,
id
=
id
,
fail
=
fail
)
"""
%
dict
(
name
=
name
,
id
=
id
,
fail
=
fail
)
...
@@ -1152,3 +1153,27 @@ if cuda_available:
...
@@ -1152,3 +1153,27 @@ if cuda_available:
" to use it. We got this error:
\n
"
+
" to use it. We got this error:
\n
"
+
dnn_available
.
msg
)
dnn_available
.
msg
)
gpu_seqopt
.
register
(
"NoCuDNNRaise"
,
NoCuDNNRaise
(),
0
,
'cudnn'
)
gpu_seqopt
.
register
(
"NoCuDNNRaise"
,
NoCuDNNRaise
(),
0
,
'cudnn'
)
@register_opt
(
'cudnn'
)
@local_optimizer
([
SoftmaxGrad
])
def
local_softmax_dnn_grad
(
node
):
if
(
isinstance
(
node
.
op
,
SoftmaxGrad
)
and
(
isinstance
(
node
.
inputs
[
0
]
.
owner
.
op
,
HostFromGpu
)
or
isinstance
(
node
.
inputs
[
1
]
.
owner
.
op
,
HostFromGpu
))
):
ins
=
[]
for
n
in
node
.
inputs
:
if
isinstance
(
n
.
owner
.
op
,
HostFromGpu
):
n
=
n
.
owner
.
inputs
[
0
]
ins
.
append
(
n
.
dimshuffle
(
0
,
1
,
'x'
,
'x'
))
out
=
GpuDnnSoftmaxGrad
(
'bc01'
,
'accurate'
,
'channel'
)(
ins
[
0
],
gpu_contiguous
(
ins
[
1
])
)
return
[
out
.
dimshuffle
(
0
,
1
)]
theano/sandbox/cuda/tests/test_nnet.py
浏览文件 @
b9d546a9
...
@@ -276,7 +276,7 @@ class test_SoftMax(unittest.TestCase):
...
@@ -276,7 +276,7 @@ class test_SoftMax(unittest.TestCase):
x
=
T
.
fmatrix
(
'x'
)
x
=
T
.
fmatrix
(
'x'
)
z
=
T
.
nnet
.
softmax
z
=
T
.
nnet
.
softmax
def
check_types
(
graph
,
graph_gpu
):
def
check_types
_without_cudnn
(
graph
,
graph_gpu
):
self
.
_check_types
(
self
.
_check_types
(
graph
,
graph
,
graph_gpu
,
graph_gpu
,
...
@@ -285,14 +285,15 @@ class test_SoftMax(unittest.TestCase):
...
@@ -285,14 +285,15 @@ class test_SoftMax(unittest.TestCase):
cuda
.
nnet
.
GpuSoftmax
cuda
.
nnet
.
GpuSoftmax
)
)
mode_wo_cudnn
=
mode_with_gpu
.
excluding
(
"cudnn"
)
f
,
f_gpu
=
self
.
_test_softmax
(
f
,
f_gpu
=
self
.
_test_softmax
(
x
,
x
,
x
,
x
,
z
,
z
,
z
,
z
,
self
.
_cmp
,
self
.
_cmp
,
mode_w
ith_gpu
,
mode_w
o_cudnn
,
check_types
check_types
_without_cudnn
)
)
# cuDNN R1 cannot handle these test cases but the Theano softmax can so
# cuDNN R1 cannot handle these test cases but the Theano softmax can so
...
@@ -300,6 +301,25 @@ class test_SoftMax(unittest.TestCase):
...
@@ -300,6 +301,25 @@ class test_SoftMax(unittest.TestCase):
self
.
_cmp
(
2
<<
15
,
5
,
f
,
f_gpu
)
self
.
_cmp
(
2
<<
15
,
5
,
f
,
f_gpu
)
self
.
_cmp
(
0
,
10
,
f
,
f_gpu
)
self
.
_cmp
(
0
,
10
,
f
,
f_gpu
)
def
check_types_with_cudnn
(
graph
,
graph_gpu
):
self
.
_check_types
(
graph
,
graph_gpu
,
-
3
,
type
(
z
),
theano
.
sandbox
.
cuda
.
dnn
.
GpuDnnSoftmax
)
f
,
f_gpu
=
self
.
_test_softmax
(
x
,
x
,
z
,
z
,
self
.
_cmp
,
mode_with_gpu
,
check_types_with_cudnn
)
def
test_cudnn_softmax
(
self
):
def
test_cudnn_softmax
(
self
):
if
not
cuda
.
dnn
.
dnn_available
():
if
not
cuda
.
dnn
.
dnn_available
():
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
...
@@ -357,5 +377,29 @@ class test_SoftMax(unittest.TestCase):
...
@@ -357,5 +377,29 @@ class test_SoftMax(unittest.TestCase):
check_types
check_types
)
)
mode
=
mode_with_gpu
.
including
(
"cudnn"
)
mode_w_cudnn
=
mode_with_gpu
.
including
(
"cudnn"
)
self
.
_test_softmax
(
x
,
x
,
f_z
,
f_z
,
self
.
_cmp
,
mode
,
check_types_opt
)
self
.
_test_softmax
(
x
,
x
,
f_z
,
f_z
,
self
.
_cmp
,
mode_w_cudnn
,
check_types_opt
)
# Verify that the SoftmaxGrad -> GpuDnnSoftmaxGrad optimization
y
=
T
.
vector
(
'y'
)
f
=
theano
.
function
(
[
y
],
T
.
grad
(
T
.
nnet
.
softmax
(
y
)
.
mean
(),
y
),
mode
=
mode_with_gpu
)
sorted_f
=
f
.
maker
.
fgraph
.
toposort
()
assert
(
len
([
i
for
i
in
sorted_f
if
isinstance
(
i
.
op
,
theano
.
sandbox
.
cuda
.
dnn
.
GpuDnnSoftmaxGrad
)])
==
1
)
assert
(
len
([
i
for
i
in
sorted_f
if
isinstance
(
i
.
op
,
theano
.
tensor
.
nnet
.
SoftmaxGrad
)])
==
0
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论