Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
9edfd200
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
接近 2 年 前同步成功
通知
706
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9edfd200
编写于
1月 10, 2017
作者:
X
xutianbing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use Daoyuan's SequenceArg.
上级
23ac0b78
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
28 addition
and
20 deletion
+28
-20
paddle/function/BufferArg.h
paddle/function/BufferArg.h
+2
-1
paddle/function/ContextProjectionOp.cpp
paddle/function/ContextProjectionOp.cpp
+13
-13
paddle/function/ContextProjectionOpTest.cpp
paddle/function/ContextProjectionOpTest.cpp
+2
-4
paddle/function/Function.cpp
paddle/function/Function.cpp
+6
-0
paddle/function/Function.h
paddle/function/Function.h
+4
-0
paddle/gserver/layers/ContextProjection.cpp
paddle/gserver/layers/ContextProjection.cpp
+1
-2
未找到文件。
paddle/function/BufferArg.h
浏览文件 @
9edfd200
...
@@ -190,7 +190,7 @@ private:
...
@@ -190,7 +190,7 @@ private:
size_t
numSeqs_
;
size_t
numSeqs_
;
};
};
// sequence data
// sequence data
{seqId(vec), buf(matrix)}
class
SequenceArg
:
public
BufferArg
{
class
SequenceArg
:
public
BufferArg
{
public:
public:
SequenceArg
(
void
*
buf
,
SequenceArg
(
void
*
buf
,
...
@@ -210,6 +210,7 @@ public:
...
@@ -210,6 +210,7 @@ public:
void
*
getIdBuf
()
const
{
return
startPositions_
.
data
();
}
void
*
getIdBuf
()
const
{
return
startPositions_
.
data
();
}
size_t
numSeqs
()
const
{
return
startPositions_
.
numSeqs
();
}
size_t
numSeqs
()
const
{
return
startPositions_
.
numSeqs
();
}
const
SequenceIdArg
&
getSequenceIds
()
const
{
return
startPositions_
;
}
private:
private:
SequenceIdArg
startPositions_
;
SequenceIdArg
startPositions_
;
...
...
paddle/function/ContextProjectionOp.cpp
浏览文件 @
9edfd200
...
@@ -17,7 +17,6 @@ limitations under the License. */
...
@@ -17,7 +17,6 @@ limitations under the License. */
#include "paddle/math/Vector.h"
#include "paddle/math/Vector.h"
namespace
paddle
{
namespace
paddle
{
/**
/**
* Context Projection Forward with CPU Matrix Device.
* Context Projection Forward with CPU Matrix Device.
*
*
...
@@ -208,10 +207,10 @@ void ContextProjectionBackward<DEVICE_TYPE_CPU>(const CpuMatrix& out_grad_mat,
...
@@ -208,10 +207,10 @@ void ContextProjectionBackward<DEVICE_TYPE_CPU>(const CpuMatrix& out_grad_mat,
* Context Projection Backward Function.
* Context Projection Backward Function.
* Update the weight gradient and input layer gradient with backprop
* Update the weight gradient and input layer gradient with backprop
*
*
* \param inputs[0] input sequence.
* \param inputs[0]
.seq
input sequence.
* \param inputs[
1]
output layer grad.
* \param inputs[
0].matrix
output layer grad.
* \param outputs[0] input layer grad.
* \param outputs[0]
input layer grad.
* \param outputs[1] weight grad.
* \param outputs[1]
weight grad.
*/
*/
template
<
DeviceType
Device
>
template
<
DeviceType
Device
>
class
ContextProjectionBackwardFunc
:
public
FunctionBase
{
class
ContextProjectionBackwardFunc
:
public
FunctionBase
{
...
@@ -225,27 +224,28 @@ public:
...
@@ -225,27 +224,28 @@ public:
}
}
void
calc
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
void
calc
(
const
BufferArgs
&
inputs
,
const
BufferArgs
&
outputs
)
override
{
CHECK_EQ
((
size_t
)
2
,
inputs
.
size
());
CHECK_EQ
((
size_t
)
1
,
inputs
.
size
());
CHECK_EQ
((
size_t
)
2
,
outputs
.
size
());
CHECK_EQ
((
size_t
)
2
,
outputs
.
size
());
CHECK
(
inputs
[
0
].
data
()
&&
inputs
[
1
].
data
());
const
auto
seqArg
=
dynamic_cast
<
const
SequenceArg
&>
(
inputs
[
0
]);
CHECK_EQ
(
inputs
[
0
].
shape
().
ndims
(),
(
size_t
)
1
);
CHECK
(
seqArg
.
data
()
&&
inputs
[
0
].
data
());
CHECK_EQ
(
inputs
[
1
].
shape
().
ndims
(),
(
size_t
)
2
);
CHECK_EQ
(
seqArg
.
shape
().
ndims
(),
(
size_t
)
2
);
CHECK_EQ
(
seqArg
.
getSequenceIds
().
shape
().
ndims
(),
(
size_t
)
1
);
CHECK_EQ
(
outputs
[
0
].
shape
().
ndims
(),
(
size_t
)
2
);
CHECK_EQ
(
outputs
[
0
].
shape
().
ndims
(),
(
size_t
)
2
);
CHECK_EQ
(
outputs
[
1
].
shape
().
ndims
(),
(
size_t
)
2
);
CHECK_EQ
(
outputs
[
1
].
shape
().
ndims
(),
(
size_t
)
2
);
/// dim of input grad == dim of weight
/// dim of input grad == dim of weight
CHECK_EQ
(
outputs
[
0
].
shape
()[
1
],
outputs
[
1
].
shape
()[
1
]);
CHECK_EQ
(
outputs
[
0
].
shape
()[
1
],
outputs
[
1
].
shape
()[
1
]);
/// input and output grad has the same batch_size
/// input and output grad has the same batch_size
CHECK_EQ
(
outputs
[
0
].
shape
()[
0
],
inputs
[
1
]
.
shape
()[
0
]);
CHECK_EQ
(
outputs
[
0
].
shape
()[
0
],
seqArg
.
shape
()[
0
]);
/// dim of output val = dim of input grad * context_length
/// dim of output val = dim of input grad * context_length
CHECK_EQ
(
inputs
[
1
]
.
shape
()[
1
],
outputs
[
0
].
shape
()[
1
]
*
context_length_
);
CHECK_EQ
(
seqArg
.
shape
()[
1
],
outputs
[
0
].
shape
()[
1
]
*
context_length_
);
CHECK_EQ
(
outputs
[
0
].
getArgType
(),
ADD_TO
);
CHECK_EQ
(
outputs
[
0
].
getArgType
(),
ADD_TO
);
CHECK_EQ
(
outputs
[
1
].
getArgType
(),
ADD_TO
);
CHECK_EQ
(
outputs
[
1
].
getArgType
(),
ADD_TO
);
const
auto
seq_vec
=
inputs
[
0
]
.
vector
<
int
,
Device
>
();
const
auto
seq_vec
=
seqArg
.
getSequenceIds
()
.
vector
<
int
,
Device
>
();
const
auto
out_grad_mat
=
inputs
[
1
]
.
matrix
<
Device
>
();
const
auto
out_grad_mat
=
seqArg
.
matrix
<
Device
>
();
auto
in_grad_mat
=
auto
in_grad_mat
=
!
outputs
[
0
].
data
()
!
outputs
[
0
].
data
()
?
typename
Tensor
<
real
,
Device
>::
Matrix
(
nullptr
,
0
,
0
)
?
typename
Tensor
<
real
,
Device
>::
Matrix
(
nullptr
,
0
,
0
)
...
...
paddle/function/ContextProjectionOpTest.cpp
浏览文件 @
9edfd200
...
@@ -122,8 +122,7 @@ void testMatrixProjectionBackward(int context_start,
...
@@ -122,8 +122,7 @@ void testMatrixProjectionBackward(int context_start,
BufferArgs
cpu_inputs
;
BufferArgs
cpu_inputs
;
BufferArgs
cpu_outputs
;
BufferArgs
cpu_outputs
;
cpu_inputs
.
addArg
(
*
cpu_seq
);
cpu_inputs
.
addArg
(
cpu_out_grad
,
*
cpu_seq
);
cpu_inputs
.
addArg
(
cpu_out_grad
);
cpu_outputs
.
addArg
(
cpu_in_grad
,
ADD_TO
);
cpu_outputs
.
addArg
(
cpu_in_grad
,
ADD_TO
);
cpu_outputs
.
addArg
(
cpu_outputs
.
addArg
(
cpu_w_grad
?
*
cpu_w_grad
:
CpuMatrix
(
nullptr
,
0
,
input_dim
),
ADD_TO
);
cpu_w_grad
?
*
cpu_w_grad
:
CpuMatrix
(
nullptr
,
0
,
input_dim
),
ADD_TO
);
...
@@ -132,8 +131,7 @@ void testMatrixProjectionBackward(int context_start,
...
@@ -132,8 +131,7 @@ void testMatrixProjectionBackward(int context_start,
BufferArgs
gpu_inputs
;
BufferArgs
gpu_inputs
;
BufferArgs
gpu_outputs
;
BufferArgs
gpu_outputs
;
gpu_inputs
.
addArg
(
*
gpu_seq
);
gpu_inputs
.
addArg
(
gpu_out_grad
,
*
gpu_seq
);
gpu_inputs
.
addArg
(
gpu_out_grad
);
gpu_outputs
.
addArg
(
gpu_in_grad
,
ADD_TO
);
gpu_outputs
.
addArg
(
gpu_in_grad
,
ADD_TO
);
gpu_outputs
.
addArg
(
gpu_outputs
.
addArg
(
gpu_w_grad
?
*
gpu_w_grad
:
GpuMatrix
(
nullptr
,
0
,
input_dim
),
ADD_TO
);
gpu_w_grad
?
*
gpu_w_grad
:
GpuMatrix
(
nullptr
,
0
,
input_dim
),
ADD_TO
);
...
...
paddle/function/Function.cpp
浏览文件 @
9edfd200
...
@@ -90,6 +90,12 @@ void BufferArgs::addArg(const GpuSparseMatrix& arg, ArgType argType) {
...
@@ -90,6 +90,12 @@ void BufferArgs::addArg(const GpuSparseMatrix& arg, ArgType argType) {
args_
.
push_back
(
std
::
make_shared
<
SparseMatrixArg
>
(
arg
,
argType
));
args_
.
push_back
(
std
::
make_shared
<
SparseMatrixArg
>
(
arg
,
argType
));
}
}
void
BufferArgs
::
addArg
(
const
Matrix
&
matrix
,
const
IVector
&
vector
,
ArgType
argType
)
{
args_
.
push_back
(
std
::
make_shared
<
SequenceArg
>
(
matrix
,
vector
,
argType
));
}
ClassRegistrar
<
FunctionBase
>
FunctionBase
::
funcRegistrar_
;
ClassRegistrar
<
FunctionBase
>
FunctionBase
::
funcRegistrar_
;
}
// namespace paddle
}
// namespace paddle
paddle/function/Function.h
浏览文件 @
9edfd200
...
@@ -77,6 +77,10 @@ public:
...
@@ -77,6 +77,10 @@ public:
void
addArg
(
const
CpuSparseMatrix
&
arg
,
ArgType
argType
=
UNSPECIFIED
);
void
addArg
(
const
CpuSparseMatrix
&
arg
,
ArgType
argType
=
UNSPECIFIED
);
void
addArg
(
const
GpuSparseMatrix
&
arg
,
ArgType
argType
=
UNSPECIFIED
);
void
addArg
(
const
GpuSparseMatrix
&
arg
,
ArgType
argType
=
UNSPECIFIED
);
void
addArg
(
const
Matrix
&
matrix
,
const
IVector
&
vector
,
ArgType
argType
=
UNSPECIFIED
);
// get argument
// get argument
const
BufferArg
&
operator
[](
size_t
num
)
const
{
const
BufferArg
&
operator
[](
size_t
num
)
const
{
CHECK_LT
(
num
,
args_
.
size
());
CHECK_LT
(
num
,
args_
.
size
());
...
...
paddle/gserver/layers/ContextProjection.cpp
浏览文件 @
9edfd200
...
@@ -166,8 +166,7 @@ void ContextProjection::backward(const UpdateCallback& callback) {
...
@@ -166,8 +166,7 @@ void ContextProjection::backward(const UpdateCallback& callback) {
BufferArgs
inputs
;
BufferArgs
inputs
;
BufferArgs
outputs
;
BufferArgs
outputs
;
inputs
.
addArg
(
*
in_
->
sequenceStartPositions
->
getVector
(
useGpu_
));
inputs
.
addArg
(
*
out_
->
grad
,
*
in_
->
sequenceStartPositions
->
getVector
(
useGpu_
));
inputs
.
addArg
(
*
out_
->
grad
);
outputs
.
addArg
(
outputs
.
addArg
(
CpuMatrix
(
CpuMatrix
(
in_
->
grad
?
in_
->
grad
->
getData
()
:
nullptr
,
batch_size
,
input_dim
),
in_
->
grad
?
in_
->
grad
->
getData
()
:
nullptr
,
batch_size
,
input_dim
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录