Skip to content

Commit 2aaa75e

Browse files
committed
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into feature/refine_gather_reduce
2 parents 690cd1f + 0032b4a commit 2aaa75e

File tree

11 files changed

+99
-15
lines changed

11 files changed

+99
-15
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ RUN localedef -i en_US -f UTF-8 en_US.UTF-8
5757
# specify sphinx version as 1.5.6 and remove -U option for [pip install -U
5858
# sphinx-rtd-theme] since -U option will cause sphinx being updated to newest
5959
# version(1.7.1 for now), which causes building documentation failed.
60-
RUN pip install --upgrade pip && \
60+
RUN pip install --upgrade pip==9.0.3 && \
6161
pip install -U wheel && \
6262
pip install -U docopt PyYAML sphinx==1.5.6 && \
6363
pip install sphinx-rtd-theme==0.1.9 recommonmark

cmake/external/grpc.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ExternalProject_Add(
3333
extern_grpc
3434
DEPENDS protobuf zlib
3535
GIT_REPOSITORY "https://github.com/grpc/grpc.git"
36-
GIT_TAG "v1.11.x"
36+
GIT_TAG "v1.10.x"
3737
PREFIX ${GRPC_SOURCES_DIR}
3838
UPDATE_COMMAND ""
3939
CONFIGURE_COMMAND ""

doc/fluid/api/layers.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ multiplex
473473
.. autofunction:: paddle.fluid.layers.multiplex
474474
:noindex:
475475

476+
label_smooth
477+
------------
478+
479+
.. autofunction:: paddle.fluid.layers.label_smooth
480+
:noindex:
481+
476482
ops
477483
===
478484

doc/fluid/dev/index_cn.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
.. toctree::
55
:maxdepth: 1
66

7+
api_doc_std_cn.md
78
new_op_cn.md
89
new_op_kernel.md
910
use_eigen_cn.md

doc/fluid/dev/index_en.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Development
44
.. toctree::
55
:maxdepth: 1
66

7+
api_doc_std_en.md
78
new_op_en.md
89
new_op_kernel.md
910
use_eigen_en.md

paddle/fluid/framework/details/multi_devices_graph_builder.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ MultiDevSSAGraphBuilder::MultiDevSSAGraphBuilder(
5555
}
5656
}
5757

58-
void MultiDevSSAGraphBuilder::CreateOpHandleIOs(SSAGraph *result, OpDesc *op,
58+
void MultiDevSSAGraphBuilder::CreateOpHandleIOs(SSAGraph *result,
59+
const OpDesc &op,
5960
const platform::Place &p,
6061
const size_t &i) const {
6162
auto *op_handle = result->ops_.back().get();
62-
op_handle->dev_ctxes_[p] = const_cast<platform::DeviceContext *>(
63-
platform::DeviceContextPool::Instance().Get(p));
63+
op_handle->dev_ctxes_[p] = platform::DeviceContextPool::Instance().Get(p);
6464

65-
auto var_names = op->InputArgumentNames();
65+
auto var_names = op.InputArgumentNames();
6666

6767
for (auto &each_var_name : var_names) {
6868
VarHandle *var = CreateOrGetLatestVarHandle(result, each_var_name, p, i);
6969
op_handle->AddInput(var);
7070
}
7171

72-
var_names = op->OutputArgumentNames();
72+
var_names = op.OutputArgumentNames();
7373

7474
for (auto &each_var_name : var_names) {
7575
CreateOpOutput(result, op_handle, each_var_name, p, i);
@@ -107,7 +107,7 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
107107
result.ops_.emplace_back(new SendOpHandle(*op, s, p));
108108
// Create inputs for output on original place and no ssa output
109109
// is created for send op.
110-
CreateOpHandleIOs(&result, op, p, 0);
110+
CreateOpHandleIOs(&result, *op, p, 0);
111111
continue;
112112
}
113113

@@ -117,7 +117,7 @@ std::unique_ptr<SSAGraph> MultiDevSSAGraphBuilder::Build(
117117

118118
result.ops_.emplace_back(new ComputationOpHandle(*op, s, p));
119119
auto *op_handle = result.ops_.back().get();
120-
CreateOpHandleIOs(&result, op, p, i);
120+
CreateOpHandleIOs(&result, *op, p, i);
121121

122122
auto var_names = op->OutputArgumentNames();
123123

paddle/fluid/framework/details/multi_devices_graph_builder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class MultiDevSSAGraphBuilder : public SSAGraphBuilder {
4545
std::unique_ptr<SSAGraph> Build(const ProgramDesc &program) const override;
4646

4747
private:
48-
void CreateOpHandleIOs(SSAGraph *result, OpDesc *op, const platform::Place &p,
49-
const size_t &i) const;
48+
void CreateOpHandleIOs(SSAGraph *result, const OpDesc &op,
49+
const platform::Place &p, const size_t &i) const;
5050

5151
private:
5252
std::string loss_var_name_;

paddle/fluid/framework/program_desc_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ TEST(ProgramDesc, copy_ctor) {
6666

6767
for (size_t i = 0; i < global_block->OpSize(); ++i) {
6868
auto op_origin = global_block->Op(i);
69-
auto op_copy = global_block->Op(i);
69+
auto op_copy = global_block_copy->Op(i);
7070

7171
ASSERT_EQ(op_origin->Type(), op_copy->Type());
7272
ASSERT_EQ(op_origin->Inputs(), op_copy->Inputs());
@@ -131,7 +131,7 @@ TEST(ProgramDescBind, serialize_and_deserialize) {
131131

132132
for (size_t i = 0; i < global_block->OpSize(); ++i) {
133133
auto op_origin = global_block->Op(i);
134-
auto op_restored = global_block->Op(i);
134+
auto op_restored = global_block_restored->Op(i);
135135

136136
ASSERT_EQ(op_origin->Type(), op_restored->Type());
137137
ASSERT_EQ(op_origin->Inputs(), op_restored->Inputs());

python/paddle/fluid/layers/nn.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
'lod_reset',
7878
'lrn',
7979
'pad',
80+
'label_smooth',
8081
]
8182

8283

@@ -3678,3 +3679,68 @@ def pad(x, paddings, pad_value=0., name=None):
36783679
attrs={'paddings': paddings,
36793680
'pad_value': float(pad_value)})
36803681
return out
3682+
3683+
3684+
def label_smooth(label,
3685+
prior_dist=None,
3686+
epsilon=0.1,
3687+
dtype="float32",
3688+
name=None):
3689+
"""
3690+
Label smoothing is a mechanism to regularize the classifier layer and is
3691+
called label-smoothing regularization (LSR).
3692+
3693+
Label smoothing is proposed to encourage the model to be less confident,
3694+
since optimizing the log-likelihood of the correct label directly may
3695+
cause overfitting and reduce the ability of the model to adapt. Label
3696+
smoothing replaces the ground-truth label :math:`y` with the weighted sum
3697+
of itself and some fixed distribution :math:`\mu`. For class :math:`k`,
3698+
i.e.
3699+
3700+
.. math::
3701+
3702+
\\tilde{y_k} = (1 - \epsilon) * y_k + \epsilon * \mu_k,
3703+
3704+
where :math:`1 - \epsilon` and :math:`\epsilon` are the weights
3705+
respectively, and :math:`\\tilde{y}_k` is the smoothed label. Usually
3706+
uniform distribution is used for :math:`\mu`.
3707+
3708+
See more details about label smoothing in https://arxiv.org/abs/1512.00567.
3709+
3710+
Args:
3711+
label(Variable): The input variable containing the label data. The
3712+
label data should use one-hot representation.
3713+
prior_dist(Variable): The prior distribution to be used to smooth
3714+
labels. If not provided, an uniform distribution
3715+
is used. The shape of :attr:`prior_dist` should
3716+
be :math:`(1, class\_num)`.
3717+
epsilon(float): The weight used to mix up the original ground-truth
3718+
distribution and the fixed distribution.
3719+
dtype(np.dtype|core.VarDesc.VarType|str): The type of data : float32,
3720+
float_64, int etc.
3721+
name(str|None): A name for this layer(optional). If set None, the layer
3722+
will be named automatically.
3723+
3724+
Returns:
3725+
Variable: The tensor variable containing the smoothed labels.
3726+
3727+
Examples:
3728+
.. code-block:: python
3729+
3730+
label = layers.data(name="label", shape=[1], dtype="float32")
3731+
one_hot_label = layers.one_hot(input=label, depth=10)
3732+
smooth_label = layers.label_smooth(
3733+
label=one_hot_label, epsilon=0.1, dtype="float32")
3734+
"""
3735+
if epsilon > 1. or epsilon < 0.:
3736+
raise ValueError("The value of epsilon must be between 0 and 1.")
3737+
helper = LayerHelper("label_smooth", **locals())
3738+
label.stop_gradient = True
3739+
smooth_label = helper.create_tmp_variable(dtype)
3740+
helper.append_op(
3741+
type="label_smooth",
3742+
inputs={"X": label,
3743+
"PriorDist": prior_dist} if prior_dist else {"X": label},
3744+
outputs={"Out": smooth_label},
3745+
attrs={"epsilon": float(epsilon)})
3746+
return smooth_label

python/paddle/fluid/metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ def eval(self):
169169
return self.value / self.weight
170170

171171

172-
class ChunkEvalutor(MetricBase):
172+
class ChunkEvaluator(MetricBase):
173173
"""
174174
Accumulate counter numbers output by chunk_eval from mini-batches and
175175
compute the precision recall and F1-score using the accumulated counter
176176
numbers.
177177
"""
178178

179179
def __init__(self, name=None):
180-
super(ChunkEvalutor, self).__init__(name)
180+
super(ChunkEvaluator, self).__init__(name)
181181
self.num_infer_chunks = 0
182182
self.num_label_chunks = 0
183183
self.num_correct_chunks = 0

0 commit comments

Comments
 (0)