Skip to content

Commit c0d2ca5

Browse files
kexinzhaowangkuiyi
authored andcommitted
polish_g_to_l (#5367)
1 parent af760ea commit c0d2ca5

File tree

11 files changed

+187
-135
lines changed

11 files changed

+187
-135
lines changed

paddle/operators/gather_op.cc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,28 @@ class GatherOpMaker : public framework::OpProtoAndCheckerMaker {
6767
: OpProtoAndCheckerMaker(proto, op_checker) {
6868
AddInput("X", "The source input of gather op");
6969
AddInput("Index", "The index input of gather op");
70-
AddOutput("Out", "The output of add op");
70+
AddOutput("Out", "The output of gather op");
7171
AddComment(R"DOC(
72-
Gather Operator by selecting from the first axis,
72+
Gather Operator.
73+
74+
$Out = X[Index]$
75+
76+
Out is obtained by gathering entries of the outer-most dimension
77+
of X indexed by Index and concatenate them together.
78+
79+
Example:
80+
81+
X = [[1, 2],
82+
[3, 4],
83+
[5, 6]]
84+
85+
Index = [[1, 2]]
86+
87+
Then:
88+
89+
Out = [[3, 4],
90+
[5, 6]]
7391
74-
Out = X[Index]
7592
)DOC");
7693
}
7794
};

paddle/operators/gaussian_random_op.cc

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,35 @@ class GaussianRandomOpMaker : public framework::OpProtoAndCheckerMaker {
6868
GaussianRandomOpMaker(framework::OpProto* proto,
6969
framework::OpAttrChecker* op_checker)
7070
: framework::OpProtoAndCheckerMaker(proto, op_checker) {
71-
AddOutput("Out", "output matrix of random op");
72-
AddComment(R"DOC(
73-
GaussianRandom operator.
74-
Use to initialize tensor with gaussian random generator.
75-
)DOC");
71+
AddOutput("Out", "Output matrix of gaussian random op");
7672

77-
AddAttr<std::vector<int>>("shape", "The dimension of random tensor.");
78-
AddAttr<float>("mean", "mean of random tensor.").SetDefault(.0f);
79-
AddAttr<float>("std", "std of random tensor.").SetDefault(1.0f);
73+
AddAttr<std::vector<int>>("shape",
74+
"(vector<int>) "
75+
"The dimension of random tensor.");
76+
AddAttr<float>("mean",
77+
"(float, default 0.0) "
78+
"mean of random tensor.")
79+
.SetDefault(.0f);
80+
AddAttr<float>("std",
81+
"(float, default 1.0) "
82+
"std of random tensor.")
83+
.SetDefault(1.0f);
8084
AddAttr<int>("seed",
85+
"(int, default 0) "
8186
"Random seed of generator."
82-
"0 means use system wide seed")
87+
"0 means use system wide seed.")
8388
.SetDefault(0);
84-
AddAttr<int>("data_type", "output data type")
89+
AddAttr<int>("data_type",
90+
"(int, default 5(FP32)) "
91+
"Output data type.")
8592
.SetDefault(framework::DataType::FP32);
93+
94+
AddComment(R"DOC(
95+
GaussianRandom Operator.
96+
97+
Used to initialize tensors with gaussian random generator.
98+
99+
)DOC");
86100
}
87101
};
88102

paddle/operators/gru_unit_op.cc

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,21 @@ class GRUUnitOpMaker : public framework::OpProtoAndCheckerMaker {
8080
AddInput("HiddenPrev",
8181
"(Tensor) Matrix with shape [batch_size, frame_size] for the "
8282
"states of previous time step.");
83-
AddInput("Weight",
84-
"(Tensor) Weight matrix with shape [frame_size, frame_size * 3]. "
85-
"The elements continuous in memory can be divided into two parts. "
86-
"The first part are weights of the update gate and reset gate "
87-
"with shape [frame_size, frame_size * 2], and the second part are "
88-
"weights of output candidate with shape [frame_size, frame_size]");
89-
AddInput("Bias",
90-
"(Tensor) Bias vector with shape [1, frame_size * 3] concating "
91-
"bias of the update gate, reset gate and output candidate.")
83+
AddInput(
84+
"Weight",
85+
"(Tensor) Weight matrix with shape [frame_size, frame_size * 3]. "
86+
"The elements continuous in memory can be divided into two parts. "
87+
"The first part are weights of the update gate and reset gate "
88+
"with shape [frame_size, frame_size * 2], and the second part are "
89+
"weights of output candidate with shape [frame_size, frame_size].");
90+
AddInput(
91+
"Bias",
92+
"(Tensor) Bias vector with shape [1, frame_size * 3] concatenating "
93+
"bias of the update gate, reset gate and output candidate.")
9294
.AsDispensable();
9395
AddOutput("Gate",
9496
"(Tensor) Matrix with shape [batch_size, frame_size * 3] for the "
95-
"output of update gate, reset gate and output candidate")
97+
"output of update gate, reset gate and output candidate.")
9698
.AsIntermediate();
9799
AddOutput("ResetHiddenPrev",
98100
"(Tensor) Matrix with shape [batch_size, frame_size] for the "
@@ -112,16 +114,19 @@ class GRUUnitOpMaker : public framework::OpProtoAndCheckerMaker {
112114
.SetDefault(sigmoid)
113115
.InEnum({identity, sigmoid, tanh, relu});
114116
AddComment(R"DOC(
115-
GRUUnitOp implements part calculations of the GRU unit as following:
117+
GRUUnit Operator.
116118
117-
\f[
118-
update \ gate: u_t = actGate(xu_t + W_u * hidden_prev + bias_u) \\
119-
reset \ gate: r_t = actGate(xr_t + W_r * hidden_prev + bias_r) \\
120-
output \ candidate: {h}_t = actNode(xc_t + W_c * dot(r_t, hidden_prev) + bias_c) \\
121-
output: h_t = dot((1-u_t), {h}_t) + dot(u_t, hidden_prev)
122-
\f]
119+
This operator implements partial calculations of the GRU unit as follows:
120+
121+
$$
122+
update \ gate: u_t = actGate(xu_t + W_u * hidden_{prev} + bias_u) \\
123+
reset \ gate: r_t = actGate(xr_t + W_r * hidden_{prev} + bias_r) \\
124+
output \ candidate: {h}_t = actNode({xc}_t + W_c * dot(r_t, hidden_{prev}) + bias_c) \\
125+
output: h_t = dot((1-u_t), {h}_t) + dot(u_t, hidden_{prev})
126+
$$
123127
124128
The rest of GRU unit can be completed by using FCOp's output as the input of GRUUnitOp.
129+
125130
)DOC");
126131
}
127132
};

paddle/operators/huber_loss_op.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ class HuberLossOpMaker : public framework::OpProtoAndCheckerMaker {
5959
"The shape is same as Input(X) and will be reused in backward.")
6060
.AsIntermediate();
6161
AddOutput("Out",
62-
"The output tensor with shape [batch_size, 1] which represents "
63-
"the huber loss.");
62+
"The output tensor with shape [batch_size, 1] "
63+
"which represents the huber loss.");
6464
AddAttr<AttrType>("delta", "Hyper parameter in huber loss.");
6565
AddComment(R"DOC(
66+
HuberLoss Operator.
67+
6668
Huber loss is a loss function used in robust regression. We define X as the
6769
input value and Y as the target value. Huber loss can evaluate the fitness of
6870
X to Y. Different from MSE loss, Huber loss is more robust for outliers. The

paddle/operators/increment_op.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ class IncrementOpMaker : public framework::OpProtoAndCheckerMaker {
3939
: OpProtoAndCheckerMaker(proto, op_checker) {
4040
AddInput("X", "(Tensor) The input tensor of increment operator");
4141
AddOutput("Out", "(Tensor) The output tensor of increment operator.");
42-
AddComment(R"DOC(Increment operator
43-
44-
The equation is: Out = X + step
45-
)DOC");
4642
AddAttr<AttrType>("step",
43+
"(float, default 1.0) "
4744
"The step size by which the "
4845
"input tensor will be incremented.")
4946
.SetDefault(1.0);
47+
AddComment(R"DOC(
48+
Increment Operator.
49+
50+
The equation is:
51+
$$Out = X + step$$
52+
53+
)DOC");
5054
}
5155
};
5256

paddle/operators/l1_norm_op.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ L1 Norm Operator.
5757
5858
Computes the L1 norm of a tensor.
5959
60-
Out = sum (abs(X))
60+
$$Out = \sum{|X|}$$
6161
6262
)DOC");
6363
}

paddle/operators/load_op.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,18 @@ class LoadOpProtoMaker : public framework::OpProtoAndCheckerMaker {
115115
LoadOpProtoMaker(framework::OpProto *proto,
116116
framework::OpAttrChecker *op_checker)
117117
: OpProtoAndCheckerMaker(proto, op_checker) {
118-
AddOutput("Out", "The tensor need to be loaded");
119-
AddComment(R"DOC(Load Operator
120-
Load operator will load a tensor variable from disk file.
121-
)DOC");
118+
AddOutput("Out", "(Tensor) The tensor need to be loaded");
122119
AddAttr<std::string>("file_path",
120+
"(string) "
123121
"Variable will be loaded from \"file_path\".")
124122
.AddCustomChecker(
125123
[](const std::string &path) { return !path.empty(); });
124+
AddComment(R"DOC(
125+
Load Operator.
126+
127+
Load operator will load a tensor variable from disk file.
128+
129+
)DOC");
126130
}
127131
};
128132
} // namespace operators

paddle/operators/lookup_table_op.cc

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,27 @@ class LookupTableOpMaker : public framework::OpProtoAndCheckerMaker {
5353
framework::OpAttrChecker* op_checker)
5454
: OpProtoAndCheckerMaker(proto, op_checker) {
5555
AddInput("W",
56-
"An input represents embedding tensors,"
57-
" which is a learnable parameter.");
56+
"An input represents embedding tensors, "
57+
"which is a learnable parameter.");
5858
AddInput("Ids",
59-
"An input with type int32 or int64"
60-
"contains the ids to be looked up in W."
61-
"Ids must be a column vector with rank = 2."
62-
"The 2nd dimension size must be 1");
63-
AddOutput("Out", "The lookup results, which have the same type with W.");
64-
AddAttr<bool>("is_sparse", "Sparse update").SetDefault(false);
59+
"An input with type int32 or int64 "
60+
"contains the ids to be looked up in W. "
61+
"Ids must be a column vector with rank = 2. "
62+
"The 2nd dimension size must be 1.");
63+
AddOutput("Out", "The lookup results, which have the same type as W.");
64+
AddAttr<bool>("is_sparse",
65+
"(boolean, default false) "
66+
"Sparse update")
67+
.SetDefault(false);
6568
AddComment(R"DOC(
69+
Lookup Table Operator.
70+
6671
This operator is used to perform lookups on the parameter W,
6772
then concatenated into a dense tensor.
6873
69-
The input `Ids` can carry the LoD (Level of Details) information,
70-
or not. And the output only shares the LoD with input `Ids`.
74+
The input Ids can carry the LoD (Level of Details) information,
75+
or not. And the output only shares the LoD information with input Ids.
76+
7177
)DOC");
7278
}
7379
};

paddle/operators/lrn_op.cc

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,72 +45,70 @@ class LRNOpMaker : public framework::OpProtoAndCheckerMaker {
4545
public:
4646
LRNOpMaker(framework::OpProto* proto, framework::OpAttrChecker* op_checker)
4747
: OpProtoAndCheckerMaker(proto, op_checker) {
48-
AddInput("X", R"DOC(
49-
(Tensor) The input of LRN operator. It must be a 4D tenor with NCHW format.
50-
)DOC");
51-
48+
AddInput("X",
49+
"(Tensor) The input of LRN operator. "
50+
"It must be a 4D tenor with NCHW format.");
5251
AddOutput("Out",
5352
"(Tensor) The output of LRN operator, which is also the 4D "
5453
"tensor with NCHW format.");
55-
AddOutput("MidOut", R"Doc(
56-
(Tensor)Middle result of lrn op.It's computed in forward process
57-
and also used in backward process.
58-
)Doc");
59-
60-
AddAttr<int>("n", R"DOC(
61-
(int, default 5)n is “adjacent” kernel maps at the same spatial position.
62-
)DOC")
54+
AddOutput("MidOut",
55+
"(Tensor) Middle result of LRN operator. It's computed in "
56+
"forward process and also used in backward process.");
57+
58+
AddAttr<int>("n",
59+
"(int default 5) "
60+
"n is the \"adjacent\" kernel that maps "
61+
"at the same spatial position.")
6362
.SetDefault(5)
6463
.GreaterThan(0);
6564

66-
AddAttr<T>("k", R"DOC(
67-
(float, default 2.0)k is the bias.
68-
)DOC")
65+
AddAttr<T>("k",
66+
"(float, default 2.0) "
67+
"k is the bias.")
6968
.SetDefault(2.0)
7069
.GreaterThan(0.0);
7170

72-
AddAttr<T>("alpha", R"DOC(
73-
(float, default 0.0001)alpha is the scale number.
74-
)DOC")
71+
AddAttr<T>("alpha",
72+
"(float, default 0.0001) "
73+
"alpha is the scale number.")
7574
.SetDefault(0.0001)
7675
.GreaterThan(0.0);
7776

78-
AddAttr<T>("beta", R"DOC(
79-
(float, default 0.75)beta is the power number.
80-
)DOC")
77+
AddAttr<T>("beta",
78+
"(float, default 0.75) "
79+
"beta is the power number.")
8180
.SetDefault(0.75)
8281
.GreaterThan(0.0);
8382

8483
AddComment(R"DOC(
85-
Local Response Normalization.
86-
87-
This Function comes from the paper
88-
"ImageNet Classification with Deep Convolutional Neural Networks".
84+
Local Response Normalization Operator.
8985
90-
The original formula is:
86+
This operator comes from the paper
87+
"ImageNet Classification with Deep Convolutional Neural Networks".
9188
92-
Input(i, x, y)
93-
Output(i, x, y) = ----------------------------------------------
94-
-- upper
95-
(k + alpha * > (Input(j, x, y))^2) ^ (beta)
96-
-- j = lower
89+
The original formula is:
9790
98-
upper is `min(C, c + n/2)`
99-
lower if `max(0, c - n/2)`
91+
$$
92+
Output(i, x, y) = Input(i, x, y) / \left(
93+
k + \alpha \sum\limits^{\min(C, c + n/2)}_{j = \max(0, c - n/2)}
94+
(Input(j, x, y))^2
95+
\right)^{\beta}
96+
$$
10097
101-
Function implementation:
98+
Function implementation:
10299
103-
inputs and outpus is NCHW format, while input.shape.ndims() is equal 4.
104-
And the meaning of each dimension(0-3) is respectively batch size,
105-
feature maps, rows and columns.
100+
Inputs and outpus are in NCHW format, while input.shape.ndims() equals 4.
101+
And dimensions 0 ~ 3 represent batch size, feature maps, rows,
102+
and columns, respectively.
106103
107-
Input and Output in the above formula is for each map(i) of one image, and
108-
Input(i, x, y), Output(i, x, y) represents an element in an image.
104+
Input and Output in the formula above is for each map(i) of one image, and
105+
Input(i, x, y), Output(i, x, y) represents an element in an image.
109106
110-
C is the number of feature maps of one image, and n is a hyper-parameters
111-
is configured when Function is initialized. The sum in the denominator
112-
is the sum of the same position in the neighboring maps.
113-
)DOC");
107+
C is the number of feature maps of one image. n is a hyper-parameter
108+
configured when operator is initialized. The sum in the denominator
109+
is the sum of the same positions in the neighboring maps.
110+
111+
)DOC");
114112
}
115113
};
116114

0 commit comments

Comments
 (0)