Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b65709e4
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b65709e4
编写于
9月 19, 2017
作者:
D
dangqingqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Share LoD between input and output of each opeators.
上级
f86c1ccd
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
87 addition
and
27 deletion
+87
-27
paddle/framework/operator.h
paddle/framework/operator.h
+8
-0
paddle/operators/accuracy_op.cc
paddle/operators/accuracy_op.cc
+6
-1
paddle/operators/cos_sim_op.cc
paddle/operators/cos_sim_op.cc
+7
-3
paddle/operators/elementwise_mul_op.cc
paddle/operators/elementwise_mul_op.cc
+5
-0
paddle/operators/fc_op.cc
paddle/operators/fc_op.cc
+4
-0
paddle/operators/fill_zeros_like_op.cc
paddle/operators/fill_zeros_like_op.cc
+10
-11
paddle/operators/fill_zeros_like_op.h
paddle/operators/fill_zeros_like_op.h
+1
-1
paddle/operators/lookup_table_op.cc
paddle/operators/lookup_table_op.cc
+8
-3
paddle/operators/mean_op.cc
paddle/operators/mean_op.cc
+2
-1
paddle/operators/minus_op.cc
paddle/operators/minus_op.cc
+7
-1
paddle/operators/mul_op.cc
paddle/operators/mul_op.cc
+8
-2
paddle/operators/onehot_cross_entropy_op.cc
paddle/operators/onehot_cross_entropy_op.cc
+3
-0
paddle/operators/prelu_op.cc
paddle/operators/prelu_op.cc
+3
-0
paddle/operators/rowwise_add_op.cc
paddle/operators/rowwise_add_op.cc
+1
-0
paddle/operators/scale_op.cc
paddle/operators/scale_op.cc
+1
-0
paddle/operators/sigmoid_op.cc
paddle/operators/sigmoid_op.cc
+1
-0
paddle/operators/squared_l2_distance_op.cc
paddle/operators/squared_l2_distance_op.cc
+4
-0
paddle/operators/sum_op.cc
paddle/operators/sum_op.cc
+6
-2
python/paddle/v2/framework/tests/test_fill_zeros_like_op.py
python/paddle/v2/framework/tests/test_fill_zeros_like_op.py
+2
-2
未找到文件。
paddle/framework/operator.h
浏览文件 @
b65709e4
...
...
@@ -336,6 +336,14 @@ class InferShapeContext {
return
&
var
->
Get
<
Tensor
>
();
}
void
ShareLoD
(
const
std
::
string
&
in
,
const
std
::
string
&
out
)
const
{
PADDLE_ENFORCE
(
InputVar
(
in
)
->
IsType
<
LoDTensor
>
(),
"The Input(%s) must be LoDTensor."
,
in
);
PADDLE_ENFORCE
(
OutputVar
(
out
)
->
IsType
<
LoDTensor
>
(),
"The Output(%s) must be LoDTensor."
,
out
);
Output
<
LoDTensor
>
(
out
)
->
set_lod
(
Input
<
LoDTensor
>
(
in
)
->
lod
());
}
private:
const
OperatorBase
&
op_
;
const
Scope
&
scope_
;
...
...
paddle/operators/accuracy_op.cc
浏览文件 @
b65709e4
...
...
@@ -40,6 +40,7 @@ class AccuracyOp : public framework::OperatorWithKernel {
"inference size must be the same as label size"
);
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Accuracy"
)
->
Resize
({
1
});
ctx
.
ShareLoD
(
"Inference"
,
"Accuracy"
);
}
};
...
...
@@ -58,7 +59,11 @@ class AccuracyOpMaker : public framework::OpProtoAndCheckerMaker {
R
"DOC(Accuracy. It will print accuracy rate for classification.
The accuracy is:
.. math::
accuracy = \\frac{NumOfCorrectPredicts}{NumOfAllSamples})DOC"
);
accuracy =
\\
frac{NumOfCorrectPredicts}{NumOfAllSamples})
Both the input `Inference` and `Label` can carry the LoD (Level of Details)
information, or not. But the output only shares the LoD with input `Inference`.
DOC"
);
}
};
...
...
paddle/operators/cos_sim_op.cc
浏览文件 @
b65709e4
...
...
@@ -57,6 +57,7 @@ class CosSimOp : public framework::OperatorWithKernel {
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
)
->
Resize
({
x_dims
[
0
],
1
});
ctx
.
Output
<
framework
::
LoDTensor
>
(
"XNorm"
)
->
Resize
({
x_dims
[
0
],
1
});
ctx
.
Output
<
framework
::
LoDTensor
>
(
"YNorm"
)
->
Resize
({
y_dims
[
0
],
1
});
ctx
.
ShareLoD
(
"X"
,
"Out"
);
}
};
...
...
@@ -81,10 +82,13 @@ Cosine Similarity Operator.
The equation is: Out = X^T * Y / (sqrt(X^T * X) * sqrt(Y^T * Y)).
Input(X) and Input(Y)
must have the same shape, except that the 1st dimension
of
Input(Y) could be just 1 (different from Input(X)
), which will be
broadcasted to match the shape of
Input(X)
before computing their cosine
The input `X` and `Y`
must have the same shape, except that the 1st dimension
of
input `Y` could be just 1 (different from input `X`
), which will be
broadcasted to match the shape of
input `X`
before computing their cosine
similarity.
Both the input `X` and `Y` can carry the LoD (Level of Details) information,
or not. But the output only shares the LoD with input `X`.
)DOC"
);
}
};
...
...
paddle/operators/elementwise_mul_op.cc
浏览文件 @
b65709e4
...
...
@@ -38,6 +38,7 @@ class ElementWiseMulOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_GE
(
x_dim
.
size
(),
y_dim
.
size
(),
"Rank of first input must >= rank of second input."
)
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
)
->
Resize
(
x_dim
);
ctx
.
ShareLoD
(
"X"
,
"Out"
);
}
};
...
...
@@ -63,11 +64,15 @@ Limited elementwise multiple operator.The equation is: Out = X ⊙ Y.
2. Y's shape is a subset of X.
Y will be broadcasted to match the shape of X and axis should be dimension index Y in X.
example:
shape(X) = (2, 3, 4, 5), shape(Y) = (,)
shape(X) = (2, 3, 4, 5), shape(Y) = (5,)
shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5)
shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1
shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0
Both the input X and Y can carry the LoD (Level of Details) information,
or not. But the output only shares the LoD with input X.
)DOC"
);
}
};
...
...
paddle/operators/fc_op.cc
浏览文件 @
b65709e4
...
...
@@ -186,6 +186,10 @@ W_i is a 2-D matrix of size (K x N), where N means the number of neurons
in the fully connected layer. B is a 1-D vector of size N.
Thus, the output Out is a 2-D matrix of size (M x N).
Activation type can be set to `identity` (default), `sigmoid` or `softmax`.
All the inputs can carry the LoD (Level of Details) information,
or not. But the output only shares the LoD with first input (`X[0]`).
)DOC"
);
)
DOC
");
}
};
...
...
paddle/operators/fill_zeros_like_op.cc
浏览文件 @
b65709e4
...
...
@@ -23,15 +23,14 @@ class FillZerosLikeOp : public framework::OperatorWithKernel {
protected:
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"Src"
),
"Input(Src) of FillZerosLikeOp should not be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
OutputVar
(
"Dst"
),
"Output(Dst) of FillZerosLikeOp should not be null."
);
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Dst"
)
->
Resize
(
ctx
.
Input
<
framework
::
Tensor
>
(
"Src"
)
->
dims
());
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
InputVar
(
"X"
),
"Input(X) of FillZerosLikeOp should not be null."
);
PADDLE_ENFORCE_NOT_NULL
(
ctx
.
OutputVar
(
"Y"
),
"Output(Y) of FillZerosLikeOp should not be null."
);
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Y"
)
->
Resize
(
ctx
.
Input
<
framework
::
Tensor
>
(
"X"
)
->
dims
());
ctx
.
ShareLoD
(
"X"
,
"Y"
);
}
};
...
...
@@ -40,8 +39,8 @@ class FillZerosLikeOpMaker : public framework::OpProtoAndCheckerMaker {
FillZerosLikeOpMaker
(
framework
::
OpProto
*
proto
,
framework
::
OpAttrChecker
*
op_checker
)
:
framework
::
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"
Src
"
,
"The input of fill-zeros-like op."
);
AddOutput
(
"
Dst
"
,
"The varibale will be filled up with zeros."
);
AddInput
(
"
X
"
,
"The input of fill-zeros-like op."
);
AddOutput
(
"
Y
"
,
"The varibale will be filled up with zeros."
);
AddComment
(
R"DOC(
Fill up a vriable with zeros.
...
...
paddle/operators/fill_zeros_like_op.h
浏览文件 @
b65709e4
...
...
@@ -23,7 +23,7 @@ template <typename Place, typename T>
class
FillZerosLikeKernel
:
public
framework
::
OpKernel
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
*
output
=
context
.
Output
<
framework
::
Tensor
>
(
"
Dst
"
);
auto
*
output
=
context
.
Output
<
framework
::
Tensor
>
(
"
Y
"
);
output
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
t
=
framework
::
EigenVector
<
T
>::
Flatten
(
*
output
);
t
.
device
(
context
.
GetEigenDevice
<
Place
>
())
=
t
.
constant
(
static_cast
<
T
>
(
0
));
...
...
paddle/operators/lookup_table_op.cc
浏览文件 @
b65709e4
...
...
@@ -35,6 +35,7 @@ class LookupTableOp : public framework::OperatorWithKernel {
auto
output_t
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
);
output_t
->
Resize
({
ids_t
->
dims
()[
0
],
table_t
->
dims
()[
1
]});
ctx
.
ShareLoD
(
"Ids"
,
"Out"
);
}
};
...
...
@@ -50,9 +51,13 @@ class LookupTableOpMaker : public framework::OpProtoAndCheckerMaker {
"An input with type int32 or int64"
"contains the ids to be looked up in W."
);
AddOutput
(
"Out"
,
"The lookup results, which have the same type with W."
);
AddComment
(
"This operator is used to perform lookups on the parameter W,"
"then concatenated into a dense tensor."
);
AddComment
(
R"DOC(
This operator is used to perform lookups on the parameter W,
then concatenated into a dense tensor.
The input `Ids` can carry the LoD (Level of Details) information,
or not. And the output only shares the LoD with input `Ids`.
)DOC"
);
}
};
...
...
paddle/operators/mean_op.cc
浏览文件 @
b65709e4
...
...
@@ -37,7 +37,8 @@ class MeanOpMaker : public framework::OpProtoAndCheckerMaker {
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
"The input of mean op"
);
AddOutput
(
"Out"
,
"The output of mean op"
).
NotInGradient
();
AddComment
(
"Mean Operator"
);
AddComment
(
R"DOC( Mean Operator
)DOC"
);
}
};
...
...
paddle/operators/minus_op.cc
浏览文件 @
b65709e4
...
...
@@ -41,6 +41,7 @@ class MinusOp : public framework::OperatorWithKernel {
left_tensor
->
numel
(),
right_tensor
->
numel
(),
"Minus operator must take two tensor with same num of elements"
);
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
)
->
Resize
(
left_tensor
->
dims
());
ctx
.
ShareLoD
(
"X"
,
"Out"
);
}
};
...
...
@@ -54,7 +55,12 @@ class MinusOpMaker : public framework::OpProtoAndCheckerMaker {
AddComment
(
R"DOC(Minus Operator
Equation: Out = X - Y
Equation:
Out = X - Y
Both the input `X` and `Y` can carry the LoD (Level of Details) information,
or not. But the output only shares the LoD with input `X`.
)DOC"
);
}
};
...
...
paddle/operators/mul_op.cc
浏览文件 @
b65709e4
...
...
@@ -55,6 +55,7 @@ class MulOp : public framework::OperatorWithKernel {
"First matrix's width must be equal with second matrix's height."
);
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
)
->
Resize
(
{
x_mat_dims
[
0
],
y_mat_dims
[
1
]});
ctx
.
ShareLoD
(
"X"
,
"Out"
);
}
};
...
...
@@ -83,9 +84,14 @@ class MulOpMaker : public framework::OpProtoAndCheckerMaker {
.
SetDefault
(
1
)
.
EqualGreaterThan
(
1
);
AddComment
(
R"DOC(
Two Element Mul Operator
.
Mul operator is used to perform matrix multiplication for input X and Y
.
The equation is: Out = X * Y
The equation is:
Out = X * Y
Both the input `X` and `Y` can carry the LoD (Level of Details) information,
or not. But the output only shares the LoD with input `X`.
)DOC"
);
}
};
...
...
paddle/operators/onehot_cross_entropy_op.cc
浏览文件 @
b65709e4
...
...
@@ -40,6 +40,7 @@ class OnehotCrossEntropyOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_EQ
(
label
->
dims
().
size
(),
1
,
"label's dimension must be 1."
);
PADDLE_ENFORCE_EQ
(
X
->
dims
()[
0
],
label
->
dims
()[
0
]);
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Y"
)
->
Resize
({
X
->
dims
()[
0
],
1
});
ctx
.
ShareLoD
(
"X"
,
"Y"
);
}
};
...
...
@@ -69,6 +70,8 @@ OnehotCrossEntropy Operator.
Y[i] = -log(X[i][j])
Both the input `X` and `Label` can carry the LoD (Level of Details) information,
or not. But the output only shares the LoD with input `X`.
)DOC"
);
}
};
...
...
paddle/operators/prelu_op.cc
浏览文件 @
b65709e4
...
...
@@ -38,6 +38,7 @@ class PReluOp : public framework::OperatorWithKernel {
"Output(Out) should not be null"
);
auto
*
out
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
);
out
->
Resize
(
in
->
dims
());
ctx
.
ShareLoD
(
"X"
,
"Out"
);
}
};
...
...
@@ -55,6 +56,8 @@ The equation is:
f(x) = alpha * x , for x < 0
f(x) = x , for x >= 0
The input `X` can carry the LoD (Level of Details) information,
or not. And the output shares the LoD with input `X`.
)DOC"
);
}
};
...
...
paddle/operators/rowwise_add_op.cc
浏览文件 @
b65709e4
...
...
@@ -45,6 +45,7 @@ class RowwiseAddOp : public framework::OperatorWithKernel {
"The width of two operands must be same"
);
PADDLE_ENFORCE_EQ
(
ctx
.
OutputSize
(
"Out"
),
1
,
"The output size must be 1"
);
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
)
->
Resize
(
x_dims
);
ctx
.
ShareLoD
(
"X"
,
"Out"
);
}
};
...
...
paddle/operators/scale_op.cc
浏览文件 @
b65709e4
...
...
@@ -35,6 +35,7 @@ class ScaleOp : public framework::OperatorWithKernel {
auto
*
in
=
ctx
.
Input
<
framework
::
Tensor
>
(
"X"
);
auto
*
out
=
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
);
out
->
Resize
(
in
->
dims
());
ctx
.
ShareLoD
(
"X"
,
"Out"
);
}
};
...
...
paddle/operators/sigmoid_op.cc
浏览文件 @
b65709e4
...
...
@@ -30,6 +30,7 @@ class SigmoidOp : public framework::OperatorWithKernel {
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Y"
)
->
Resize
(
ctx
.
Input
<
Tensor
>
(
"X"
)
->
dims
());
ctx
.
ShareLoD
(
"X"
,
"Y"
);
}
};
...
...
paddle/operators/squared_l2_distance_op.cc
浏览文件 @
b65709e4
...
...
@@ -57,6 +57,7 @@ class SquaredL2DistanceOp : public framework::OperatorWithKernel {
ctx
.
Output
<
framework
::
LoDTensor
>
(
"sub_result"
)
->
Resize
({
x_dims
[
0
],
x
->
numel
()
/
x_dims
[
0
]});
ctx
.
Output
<
framework
::
LoDTensor
>
(
"Out"
)
->
Resize
({
x_dims
[
0
],
1
});
ctx
.
ShareLoD
(
"X"
,
"Out"
);
}
};
...
...
@@ -79,6 +80,9 @@ class SquaredL2DistanceOpMaker : public framework::OpProtoAndCheckerMaker {
input or to 1. If the first dimension of target is 1, SquaredL2DistanceOp
will broadcast target's first dimension to input's first dimension.
You can decide whether calculate the gradient of input and target.
Both the input X and Y can carry the LoD (Level of Details) information,
or not. But the output only shares the LoD with input X.
)DOC"
);
}
};
...
...
paddle/operators/sum_op.cc
浏览文件 @
b65709e4
...
...
@@ -39,6 +39,7 @@ class SumOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE
(
in_dim
==
dim
,
"Input tensors must have same shape"
);
}
out
->
Resize
(
in_dim
);
ctx
.
ShareLoD
(
ctx
.
op
().
Inputs
(
"X"
)[
0
],
"Out"
);
}
};
...
...
@@ -49,8 +50,11 @@ class SumOpMaker : public framework::OpProtoAndCheckerMaker {
AddInput
(
"X"
,
"the input tensors of sum operator."
).
AsDuplicable
();
AddOutput
(
"Out"
,
"the output tensor of sum operator."
);
AddComment
(
R"DOC(
Sum the input tensors.
)DOC"
);
Sum the input tensors.
All the inputs can carry the LoD (Level of Details) information,
or not. But the output only shares the LoD with the first input.
)DOC"
);
}
};
...
...
python/paddle/v2/framework/tests/test_fill_zeros_like_op.py
浏览文件 @
b65709e4
...
...
@@ -6,8 +6,8 @@ from op_test import OpTest
class
TestFillZerosLikeOp
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"fill_zeros_like"
self
.
inputs
=
{
'
Src
'
:
np
.
random
.
random
((
219
,
232
)).
astype
(
"float32"
)}
self
.
outputs
=
{
'
Dst'
:
np
.
zeros_like
(
self
.
inputs
[
"Src
"
])}
self
.
inputs
=
{
'
X
'
:
np
.
random
.
random
((
219
,
232
)).
astype
(
"float32"
)}
self
.
outputs
=
{
'
Y'
:
np
.
zeros_like
(
self
.
inputs
[
"X
"
])}
def
test_check_output
(
self
):
self
.
check_output
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录