Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
17fcc4f5
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
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看板
未验证
提交
17fcc4f5
编写于
8月 23, 2018
作者:
Y
Yu Yang
提交者:
GitHub
8月 23, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12864 from reyoung/feature/process_lod_grad
Feature/process lod grad
上级
f5d5d7b2
eb8fd853
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
78 addition
and
27 deletion
+78
-27
paddle/fluid/operators/concat_op.h
paddle/fluid/operators/concat_op.h
+14
-2
paddle/fluid/operators/elementwise_add_mkldnn_op.cc
paddle/fluid/operators/elementwise_add_mkldnn_op.cc
+2
-1
paddle/fluid/operators/elementwise_add_op.h
paddle/fluid/operators/elementwise_add_op.h
+4
-1
paddle/fluid/operators/elementwise_div_op.h
paddle/fluid/operators/elementwise_div_op.h
+3
-2
paddle/fluid/operators/elementwise_max_op.h
paddle/fluid/operators/elementwise_max_op.h
+3
-1
paddle/fluid/operators/elementwise_min_op.h
paddle/fluid/operators/elementwise_min_op.h
+3
-2
paddle/fluid/operators/elementwise_mul_op.h
paddle/fluid/operators/elementwise_mul_op.h
+3
-1
paddle/fluid/operators/elementwise_op.h
paddle/fluid/operators/elementwise_op.h
+14
-0
paddle/fluid/operators/elementwise_sub_op.h
paddle/fluid/operators/elementwise_sub_op.h
+3
-1
paddle/fluid/operators/math/concat.cc
paddle/fluid/operators/math/concat.cc
+1
-1
paddle/fluid/operators/math/concat.cu
paddle/fluid/operators/math/concat.cu
+1
-1
paddle/fluid/operators/math/concat.h
paddle/fluid/operators/math/concat.h
+2
-2
paddle/fluid/operators/mul_op.h
paddle/fluid/operators/mul_op.h
+19
-11
paddle/fluid/operators/sequence_softmax_cudnn_op.cu.cc
paddle/fluid/operators/sequence_softmax_cudnn_op.cu.cc
+3
-1
paddle/fluid/operators/sequence_softmax_op.h
paddle/fluid/operators/sequence_softmax_op.h
+3
-0
未找到文件。
paddle/fluid/operators/concat_op.h
浏览文件 @
17fcc4f5
...
...
@@ -62,9 +62,21 @@ class ConcatGradKernel : public framework::OpKernel<T> {
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
{
auto
*
out_grad
=
ctx
.
Input
<
framework
::
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
ins
=
ctx
.
MultiInput
<
framework
::
Tensor
>
(
"X"
);
auto
ins
=
ctx
.
MultiInput
<
framework
::
LoD
Tensor
>
(
"X"
);
auto
out_var_names
=
ctx
.
Outputs
(
framework
::
GradVarName
(
"X"
));
auto
outs
=
ctx
.
MultiOutput
<
framework
::
Tensor
>
(
framework
::
GradVarName
(
"X"
));
auto
outs
=
ctx
.
MultiOutput
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"X"
));
{
auto
dx
=
outs
;
auto
x
=
ins
;
for
(
size_t
i
=
0
;
i
<
dx
.
size
();
++
i
)
{
if
(
dx
[
i
]
!=
nullptr
)
{
dx
[
i
]
->
set_lod
(
x
[
i
]
->
lod
());
}
}
}
int64_t
axis
=
static_cast
<
int64_t
>
(
ctx
.
Attr
<
int
>
(
"axis"
));
// get output tensor that the name is not kEmptyVarName
...
...
paddle/fluid/operators/elementwise_add_mkldnn_op.cc
浏览文件 @
17fcc4f5
...
...
@@ -137,9 +137,10 @@ class EltwiseAddMKLDNNKernel : public framework::OpKernel<T> {
};
template
<
typename
T
>
class
EltwiseAddMKLDNNGradKernel
:
public
framework
::
Op
Kernel
<
T
>
{
class
EltwiseAddMKLDNNGradKernel
:
public
ElemwiseGrad
Kernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
ElemwiseGradKernel
<
T
>::
Compute
(
ctx
);
using
Tensor
=
framework
::
Tensor
;
auto
*
dout
=
ctx
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
...
...
paddle/fluid/operators/elementwise_add_op.h
浏览文件 @
17fcc4f5
...
...
@@ -15,6 +15,7 @@ limitations under the License. */
#pragma once
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/operators/elementwise_op.h"
#include "paddle/fluid/operators/elementwise_op_function.h"
#include "paddle/fluid/operators/math/blas.h"
...
...
@@ -136,9 +137,11 @@ elementwise_add_grad(const framework::ExecutionContext& ctx,
}
template
<
typename
DeviceContext
,
typename
T
>
class
ElementwiseAddGradKernel
:
public
framework
::
Op
Kernel
<
T
>
{
class
ElementwiseAddGradKernel
:
public
ElemwiseGrad
Kernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
ElemwiseGradKernel
<
T
>::
Compute
(
ctx
);
using
Tensor
=
framework
::
Tensor
;
auto
*
dout
=
ctx
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
...
...
paddle/fluid/operators/elementwise_div_op.h
浏览文件 @
17fcc4f5
...
...
@@ -14,8 +14,8 @@ limitations under the License. */
#pragma once
#include "paddle/fluid/operators/elementwise_op.h"
#include "paddle/fluid/operators/elementwise_op_function.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -53,9 +53,10 @@ struct DivGradDY {
};
template
<
typename
DeviceContext
,
typename
T
>
class
ElementwiseDivGradKernel
:
public
framework
::
Op
Kernel
<
T
>
{
class
ElementwiseDivGradKernel
:
public
ElemwiseGrad
Kernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
ElemwiseGradKernel
<
T
>::
Compute
(
ctx
);
using
Tensor
=
framework
::
Tensor
;
auto
*
x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
...
...
paddle/fluid/operators/elementwise_max_op.h
浏览文件 @
17fcc4f5
...
...
@@ -14,6 +14,7 @@ limitations under the License. */
#pragma once
#include "paddle/fluid/operators/elementwise_op.h"
#include "paddle/fluid/operators/elementwise_op_function.h"
namespace
paddle
{
...
...
@@ -55,9 +56,10 @@ struct MaxGradDy {
};
template
<
typename
DeviceContext
,
typename
T
>
class
ElementwiseMaxGradKernel
:
public
framework
::
Op
Kernel
<
T
>
{
class
ElementwiseMaxGradKernel
:
public
ElemwiseGrad
Kernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
ElemwiseGradKernel
<
T
>::
Compute
(
ctx
);
using
Tensor
=
framework
::
Tensor
;
auto
*
x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
...
...
paddle/fluid/operators/elementwise_min_op.h
浏览文件 @
17fcc4f5
...
...
@@ -14,8 +14,8 @@ limitations under the License. */
#pragma once
#include "paddle/fluid/operators/elementwise_op.h"
#include "paddle/fluid/operators/elementwise_op_function.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -55,9 +55,10 @@ struct MinGradDy {
};
template
<
typename
DeviceContext
,
typename
T
>
class
ElementwiseMinGradKernel
:
public
framework
::
Op
Kernel
<
T
>
{
class
ElementwiseMinGradKernel
:
public
ElemwiseGrad
Kernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
ElemwiseGradKernel
<
T
>::
Compute
(
ctx
);
using
Tensor
=
framework
::
Tensor
;
auto
*
x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
...
...
paddle/fluid/operators/elementwise_mul_op.h
浏览文件 @
17fcc4f5
...
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include "paddle/fluid/operators/elementwise_op.h"
#include "paddle/fluid/operators/elementwise_op_function.h"
#include "paddle/fluid/operators/math/blas.h"
...
...
@@ -84,9 +85,10 @@ struct MulGradDY {
};
template
<
typename
DeviceContext
,
typename
T
>
class
ElementwiseMulGradKernel
:
public
framework
::
Op
Kernel
<
T
>
{
class
ElementwiseMulGradKernel
:
public
ElemwiseGrad
Kernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
ElemwiseGradKernel
<
T
>::
Compute
(
ctx
);
using
Tensor
=
framework
::
Tensor
;
auto
*
x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
...
...
paddle/fluid/operators/elementwise_op.h
浏览文件 @
17fcc4f5
...
...
@@ -205,6 +205,20 @@ class ElementwiseOpExplicitGrad : public ElementwiseOpGrad {
}
};
template
<
typename
T
>
class
ElemwiseGradKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
*
dx
=
context
.
Output
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"X"
));
if
(
dx
!=
nullptr
)
{
auto
&
dout
=
*
context
.
Input
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"Out"
));
dx
->
set_lod
(
dout
.
lod
());
}
}
};
}
// namespace operators
}
// namespace paddle
...
...
paddle/fluid/operators/elementwise_sub_op.h
浏览文件 @
17fcc4f5
...
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include "paddle/fluid/operators/elementwise_op.h"
#include "paddle/fluid/operators/elementwise_op_function.h"
namespace
paddle
{
...
...
@@ -50,9 +51,10 @@ struct SubGradDY {
};
template
<
typename
DeviceContext
,
typename
T
>
class
ElementwiseSubGradKernel
:
public
framework
::
Op
Kernel
<
T
>
{
class
ElementwiseSubGradKernel
:
public
ElemwiseGrad
Kernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
ElemwiseGradKernel
<
T
>::
Compute
(
ctx
);
using
Tensor
=
framework
::
Tensor
;
auto
*
dout
=
ctx
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
...
...
paddle/fluid/operators/math/concat.cc
浏览文件 @
17fcc4f5
...
...
@@ -71,7 +71,7 @@ class ConcatGradFunctor<platform::CPUDeviceContext, T> {
public:
void
operator
()(
const
platform
::
CPUDeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
const
std
::
vector
<
const
framework
::
Tensor
*>&
ref_inputs
,
const
std
::
vector
<
const
framework
::
LoD
Tensor
*>&
ref_inputs
,
const
int
axis
,
std
::
vector
<
framework
::
Tensor
*>*
outputs
)
{
// TODO(zcd): Add input data validity checking
size_t
num
=
outputs
->
size
();
...
...
paddle/fluid/operators/math/concat.cu
浏览文件 @
17fcc4f5
...
...
@@ -189,7 +189,7 @@ class ConcatGradFunctor<platform::CUDADeviceContext, T> {
public:
void
operator
()(
const
platform
::
CUDADeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
const
std
::
vector
<
const
framework
::
Tensor
*>&
ref_inputs
,
const
std
::
vector
<
const
framework
::
LoD
Tensor
*>&
ref_inputs
,
const
int
axis
,
std
::
vector
<
framework
::
Tensor
*>*
outputs
)
{
// TODO(zcd): Add input data validity checking
int
o_num
=
outputs
->
size
();
...
...
paddle/fluid/operators/math/concat.h
浏览文件 @
17fcc4f5
...
...
@@ -15,7 +15,7 @@ limitations under the License. */
#pragma once
#include <vector>
#include "paddle/fluid/framework/data_type.h"
#include "paddle/fluid/framework/tensor.h"
#include "paddle/fluid/framework/
lod_
tensor.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -57,7 +57,7 @@ template <typename DeviceContext, typename T>
class
ConcatGradFunctor
{
public:
void
operator
()(
const
DeviceContext
&
context
,
const
framework
::
Tensor
&
input
,
const
std
::
vector
<
const
framework
::
Tensor
*>&
ref_inputs
,
const
std
::
vector
<
const
framework
::
LoD
Tensor
*>&
ref_inputs
,
const
int
axis
,
std
::
vector
<
framework
::
Tensor
*>*
outputs
);
};
...
...
paddle/fluid/operators/mul_op.h
浏览文件 @
17fcc4f5
...
...
@@ -62,23 +62,31 @@ class MulGradKernel : public framework::OpKernel<T> {
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
int
x_num_col_dims
=
ctx
.
template
Attr
<
int
>(
"x_num_col_dims"
);
int
y_num_col_dims
=
ctx
.
template
Attr
<
int
>(
"y_num_col_dims"
);
const
Tensor
*
x
=
ctx
.
Input
<
Tensor
>
(
"X"
);
const
Tensor
*
y
=
ctx
.
Input
<
Tensor
>
(
"Y"
);
const
Tensor
x_matrix
=
x
->
dims
().
size
()
>
2
?
framework
::
ReshapeToMatrix
(
*
x
,
x_num_col_dims
)
:
*
x
;
const
Tensor
y_matrix
=
y
->
dims
().
size
()
>
2
?
framework
::
ReshapeToMatrix
(
*
y
,
y_num_col_dims
)
:
*
y
;
const
Tensor
*
dout
=
ctx
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
x
=
ctx
.
Input
<
framework
::
LoD
Tensor
>
(
"X"
);
auto
*
y
=
ctx
.
Input
<
framework
::
LoD
Tensor
>
(
"Y"
);
auto
x_matrix
=
x
->
dims
().
size
()
>
2
?
framework
::
ReshapeToMatrix
(
*
x
,
x_num_col_dims
)
:
static_cast
<
const
Tensor
&>
(
*
x
)
;
auto
y_matrix
=
y
->
dims
().
size
()
>
2
?
framework
::
ReshapeToMatrix
(
*
y
,
y_num_col_dims
)
:
static_cast
<
const
Tensor
&>
(
*
y
)
;
auto
*
dout
=
ctx
.
Input
<
framework
::
LoD
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
Tensor
dout_mat
;
dout_mat
.
ShareDataWith
(
*
dout
);
dout_mat
.
Resize
({
framework
::
flatten_to_2d
(
x
->
dims
(),
x_num_col_dims
)[
0
],
framework
::
flatten_to_2d
(
y
->
dims
(),
y_num_col_dims
)[
1
]});
Tensor
*
dx
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
Tensor
*
dy
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"Y"
));
auto
*
dx
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"X"
));
auto
*
dy
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"Y"
));
if
(
dx
!=
nullptr
)
{
dx
->
set_lod
(
x
->
lod
());
}
if
(
dy
!=
nullptr
)
{
dy
->
set_lod
(
y
->
lod
());
}
auto
&
dev_ctx
=
ctx
.
template
device_context
<
DeviceContext
>();
auto
blas
=
math
::
GetBlas
<
DeviceContext
,
T
>
(
dev_ctx
);
if
(
dx
)
{
...
...
paddle/fluid/operators/sequence_softmax_cudnn_op.cu.cc
浏览文件 @
17fcc4f5
...
...
@@ -68,7 +68,9 @@ class SequenceSoftmaxGradCUDNNKernel : public framework::OpKernel<T> {
auto
*
out_grad
=
ctx
.
Input
<
LoDTensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
x
=
ctx
.
Input
<
LoDTensor
>
(
"X"
);
auto
*
x_grad
=
ctx
.
Output
<
LoDTensor
>
(
framework
::
GradVarName
(
"X"
));
if
(
x_grad
)
{
x_grad
->
set_lod
(
x
->
lod
());
}
auto
lod
=
x
->
lod
();
const
size_t
level
=
lod
.
size
()
-
1
;
...
...
paddle/fluid/operators/sequence_softmax_op.h
浏览文件 @
17fcc4f5
...
...
@@ -66,6 +66,9 @@ class SequenceSoftmaxGradKernel : public framework::OpKernel<T> {
auto
*
out_grad
=
ctx
.
Input
<
LoDTensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
x
=
ctx
.
Input
<
LoDTensor
>
(
"X"
);
auto
*
x_grad
=
ctx
.
Output
<
LoDTensor
>
(
framework
::
GradVarName
(
"X"
));
if
(
x_grad
)
{
x_grad
->
set_lod
(
x
->
lod
());
}
auto
lod
=
x
->
lod
();
const
size_t
level
=
lod
.
size
()
-
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录