提交 eb2123e1 编写于 作者: D dengkaipeng

fix doc and jit. test=develop

上级 7920e3be
...@@ -86,7 +86,7 @@ paddle.fluid.layers.conv2d (ArgSpec(args=['input', 'num_filters', 'filter_size', ...@@ -86,7 +86,7 @@ paddle.fluid.layers.conv2d (ArgSpec(args=['input', 'num_filters', 'filter_size',
paddle.fluid.layers.conv3d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None)), ('document', '37042620f9bd3a2da6e5d3138b2f724b')) paddle.fluid.layers.conv3d (ArgSpec(args=['input', 'num_filters', 'filter_size', 'stride', 'padding', 'dilation', 'groups', 'param_attr', 'bias_attr', 'use_cudnn', 'act', 'name'], varargs=None, keywords=None, defaults=(1, 0, 1, None, None, None, True, None, None)), ('document', '37042620f9bd3a2da6e5d3138b2f724b'))
paddle.fluid.layers.sequence_pool (ArgSpec(args=['input', 'pool_type', 'is_test'], varargs=None, keywords=None, defaults=(False,)), ('document', 'a194fb80614023f543df3949fbd0d0b8')) paddle.fluid.layers.sequence_pool (ArgSpec(args=['input', 'pool_type', 'is_test'], varargs=None, keywords=None, defaults=(False,)), ('document', 'a194fb80614023f543df3949fbd0d0b8'))
paddle.fluid.layers.sequence_softmax (ArgSpec(args=['input', 'use_cudnn', 'name'], varargs=None, keywords=None, defaults=(False, None)), ('document', '19ef6f9cdd27feac8a1ae060f19c10b4')) paddle.fluid.layers.sequence_softmax (ArgSpec(args=['input', 'use_cudnn', 'name'], varargs=None, keywords=None, defaults=(False, None)), ('document', '19ef6f9cdd27feac8a1ae060f19c10b4'))
paddle.fluid.layers.softmax (ArgSpec(args=['input', 'use_cudnn', 'name', 'axis'], varargs=None, keywords=None, defaults=(False, None, -1)), ('document', '502bad9e8bc7ef24817d0d4b20f61df3')) paddle.fluid.layers.softmax (ArgSpec(args=['input', 'use_cudnn', 'name', 'axis'], varargs=None, keywords=None, defaults=(False, None, -1)), ('document', '59b1c6bf2f0fa9dc649c85fef3a3b2ea'))
paddle.fluid.layers.pool2d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'pool_stride', 'pool_padding', 'global_pooling', 'use_cudnn', 'ceil_mode', 'name', 'exclusive'], varargs=None, keywords=None, defaults=(-1, 'max', 1, 0, False, True, False, None, True)), ('document', 'bbd84e855e660cd1084bb71a2fd0cdaa')) paddle.fluid.layers.pool2d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'pool_stride', 'pool_padding', 'global_pooling', 'use_cudnn', 'ceil_mode', 'name', 'exclusive'], varargs=None, keywords=None, defaults=(-1, 'max', 1, 0, False, True, False, None, True)), ('document', 'bbd84e855e660cd1084bb71a2fd0cdaa'))
paddle.fluid.layers.pool3d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'pool_stride', 'pool_padding', 'global_pooling', 'use_cudnn', 'ceil_mode', 'name', 'exclusive'], varargs=None, keywords=None, defaults=(-1, 'max', 1, 0, False, True, False, None, True)), ('document', '043de7333b79ee0ac55053c14ed81625')) paddle.fluid.layers.pool3d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'pool_stride', 'pool_padding', 'global_pooling', 'use_cudnn', 'ceil_mode', 'name', 'exclusive'], varargs=None, keywords=None, defaults=(-1, 'max', 1, 0, False, True, False, None, True)), ('document', '043de7333b79ee0ac55053c14ed81625'))
paddle.fluid.layers.adaptive_pool2d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'require_index', 'name'], varargs=None, keywords=None, defaults=('max', False, None)), ('document', '859b887174d06f361658f69cb7c06d95')) paddle.fluid.layers.adaptive_pool2d (ArgSpec(args=['input', 'pool_size', 'pool_type', 'require_index', 'name'], varargs=None, keywords=None, defaults=('max', False, None)), ('document', '859b887174d06f361658f69cb7c06d95'))
......
...@@ -38,6 +38,8 @@ typedef enum { ...@@ -38,6 +38,8 @@ typedef enum {
kNCHW16CMulNC, kNCHW16CMulNC,
kSeqPool, kSeqPool,
kSoftmax, kSoftmax,
kStrideASum,
kStrideScal,
kVAdd, kVAdd,
kVAddBias, kVAddBias,
kVAddRelu, kVAddRelu,
...@@ -53,8 +55,6 @@ typedef enum { ...@@ -53,8 +55,6 @@ typedef enum {
kVSquare, kVSquare,
kVSub, kVSub,
kVTanh, kVTanh,
kStrideASum,
kStrideScal,
} KernelType; } KernelType;
typedef enum { typedef enum {
......
...@@ -50,11 +50,12 @@ void VTanh(const T* x, T* y, int n) { ...@@ -50,11 +50,12 @@ void VTanh(const T* x, T* y, int n) {
compute_addbias(&b, y, y, n); compute_addbias(&b, y, y, n);
} }
// remain is the product of dimension shapes after the axis dimension
void Softmax(const T* x, T* y, int n, int bs, int remain) { void Softmax(const T* x, T* y, int n, int bs, int remain) {
auto compute_hmax = KernelFuncs<HMaxTuple<T>, CPUPlace>::Cache().At(n); auto compute_hmax = KernelFuncs<HMaxTuple<T>, CPUPlace>::Cache().At(n);
auto compute_hsum = KernelFuncs<HSumTuple<T>, CPUPlace>::Cache().At(n); auto compute_hsum = KernelFuncs<HSumTuple<T>, CPUPlace>::Cache().At(n);
auto compute_vscal = KernelFuncs<VScalTuple<T>, CPUPlace>::Cache().At(n); auto compute_vscal = KernelFuncs<VScalTuple<T>, CPUPlace>::Cache().At(n);
auto compute_stridesum = auto compute_strideasum =
KernelFuncs<StrideASumTuple<T>, CPUPlace>::Cache().At(n); KernelFuncs<StrideASumTuple<T>, CPUPlace>::Cache().At(n);
auto compute_stridescal = auto compute_stridescal =
KernelFuncs<StrideScalTuple<T>, CPUPlace>::Cache().At(n); KernelFuncs<StrideScalTuple<T>, CPUPlace>::Cache().At(n);
...@@ -74,7 +75,7 @@ void Softmax(const T* x, T* y, int n, int bs, int remain) { ...@@ -74,7 +75,7 @@ void Softmax(const T* x, T* y, int n, int bs, int remain) {
compute_vscal(&scalar, y, y, n); compute_vscal(&scalar, y, y, n);
} else { } else {
for (int j = 0; j < remain; ++j) { for (int j = 0; j < remain; ++j) {
compute_stridesum(&y[j], &scalar, n, remain); compute_strideasum(&y[j], &scalar, n, remain);
scalar = static_cast<T>(1) / scalar; scalar = static_cast<T>(1) / scalar;
compute_stridescal(&scalar, &y[j], &y[j], n, remain); compute_stridescal(&scalar, &y[j], &y[j], n, remain);
} }
......
...@@ -134,6 +134,7 @@ void StrideASum(const T* x, T* res, int n, int stride); ...@@ -134,6 +134,7 @@ void StrideASum(const T* x, T* res, int n, int stride);
template <typename T> template <typename T>
void StrideScal(const T* a, const T* x, T* y, int n, int stride); void StrideScal(const T* a, const T* x, T* y, int n, int stride);
// remain is the product of dimension shapes after the axis dimension
template <typename T> template <typename T>
void Softmax(const T* x, T* y, int n, int bs, int remain = 1) { void Softmax(const T* x, T* y, int n, int bs, int remain = 1) {
std::vector<T> entities(bs); std::vector<T> entities(bs);
......
...@@ -432,6 +432,7 @@ void StrideScal(const T* a, const T* x, T* y, int n, int stride) { ...@@ -432,6 +432,7 @@ void StrideScal(const T* a, const T* x, T* y, int n, int stride) {
// y = e^(x - max(x)) // y = e^(x - max(x))
// y = y / sum(y) // y = y / sum(y)
// remain is the product of dimension shapes after the axis dimension
template <typename T> template <typename T>
void Softmax(const T* x, T* y, int n, int bs = 1, int remain = 1) { void Softmax(const T* x, T* y, int n, int bs = 1, int remain = 1) {
for (int i = 0; i < bs; ++i) { for (int i = 0; i < bs; ++i) {
......
...@@ -798,10 +798,8 @@ template <typename KernelTuple, typename PlaceType> ...@@ -798,10 +798,8 @@ template <typename KernelTuple, typename PlaceType>
void TestKernelStrideScal() { void TestKernelStrideScal() {
using T = typename KernelTuple::data_type; using T = typename KernelTuple::data_type;
VLOG(10) << "Test JITKernel: " << jit::to_string(KernelTuple::kernel_type); VLOG(10) << "Test JITKernel: " << jit::to_string(KernelTuple::kernel_type);
// for (int d : TestSizes()) { for (int d : TestSizes()) {
// for (int m : {1, 2, 3}) { // stride for (int m : {1, 2, 3}) { // stride
for (int d : {4}) {
for (int m : {2}) { // stride
if (m > d || d % m != 0) { if (m > d || d % m != 0) {
continue; continue;
} }
......
...@@ -1826,7 +1826,7 @@ def softmax(input, use_cudnn=False, name=None, axis=-1): ...@@ -1826,7 +1826,7 @@ def softmax(input, use_cudnn=False, name=None, axis=-1):
The dimension :attr:`axis` of the input tensor will be permuted to the last. The dimension :attr:`axis` of the input tensor will be permuted to the last.
Then the input tensor will be logically flattened to a 2-D matrix. The matrix's Then the input tensor will be logically flattened to a 2-D matrix. The matrix's
second dimension(row length) is as same as the dimension :attr:`axis` of the input second dimension(row length) is the same as the dimension :attr:`axis` of the input
tensor, and the first dimension(column length) is the product of all other tensor, and the first dimension(column length) is the product of all other
dimensions of the input tensor. For each row of the matrix, the softmax operator dimensions of the input tensor. For each row of the matrix, the softmax operator
squashes the K-dimensional(K is the width of the matrix, which is also the size squashes the K-dimensional(K is the width of the matrix, which is also the size
...@@ -1864,7 +1864,10 @@ def softmax(input, use_cudnn=False, name=None, axis=-1): ...@@ -1864,7 +1864,10 @@ def softmax(input, use_cudnn=False, name=None, axis=-1):
.. code-block:: python .. code-block:: python
fc = fluid.layers.fc(input=x, size=10) fc = fluid.layers.fc(input=x, size=10)
# perform softmax in the second dimension
softmax = fluid.layers.softmax(input=fc, axis=1) softmax = fluid.layers.softmax(input=fc, axis=1)
# perform softmax in the last dimension
softmax = fluid.layers.softmax(input=fc, axis=-1)
""" """
helper = LayerHelper('softmax', **locals()) helper = LayerHelper('softmax', **locals())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册