Skip to content

Commit 4970414

Browse files
committed
Merge remote-tracking branch 'origin/develop' into doc/api1
2 parents 7ad46ec + 566a940 commit 4970414

32 files changed

+1058
-446
lines changed

doc/v2/dev/contribute_to_paddle_cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ no changes added to commit (use "git add" and/or "git commit -a")
104104
➜ docker run -it -v $(pwd):/paddle paddle:latest-dev bash -c "cd /paddle/build && ctest"
105105
```
106106

107-
关于构建和测试的更多信息,请参见[这篇文档](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/getstarted/build_and_install/docker_install_cn.rst)
107+
关于构建和测试的更多信息,请参见[使用Docker安装运行](https://github.com/PaddlePaddle/Paddle/blob/develop/doc/v2/build_and_install/docker_install_cn.rst)
108108

109109
## 提交(commit)
110110

paddle/fluid/inference/tensorrt/convert/op_converter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class OpConverter {
6464
(*it)(op, scope, test_mode);
6565
}
6666

67-
// convert fluid block to tensorrt network
67+
// Convert a fluid block to tensorrt network, NOTE it just convert operators,
68+
// the INetwork's inputs and outputs should specified in some other modules.
6869
void ConvertBlock(const framework::proto::BlockDesc& block,
6970
const std::unordered_set<std::string>& parameters,
7071
const framework::Scope& scope, TensorRTEngine* engine) {

paddle/fluid/inference/tensorrt/engine.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ class TensorRTEngine : public EngineBase {
5151
nvinfer1::Weights w_;
5252
};
5353

54-
TensorRTEngine(int max_batch, int max_workspace, cudaStream_t* stream,
54+
TensorRTEngine(int max_batch, int max_workspace,
55+
cudaStream_t* stream = nullptr,
5556
nvinfer1::ILogger& logger = NaiveLogger::Global())
5657
: max_batch_(max_batch),
5758
max_workspace_(max_workspace),
58-
stream_(stream),
59+
stream_(stream ? stream : &default_stream_),
5960
logger_(logger) {}
6061

6162
virtual ~TensorRTEngine();
@@ -121,6 +122,8 @@ class TensorRTEngine : public EngineBase {
121122
// the max memory size the engine uses
122123
int max_workspace_;
123124
cudaStream_t* stream_;
125+
// If stream_ is not set from outside, hold its own stream.
126+
cudaStream_t default_stream_;
124127
nvinfer1::ILogger& logger_;
125128

126129
std::vector<Buffer> buffers_;
@@ -165,20 +168,31 @@ class TensorRTEngine : public EngineBase {
165168
*/
166169
class TRT_EngineManager {
167170
public:
168-
TensorRTEngine* Create(int max_batch, int max_workspace,
169-
cudaStream_t* stream) {
170-
engines_.emplace_back(new TensorRTEngine(max_batch, max_workspace, stream));
171-
return engines_.back().get();
171+
bool HasEngine(const std::string& name) const {
172+
return engines_.count(name) != 0;
173+
}
174+
175+
// Get an engine called `name`.
176+
TensorRTEngine* Get(const std::string& name) const {
177+
return engines_.at(name).get();
178+
}
179+
180+
// Create or get an engine called `name`
181+
TensorRTEngine* Create(int max_batch, int max_workspace, cudaStream_t* stream,
182+
const std::string& name) {
183+
auto* p = new TensorRTEngine(max_batch, max_workspace, stream);
184+
engines_[name].reset(p);
185+
return p;
172186
}
173187

174188
void DeleteALl() {
175-
for (auto& ptr : engines_) {
176-
ptr.reset(nullptr);
189+
for (auto& item : engines_) {
190+
item.second.reset(nullptr);
177191
}
178192
}
179193

180194
private:
181-
std::vector<std::unique_ptr<TensorRTEngine>> engines_;
195+
std::unordered_map<std::string, std::unique_ptr<TensorRTEngine>> engines_;
182196
};
183197

184198
} // namespace tensorrt

paddle/fluid/operators/activation_op.cc

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Sigmoid Activation Operator
112112
__attribute__((unused)) constexpr char LogSigmoidDoc[] = R"DOC(
113113
Logsigmoid Activation Operator
114114
115-
$$out = \log \frac{1}{1 + e^{-x}}$$
115+
$$out = \\log \\frac{1}{1 + e^{-x}}$$
116116
117117
)DOC";
118118

@@ -252,15 +252,14 @@ class SoftShrinkOpMaker : public framework::OpProtoAndCheckerMaker {
252252
AddOutput("Out", "Output of Softshrink operator");
253253
AddAttr<float>("lambda", "non-negative offset").SetDefault(0.5f);
254254
AddComment(R"DOC(
255-
Softshrink Activation Operator.
255+
:strong:`Softshrink Activation Operator`
256256
257-
$$
258-
out = \begin{cases}
259-
x - \lambda, \text{if } x > \lambda \\
260-
x + \lambda, \text{if } x < -\lambda \\
261-
0, \text{otherwise}
262-
\end{cases}
263-
$$
257+
.. math::
258+
out = \begin{cases}
259+
x - \lambda, \text{if } x > \lambda \\
260+
x + \lambda, \text{if } x < -\lambda \\
261+
0, \text{otherwise}
262+
\end{cases}
264263
265264
)DOC");
266265
}
@@ -271,18 +270,18 @@ class HardShrinkOpMaker : public framework::OpProtoAndCheckerMaker {
271270
void Make() override {
272271
AddInput("X", "Input of HardShrink operator");
273272
AddOutput("Out", "Output of HardShrink operator");
274-
AddAttr<float>("threshold", "The value of threshold for HardShrink")
273+
AddAttr<float>("threshold",
274+
"The value of threshold for HardShrink. [default: 0.5]")
275275
.SetDefault(0.5f);
276276
AddComment(R"DOC(
277-
HardShrink Activation Operator.
277+
:strong:`HardShrink activation operator`
278278
279-
$$
280-
out = \begin{cases}
281-
x, \text{if } x > \lambda \\
282-
x, \text{if } x < -\lambda \\
283-
0, \text{otherwise}
284-
\end{cases}
285-
$$
279+
.. math::
280+
out = \begin{cases}
281+
x, \text{if } x > \lambda \\
282+
x, \text{if } x < -\lambda \\
283+
0, \text{otherwise}
284+
\end{cases}
286285
287286
)DOC");
288287
}
@@ -394,18 +393,18 @@ class ThresholdedReluOpMaker : public framework::OpProtoAndCheckerMaker {
394393
void Make() override {
395394
AddInput("X", "Input of ThresholdedRelu operator");
396395
AddOutput("Out", "Output of ThresholdedRelu operator");
397-
AddAttr<float>("threshold", "The threshold location of activation")
396+
AddAttr<float>("threshold",
397+
"The threshold location of activation. [default 1.0].")
398398
.SetDefault(1.0f);
399399
AddComment(R"DOC(
400-
ThresholdedRelu Activation Operator.
400+
:strong:`ThresholdedRelu activation operator`
401401
402-
$$
403-
out = \begin{cases}
404-
x, \text{if } x > threshold \\
405-
0, \text{otherwise}
406-
\end{cases}
407-
$$
402+
.. math::
408403
404+
out = \begin{cases}
405+
x, \text{if } x > threshold \\
406+
0, \text{otherwise}
407+
\end{cases}
409408
)DOC");
410409
}
411410
};

paddle/fluid/operators/compare_op.cc

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,26 @@ class CompareOpProtoMaker : public framework::OpProtoAndCheckerMaker {
2323
public:
2424
void Make() override {
2525
OpComment comment;
26-
AddInput("X",
27-
string::Sprintf("(LoDTensor) the left hand operand of %s operator",
28-
comment.type));
29-
AddInput("Y", string::Sprintf(
30-
"(LoDTensor) the right hand operand of %s operator",
31-
comment.type));
26+
AddInput("X", string::Sprintf("the left hand operand of %s operator",
27+
comment.type));
28+
AddInput("Y", string::Sprintf("the right hand operand of %s operator",
29+
comment.type));
3230
AddAttr<bool>("force_cpu",
33-
"(bool, default false) Force fill output variable to cpu "
31+
"Force fill output variable to cpu "
3432
"memory. Otherwise, fill output variable to the running "
35-
"device")
36-
.SetDefault(false);
37-
AddOutput("Out", string::Sprintf(
38-
"(LoDTensor) n-dim bool tensor. Each element is %s",
39-
comment.equation));
40-
AddComment(string::Sprintf(R"DOC(%s Operator
41-
33+
"device [default true].")
34+
.SetDefault(true);
35+
AddOutput("Out", string::Sprintf("n-dim bool tensor. Each element is %s",
36+
comment.equation));
37+
AddComment(string::Sprintf(R"DOC(
4238
It operates element-wise on X and Y, and returns the Out. Each of them is a
4339
N-dim tensor. X and Y could be any type. The each element of the Out tensor is
44-
calculated by %s
40+
calculated by $%s$
4541
)DOC",
46-
comment.type, comment.equation));
47-
AddAttr<int>("axis",
48-
"(int, default -1). The start dimension index "
49-
"for broadcasting Y onto X.")
42+
comment.equation));
43+
AddAttr<int>(
44+
"axis",
45+
"The start dimension index for broadcasting Y onto X. [default -1]")
5046
.SetDefault(-1)
5147
.EqualGreaterThan(-1);
5248
}

paddle/fluid/operators/cumsum_op.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ class CumOp : public framework::OperatorWithKernel {
3030
class CumsumOpMaker : public framework::OpProtoAndCheckerMaker {
3131
public:
3232
void Make() override {
33-
AddInput("X", "Input of Cumsum operator");
34-
AddOutput("Out", "Output of Cumsum operator");
33+
AddInput("X", "Input of cumsum operator");
34+
AddOutput("Out", "Output of cumsum operator");
3535
AddAttr<int>("axis",
36-
"(int, default -1). The dimenstion to accumulate along. "
37-
"-1 means the last dimenstion")
36+
"The dimenstion to accumulate along. -1 means the last "
37+
"dimenstion [default -1].")
3838
.SetDefault(-1)
3939
.EqualGreaterThan(-1);
4040
AddAttr<bool>("exclusive",
41-
"bool, default false). Whether to perform exclusive cumsum")
41+
"Whether to perform exclusive cumsum. [default false].")
4242
.SetDefault(false);
4343
AddAttr<bool>("reverse",
44-
"bool, default false). If true, the cumsum is performed in "
45-
"the reversed direction")
44+
"If true, the cumsum is performed in the reversed direction. "
45+
"[default false].")
4646
.SetDefault(false);
4747
AddComment(R"DOC(
4848
The cumulative sum of the elements along a given axis.

paddle/fluid/operators/detection/box_coder_op.cc

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,36 @@ class BoxCoderOpMaker : public framework::OpProtoAndCheckerMaker {
106106
"and M represents the number of deocded boxes.");
107107

108108
AddComment(R"DOC(
109-
Bounding Box Coder Operator.
109+
110+
Bounding Box Coder.
111+
110112
Encode/Decode the target bounding box with the priorbox information.
113+
111114
The Encoding schema described below:
112-
ox = (tx - px) / pw / pxv
113-
oy = (ty - py) / ph / pyv
114-
ow = log(abs(tw / pw)) / pwv
115-
oh = log(abs(th / ph)) / phv
115+
116+
ox = (tx - px) / pw / pxv
117+
118+
oy = (ty - py) / ph / pyv
119+
120+
ow = log(abs(tw / pw)) / pwv
121+
122+
oh = log(abs(th / ph)) / phv
123+
116124
The Decoding schema described below:
117-
ox = (pw * pxv * tx * + px) - tw / 2
118-
oy = (ph * pyv * ty * + py) - th / 2
119-
ow = exp(pwv * tw) * pw + tw / 2
120-
oh = exp(phv * th) * ph + th / 2
121-
where tx, ty, tw, th denote the target box's center coordinates, width and
122-
height respectively. Similarly, px, py, pw, ph denote the priorbox's(anchor)
123-
center coordinates, width and height. pxv, pyv, pwv, phv denote the variance
124-
of the priorbox and ox, oy, ow, oh denote the encoded/decoded coordinates,
125-
width and height.
125+
126+
ox = (pw * pxv * tx * + px) - tw / 2
127+
128+
oy = (ph * pyv * ty * + py) - th / 2
129+
130+
ow = exp(pwv * tw) * pw + tw / 2
131+
132+
oh = exp(phv * th) * ph + th / 2
133+
134+
where `tx`, `ty`, `tw`, `th` denote the target box's center coordinates, width
135+
and height respectively. Similarly, `px`, `py`, `pw`, `ph` denote the
136+
priorbox's (anchor) center coordinates, width and height. `pxv`, `pyv`, `pwv`,
137+
`phv` denote the variance of the priorbox and `ox`, `oy`, `ow`, `oh` denote the
138+
encoded/decoded coordinates, width and height.
126139
)DOC");
127140
}
128141
};

paddle/fluid/operators/gaussian_random_batch_size_like_op.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ class GaussianRandomBatchSizeLikeOpMaker : public BatchSizeLikeOpMaker {
3636
void Apply() override {
3737
AddAttr<float>("mean",
3838
"(float, default 0.0) "
39-
"mean of random tensor.")
39+
"The mean (or center) of the gaussian distribution.")
4040
.SetDefault(.0f);
4141
AddAttr<float>("std",
4242
"(float, default 1.0) "
43-
"std of random tensor.")
43+
"The standard deviation (std, or spread) of the "
44+
"gaussian distribution.")
4445
.SetDefault(1.0f);
4546
AddAttr<int>("seed",
4647
"(int, default 0) "
@@ -55,9 +56,11 @@ class GaussianRandomBatchSizeLikeOpMaker : public BatchSizeLikeOpMaker {
5556
.SetDefault(framework::proto::VarType::FP32);
5657

5758
AddComment(R"DOC(
58-
GaussianRandom Operator.
5959
6060
Used to initialize tensors with gaussian random generator.
61+
The defalut mean of the distribution is 0. and defalut standard
62+
deviation (std) of the distribution is 1.. Uers can set mean and std
63+
by input arguments.
6164
)DOC");
6265
}
6366
};

paddle/fluid/operators/layer_norm_op.cc

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,47 +62,48 @@ class LayerNormOp : public framework::OperatorWithKernel {
6262
class LayerNormOpMaker : public framework::OpProtoAndCheckerMaker {
6363
public:
6464
void Make() override {
65-
AddInput("X", "(LoDTensor) The input tensor.");
65+
AddInput("X", "The input tensor.");
6666
AddInput("Scale",
67-
"(Tensor, optional) Scale is a 1-dimensional tensor of size "
67+
"(optional) Scale is a 1-dimensional tensor of size "
6868
"H(`begin_norm_axis` splits the tensor(`X`) to a matrix [N,H])."
6969
"It is applied to the output.")
7070
.AsDispensable();
7171
AddInput("Bias",
72-
"(Tensor, optional) Bias is a 1-dimensional tensor of size "
72+
"(optional) Bias is a 1-dimensional tensor of size "
7373
"H(`begin_norm_axis` splits the tensor(`X`) to a matrix [N,H])."
7474
"It is applied to the output.")
7575
.AsDispensable();
76-
AddOutput("Y", "(LoDTensor) Result after normalization.");
77-
AddOutput("Mean", "(Tensor) Mean of the current mini batch.")
78-
.AsIntermediate();
79-
AddOutput("Variance", "(Tensor) Variance of the current mini batch.")
76+
AddOutput("Y", "Result after normalization.");
77+
AddOutput("Mean", "Mean of the current mini batch.").AsIntermediate();
78+
AddOutput("Variance", "Variance of the current mini batch.")
8079
.AsIntermediate();
8180

8281
AddAttr<float>("epsilon",
83-
"(float, default 1e-5) Constant for "
84-
"numerical stability")
82+
"Constant for numerical stability [default 1e-5].")
8583
.SetDefault(1e-5)
8684
.AddCustomChecker([](const float &epsilon) {
8785
PADDLE_ENFORCE(epsilon >= 0.0f && epsilon <= 0.001f,
8886
"'epsilon' should be between 0.0 and 0.001.");
8987
});
9088
AddAttr<int>("begin_norm_axis",
91-
"(int default:1), the "
92-
"axis of `begin_norm_axis ... Rank(X) - 1` will be "
89+
"the axis of `begin_norm_axis ... Rank(X) - 1` will be "
9390
"normalized. `begin_norm_axis` splits the tensor(`X`) to a "
94-
"matrix [N,H].")
91+
"matrix [N,H]. [default 1].")
9592
.SetDefault(1)
9693
.AddCustomChecker([](const int &begin_norm_axis) {
9794
PADDLE_ENFORCE_GT(begin_norm_axis, 0,
9895
"'begin_norm_axis' should be greater than zero.");
9996
});
10097

10198
AddComment(R"DOC(
102-
Layer Normalization.
103-
Layer Norm has been implemented as discussed in the paper:
104-
https://arxiv.org/abs/1607.06450
105-
...
99+
Assume feature vectors exist on dimensions
100+
:attr:`begin_norm_axis ... rank(input)` and calculate the moment statistics
101+
along these dimensions for each feature vector :math:`a` with size
102+
:math:`H`, then normalize each feature vector using the corresponding
103+
statistics. After that, apply learnable gain and bias on the normalized
104+
tensor to scale and shift if :attr:`scale` and :attr:`shift` are set.
105+
106+
Refer to `Layer Normalization <https://arxiv.org/pdf/1607.06450v1.pdf>`_
106107
)DOC");
107108
}
108109
};

paddle/fluid/operators/listen_and_serv_op.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ class ListenAndServOpMaker : public framework::OpProtoAndCheckerMaker {
348348
};
349349

350350
void SignalHandler::StopAndExit(int signal_num) {
351-
VLOG(3) << "Catch interrupt signal: " << signal_num << ", program will exit";
351+
// Do not use VLOG here for the device for printing maybe already released.
352+
// exit will release interal allocated resoureces.
352353
exit(0);
353354
}
354355

0 commit comments

Comments
 (0)