Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8b9f7336
提交
8b9f7336
authored
1月 31, 2017
作者:
Frédéric Bastien
提交者:
GitHub
1月 31, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5190 from gvtulder/f-batchnorm-abstract
Abstract Ops for batch normalization
上级
18f27c44
60238616
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
101 行增加
和
4 行删除
+101
-4
bn.txt
doc/library/tensor/nnet/bn.txt
+4
-1
dnn.py
theano/gpuarray/dnn.py
+0
-0
dnn_batchnorm.c
theano/gpuarray/dnn_batchnorm.c
+54
-2
dnn_batchnorm_inf.c
theano/gpuarray/dnn_batchnorm_inf.c
+6
-0
test_dnn.py
theano/gpuarray/tests/test_dnn.py
+0
-0
__init__.py
theano/sandbox/cuda/__init__.py
+12
-1
dnn.py
theano/sandbox/cuda/dnn.py
+0
-0
opt.py
theano/sandbox/cuda/opt.py
+25
-0
test_dnn.py
theano/sandbox/cuda/tests/test_dnn.py
+0
-0
bn.py
theano/tensor/nnet/bn.py
+0
-0
test_bn.py
theano/tensor/nnet/tests/test_bn.py
+0
-0
没有找到文件。
doc/library/tensor/nnet/bn.txt
浏览文件 @
8b9f7336
...
@@ -10,6 +10,9 @@
...
@@ -10,6 +10,9 @@
.. moduleauthor:: LISA
.. moduleauthor:: LISA
.. seealso:: cuDNN batch normalization: :class:`theano.gpuarray.dnn.dnn_batch_normalization_train`, :class:`theano.gpuarray.dnn.dnn_batch_normalization_test>`. They must be added manually as they do not have the same user interface.
.. autofunction:: theano.tensor.nnet.bn.batch_normalization_train
.. autofunction:: theano.tensor.nnet.bn.batch_normalization_test
.. seealso:: cuDNN batch normalization: :class:`theano.gpuarray.dnn.dnn_batch_normalization_train`, :class:`theano.gpuarray.dnn.dnn_batch_normalization_test>`.
.. autofunction:: theano.tensor.nnet.bn.batch_normalization
.. autofunction:: theano.tensor.nnet.bn.batch_normalization
theano/gpuarray/dnn.py
浏览文件 @
8b9f7336
差异被折叠。
点击展开。
theano/gpuarray/dnn_batchnorm.c
浏览文件 @
8b9f7336
...
@@ -2,8 +2,19 @@
...
@@ -2,8 +2,19 @@
int
dnn_batchnorm_op
(
PyGpuArrayObject
*
inp
,
PyGpuArrayObject
*
scale
,
int
dnn_batchnorm_op
(
PyGpuArrayObject
*
inp
,
PyGpuArrayObject
*
scale
,
PyGpuArrayObject
*
bias
,
npy_float64
epsilon
,
PyGpuArrayObject
*
bias
,
npy_float64
epsilon
,
PyGpuArrayObject
**
outp
,
PyGpuArrayObject
**
x_mean
,
npy_float64
running_average_factor
,
PyGpuArrayObject
**
x_invstd
,
cudnnHandle_t
_handle
)
{
#ifdef RUNNING_AVERAGES
PyGpuArrayObject
*
in_running_mean
,
PyGpuArrayObject
*
in_running_var
,
#endif
PyGpuArrayObject
**
outp
,
PyGpuArrayObject
**
x_mean
,
PyGpuArrayObject
**
x_invstd
,
#ifdef RUNNING_AVERAGES
PyGpuArrayObject
**
out_running_mean
,
PyGpuArrayObject
**
out_running_var
,
#endif
cudnnHandle_t
_handle
)
{
PyGpuContextObject
*
c
=
inp
->
context
;
PyGpuContextObject
*
c
=
inp
->
context
;
if
(
c_set_tensorNd
(
inp
,
bn_input
)
!=
0
)
if
(
c_set_tensorNd
(
inp
,
bn_input
)
!=
0
)
...
@@ -16,8 +27,14 @@ int dnn_batchnorm_op(PyGpuArrayObject *inp, PyGpuArrayObject *scale,
...
@@ -16,8 +27,14 @@ int dnn_batchnorm_op(PyGpuArrayObject *inp, PyGpuArrayObject *scale,
return
1
;
return
1
;
}
}
#ifdef INPLACE_OUTPUT
Py_XDECREF
(
*
outp
);
*
outp
=
inp
;
Py_INCREF
(
*
outp
);
#else
if
(
theano_prep_output
(
outp
,
inp
->
ga
.
nd
,
inp
->
ga
.
dimensions
,
inp
->
ga
.
typecode
,
GA_C_ORDER
,
c
)
!=
0
)
if
(
theano_prep_output
(
outp
,
inp
->
ga
.
nd
,
inp
->
ga
.
dimensions
,
inp
->
ga
.
typecode
,
GA_C_ORDER
,
c
)
!=
0
)
return
1
;
return
1
;
#endif
if
(
theano_prep_output
(
x_mean
,
scale
->
ga
.
nd
,
scale
->
ga
.
dimensions
,
scale
->
ga
.
typecode
,
GA_C_ORDER
,
c
)
!=
0
)
if
(
theano_prep_output
(
x_mean
,
scale
->
ga
.
nd
,
scale
->
ga
.
dimensions
,
scale
->
ga
.
typecode
,
GA_C_ORDER
,
c
)
!=
0
)
return
1
;
return
1
;
if
(
theano_prep_output
(
x_invstd
,
scale
->
ga
.
nd
,
scale
->
ga
.
dimensions
,
scale
->
ga
.
typecode
,
GA_C_ORDER
,
c
)
!=
0
)
if
(
theano_prep_output
(
x_invstd
,
scale
->
ga
.
nd
,
scale
->
ga
.
dimensions
,
scale
->
ga
.
typecode
,
GA_C_ORDER
,
c
)
!=
0
)
...
@@ -26,6 +43,31 @@ int dnn_batchnorm_op(PyGpuArrayObject *inp, PyGpuArrayObject *scale,
...
@@ -26,6 +43,31 @@ int dnn_batchnorm_op(PyGpuArrayObject *inp, PyGpuArrayObject *scale,
if
(
c_set_tensorNd
(
*
outp
,
bn_output
)
!=
0
)
if
(
c_set_tensorNd
(
*
outp
,
bn_output
)
!=
0
)
return
1
;
return
1
;
#ifdef RUNNING_AVERAGES
#ifdef INPLACE_RUNNING_MEAN
Py_XDECREF
(
out_running_mean
);
PyGpuArrayObject
*
running_mean
=
in_running_mean
;
Py_INCREF
(
running_mean
);
#else
PyGpuArrayObject
*
running_mean
=
*
out_running_mean
;
running_mean
=
theano_try_copy
(
running_mean
,
in_running_mean
);
if
(
running_mean
==
NULL
)
{
return
1
;
}
#endif
#ifdef INPLACE_RUNNING_VAR
Py_XDECREF
(
out_running_var
);
PyGpuArrayObject
*
running_var
=
in_running_var
;
Py_INCREF
(
running_var
);
#else
PyGpuArrayObject
*
running_var
=
*
out_running_var
;
running_var
=
theano_try_copy
(
running_var
,
in_running_var
);
if
(
running_var
==
NULL
)
{
return
1
;
}
#endif
#endif
{
{
const
float
falpha
=
1
.;
const
float
falpha
=
1
.;
const
float
fbeta
=
0
.;
const
float
fbeta
=
0
.;
...
@@ -52,9 +94,15 @@ int dnn_batchnorm_op(PyGpuArrayObject *inp, PyGpuArrayObject *scale,
...
@@ -52,9 +94,15 @@ int dnn_batchnorm_op(PyGpuArrayObject *inp, PyGpuArrayObject *scale,
bn_params
,
bn_params
,
PyGpuArray_DEV_DATA
(
scale
),
PyGpuArray_DEV_DATA
(
scale
),
PyGpuArray_DEV_DATA
(
bias
),
PyGpuArray_DEV_DATA
(
bias
),
#ifdef RUNNING_AVERAGES
running_average_factor
,
PyGpuArray_DEV_DATA
(
running_mean
),
PyGpuArray_DEV_DATA
(
running_var
),
#else
0
,
0
,
NULL
,
// running mean, deliberately unused
NULL
,
// running mean, deliberately unused
NULL
,
// running var, deliberately unused
NULL
,
// running var, deliberately unused
#endif
epsilon
,
epsilon
,
PyGpuArray_DEV_DATA
(
*
x_mean
),
PyGpuArray_DEV_DATA
(
*
x_mean
),
PyGpuArray_DEV_DATA
(
*
x_invstd
)
PyGpuArray_DEV_DATA
(
*
x_invstd
)
...
@@ -64,6 +112,10 @@ int dnn_batchnorm_op(PyGpuArrayObject *inp, PyGpuArrayObject *scale,
...
@@ -64,6 +112,10 @@ int dnn_batchnorm_op(PyGpuArrayObject *inp, PyGpuArrayObject *scale,
cudnnGetErrorString
(
err
));
cudnnGetErrorString
(
err
));
return
1
;
return
1
;
}
}
#ifdef RUNNING_AVERAGES
*
out_running_mean
=
running_mean
;
*
out_running_var
=
running_var
;
#endif
}
}
return
0
;
return
0
;
}
}
theano/gpuarray/dnn_batchnorm_inf.c
浏览文件 @
8b9f7336
...
@@ -16,8 +16,14 @@ int dnn_batchnorm_op(PyGpuArrayObject *inp, PyGpuArrayObject *scale,
...
@@ -16,8 +16,14 @@ int dnn_batchnorm_op(PyGpuArrayObject *inp, PyGpuArrayObject *scale,
return
1
;
return
1
;
}
}
#ifdef INPLACE_OUTPUT
Py_XDECREF
(
*
outp
);
*
outp
=
inp
;
Py_INCREF
(
*
outp
);
#else
if
(
theano_prep_output
(
outp
,
inp
->
ga
.
nd
,
inp
->
ga
.
dimensions
,
inp
->
ga
.
typecode
,
GA_C_ORDER
,
c
)
!=
0
)
if
(
theano_prep_output
(
outp
,
inp
->
ga
.
nd
,
inp
->
ga
.
dimensions
,
inp
->
ga
.
typecode
,
GA_C_ORDER
,
c
)
!=
0
)
return
1
;
return
1
;
#endif
if
(
c_set_tensorNd
(
*
outp
,
bn_output
)
!=
0
)
if
(
c_set_tensorNd
(
*
outp
,
bn_output
)
!=
0
)
return
1
;
return
1
;
...
...
theano/gpuarray/tests/test_dnn.py
浏览文件 @
8b9f7336
差异被折叠。
点击展开。
theano/sandbox/cuda/__init__.py
浏览文件 @
8b9f7336
...
@@ -12,7 +12,7 @@ import warnings
...
@@ -12,7 +12,7 @@ import warnings
import
theano
import
theano
from
theano.compat
import
get_unbound_function
from
theano.compat
import
get_unbound_function
from
theano.compile
import
optdb
from
theano.compile
import
optdb
from
theano.gof
import
EquilibriumDB
,
SequenceDB
from
theano.gof
import
EquilibriumDB
,
SequenceDB
,
TopoOptimizer
from
theano.gof.cmodule
import
get_lib_extension
from
theano.gof.cmodule
import
get_lib_extension
from
theano.gof.compilelock
import
get_lock
,
release_lock
from
theano.gof.compilelock
import
get_lock
,
release_lock
from
theano
import
config
from
theano
import
config
...
@@ -40,6 +40,17 @@ def register_opt(*tags, **kwargs):
...
@@ -40,6 +40,17 @@ def register_opt(*tags, **kwargs):
return
f
return
f
def
register_inplace
(
*
tags
,
**
kwargs
):
def
f
(
local_opt
):
name
=
(
kwargs
and
kwargs
.
pop
(
'name'
))
or
local_opt
.
__name__
optdb
.
register
(
name
,
TopoOptimizer
(
local_opt
,
failure_callback
=
TopoOptimizer
.
warn_inplace
),
60
,
'fast_run'
,
'inplace'
,
'gpu'
,
*
tags
)
return
local_opt
return
f
_logger_name
=
'theano.sandbox.cuda'
_logger_name
=
'theano.sandbox.cuda'
_logger
=
logging
.
getLogger
(
_logger_name
)
_logger
=
logging
.
getLogger
(
_logger_name
)
...
...
theano/sandbox/cuda/dnn.py
浏览文件 @
8b9f7336
差异被折叠。
点击展开。
theano/sandbox/cuda/opt.py
浏览文件 @
8b9f7336
...
@@ -3050,3 +3050,28 @@ conv_groupopt.register('local_abstractconv3d_gradinputs_gemm',
...
@@ -3050,3 +3050,28 @@ conv_groupopt.register('local_abstractconv3d_gradinputs_gemm',
local_abstractconv3d_gradinputs_gemm
,
30
,
local_abstractconv3d_gradinputs_gemm
,
30
,
'conv_gemm'
,
'conv_gemm'
,
'gpu'
,
'fast_compile'
,
'fast_run'
)
'gpu'
,
'fast_compile'
,
'fast_run'
)
# Register cuDNN batch normalization implementation
abstract_batch_norm_groupopt
=
theano
.
gof
.
optdb
.
LocalGroupDB
()
abstract_batch_norm_groupopt
.
__name__
=
"gpu_batchnorm_opts"
register_opt
(
'fast_compile'
)(
abstract_batch_norm_groupopt
)
# cuDNN optimizations are only registered if cuDNN is available.
# (we import these opts here instead of at the top of this file
# to avoid a circular dependency problem with dnn)
from
.dnn
import
(
local_abstract_batch_norm_train_cudnn
,
local_abstract_batch_norm_train_grad_cudnn
,
local_abstract_batch_norm_inference_cudnn
)
# noqa: 402
abstract_batch_norm_groupopt
.
register
(
'local_abstract_batch_norm_train_dnn'
,
local_abstract_batch_norm_train_cudnn
,
20
,
'batchnorm_dnn'
,
'gpu'
,
'fast_compile'
,
'fast_run'
,
'cudnn'
)
abstract_batch_norm_groupopt
.
register
(
'local_abstract_batch_norm_train_grad_dnn'
,
local_abstract_batch_norm_train_grad_cudnn
,
20
,
'batchnorm_dnn'
,
'gpu'
,
'fast_compile'
,
'fast_run'
,
'cudnn'
)
abstract_batch_norm_groupopt
.
register
(
'local_abstract_batch_norm_inference_dnn'
,
local_abstract_batch_norm_inference_cudnn
,
20
,
'batchnorm_dnn'
,
'gpu'
,
'fast_compile'
,
'fast_run'
,
'cudnn'
)
theano/sandbox/cuda/tests/test_dnn.py
浏览文件 @
8b9f7336
差异被折叠。
点击展开。
theano/tensor/nnet/bn.py
浏览文件 @
8b9f7336
差异被折叠。
点击展开。
theano/tensor/nnet/tests/test_bn.py
浏览文件 @
8b9f7336
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论