Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
7278aa7b
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
7278aa7b
编写于
1月 25, 2018
作者:
Y
Yang yaming
提交者:
GitHub
1月 25, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7739 from pkuyym/fix-7717
Add python wrapper for multiplex operator.
上级
33093002
9d826e1c
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
84 addition
and
4 deletion
+84
-4
doc/api/v2/fluid/layers.rst
doc/api/v2/fluid/layers.rst
+5
-0
paddle/operators/multiplex_op.cc
paddle/operators/multiplex_op.cc
+8
-2
paddle/operators/multiplex_op.cu
paddle/operators/multiplex_op.cu
+8
-2
python/paddle/v2/fluid/layers/nn.py
python/paddle/v2/fluid/layers/nn.py
+53
-0
python/paddle/v2/fluid/tests/test_layers.py
python/paddle/v2/fluid/tests/test_layers.py
+10
-0
未找到文件。
doc/api/v2/fluid/layers.rst
浏览文件 @
7278aa7b
...
@@ -534,3 +534,8 @@ row_conv
...
@@ -534,3 +534,8 @@ row_conv
--------
--------
.. autofunction:: paddle.v2.fluid.layers.row_conv
.. autofunction:: paddle.v2.fluid.layers.row_conv
:noindex:
:noindex:
multiplex
---------
.. autofunction:: paddle.v2.fluid.layers.multiplex
:noindex:
paddle/operators/multiplex_op.cc
浏览文件 @
7278aa7b
...
@@ -119,7 +119,13 @@ REGISTER_OPERATOR(multiplex, ops::MultiplexOp, ops::MultiplexOpMaker,
...
@@ -119,7 +119,13 @@ REGISTER_OPERATOR(multiplex, ops::MultiplexOp, ops::MultiplexOpMaker,
REGISTER_OPERATOR
(
multiplex_grad
,
ops
::
MultiplexGradOp
);
REGISTER_OPERATOR
(
multiplex_grad
,
ops
::
MultiplexGradOp
);
REGISTER_OP_CPU_KERNEL
(
REGISTER_OP_CPU_KERNEL
(
multiplex
,
multiplex
,
ops
::
MultiplexCPUKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
);
ops
::
MultiplexCPUKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
ops
::
MultiplexCPUKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
,
ops
::
MultiplexCPUKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int
>
,
ops
::
MultiplexCPUKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int64_t
>
);
REGISTER_OP_CPU_KERNEL
(
REGISTER_OP_CPU_KERNEL
(
multiplex_grad
,
multiplex_grad
,
ops
::
MultiplexGradCPUKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
);
ops
::
MultiplexGradCPUKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
ops
::
MultiplexGradCPUKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
,
ops
::
MultiplexGradCPUKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int
>
,
ops
::
MultiplexGradCPUKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int64_t
>
);
paddle/operators/multiplex_op.cu
浏览文件 @
7278aa7b
...
@@ -90,7 +90,13 @@ namespace ops = paddle::operators;
...
@@ -90,7 +90,13 @@ namespace ops = paddle::operators;
REGISTER_OP_CUDA_KERNEL
(
REGISTER_OP_CUDA_KERNEL
(
multiplex
,
multiplex
,
ops
::
MultiplexGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
);
ops
::
MultiplexGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
,
ops
::
MultiplexGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
double
>
,
ops
::
MultiplexGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int
>
,
ops
::
MultiplexGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int64_t
>
);
REGISTER_OP_CUDA_KERNEL
(
REGISTER_OP_CUDA_KERNEL
(
multiplex_grad
,
multiplex_grad
,
ops
::
MultiplexGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
);
ops
::
MultiplexGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
,
ops
::
MultiplexGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
double
>
,
ops
::
MultiplexGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int
>
,
ops
::
MultiplexGradGPUKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int64_t
>
);
python/paddle/v2/fluid/layers/nn.py
浏览文件 @
7278aa7b
...
@@ -63,6 +63,7 @@ __all__ = [
...
@@ -63,6 +63,7 @@ __all__ = [
'nce'
,
'nce'
,
'beam_search'
,
'beam_search'
,
'row_conv'
,
'row_conv'
,
'multiplex'
,
]
]
...
@@ -2707,3 +2708,55 @@ def row_conv(input, future_context_size, param_attr=None, act=None):
...
@@ -2707,3 +2708,55 @@ def row_conv(input, future_context_size, param_attr=None, act=None):
'Filter'
:
[
filter_param
]},
'Filter'
:
[
filter_param
]},
outputs
=
{
'Out'
:
[
out
]})
outputs
=
{
'Out'
:
[
out
]})
return
helper
.
append_activation
(
out
)
return
helper
.
append_activation
(
out
)
def
multiplex
(
inputs
,
index
):
"""
**Multiplex Layer**
Referring to the given index variable, this layer selects rows from the
input variables to construct a multiplex variable. Assuming that there are
:math:`m` input variables and :math:`I_i` represents the i-th input
variable and :math:`i` is in [0, :math:`m`). All input variables are
tensors with same shape [:math:`d_0`, :math:`d_1`, ..., :math:`d_R`].
Please note that rank of the input tensor should be at least 2. Each input
variable will be treated as a 2-D matrix with shape [:math:`M`, :math:`N`]
where :math:`M` for :math:`d_0` and :math:`N` for :math:`d_1` * :math:`d_2`
* ... * :math:`d_R`. Let :math:`I_i[j]` be the j-th row of the i-th input
variable. The given index variable should be a 2-D tensor with shape
[:math:`M`, 1]. Let `ID[i]` be the i-th index value of the index variable.
Then the output variable will be a tensor with shape [:math:`d_0`,
:math:`d_1`, ..., :math:`d_R`]. If we treat the output tensor as a 2-D
matrix with shape [:math:`M`, :math:`N`] and let :math:`O[i]` be the i-th
row of the matrix, then `O[i]` is equal to :math:`I_{ID[i]}[i]`.
Args:
inputs (list): A list of variables to gather from. All variables have the
same shape and the rank is at least 2.
index (Variable): Tensor<int32>, index variable which is a 2-D tensor
with shape [M, 1] where M is the batch size.
Returns:
Variable: Multiplex variable gathered from input variables.
Examples:
.. code-block:: python
x1 = fluid.layers.data(name='x1', shape=[4], dtype='float32')
x2 = fluid.layers.data(name='x2', shape=[4], dtype='float32')
index = fluid.layers.data(name='index', shape=[1], dtype='int32')
out = fluid.layers.multiplex(inputs=[x1, x2], index=index)
"""
helper
=
LayerHelper
(
'multiplex'
,
**
locals
())
if
not
isinstance
(
inputs
,
list
)
and
len
(
inputs
)
<
2
:
raise
ValueError
(
"inputs should be a list object and contains at least "
"2 elements."
)
out
=
helper
.
create_tmp_variable
(
inputs
[
0
].
dtype
)
helper
.
append_op
(
type
=
'multiplex'
,
inputs
=
{
'X'
:
inputs
,
'Ids'
:
index
},
outputs
=
{
'Out'
:
[
out
]})
return
out
python/paddle/v2/fluid/tests/test_layers.py
浏览文件 @
7278aa7b
...
@@ -279,6 +279,16 @@ class TestBook(unittest.TestCase):
...
@@ -279,6 +279,16 @@ class TestBook(unittest.TestCase):
self
.
assertIsNotNone
(
out
)
self
.
assertIsNotNone
(
out
)
print
(
str
(
program
))
print
(
str
(
program
))
def
test_multiplex
(
self
):
program
=
Program
()
with
program_guard
(
program
):
x1
=
layers
.
data
(
name
=
'x1'
,
shape
=
[
4
],
dtype
=
'float32'
)
x2
=
layers
.
data
(
name
=
'x2'
,
shape
=
[
4
],
dtype
=
'float32'
)
index
=
layers
.
data
(
name
=
'index'
,
shape
=
[
1
],
dtype
=
'int32'
)
out
=
layers
.
multiplex
(
inputs
=
[
x1
,
x2
],
index
=
index
)
self
.
assertIsNotNone
(
out
)
print
(
str
(
program
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录