Skip to content

Commit 2e40660

Browse files
committed
Fix some issues.
1 parent 19db989 commit 2e40660

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

python/paddle/fluid/framework.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ def __init__(self, block, shape, dtype, **kwargs):
11551155

11561156
self.gradient_clip_attr = kwargs.get('gradient_clip_attr', None)
11571157

1158-
self.average = kwargs.get('average', True)
1158+
self.do_model_average = kwargs.get('do_model_average', None)
11591159

11601160
def __str__(self):
11611161
return self.to_string(True)
@@ -1177,7 +1177,7 @@ def to_string(self, throw_on_error, with_details=False):
11771177
if with_details:
11781178
res_str = Variable.to_string(self, throw_on_error, True)
11791179
additional_attr = ("trainable", "optimize_attr", "regularizer",
1180-
"gradient_clip_attr", "average")
1180+
"gradient_clip_attr", "do_model_average")
11811181
for attr_name in additional_attr:
11821182
res_str += "%s: %s\n" % (attr_name,
11831183
str(getattr(self, attr_name)))

python/paddle/fluid/layers/nn.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,8 +1489,7 @@ def batch_norm(input,
14891489
name=None,
14901490
moving_mean_name=None,
14911491
moving_variance_name=None,
1492-
average_mean=True,
1493-
average_variance=True):
1492+
do_model_average_for_mean_and_var=False):
14941493
"""
14951494
This function helps create an operator to implement
14961495
the BatchNorm layer using the configurations from the input parameters.
@@ -1519,12 +1518,15 @@ def batch_norm(input,
15191518
bias = helper.create_parameter(
15201519
attr=helper.bias_attr, shape=param_shape, dtype=dtype, is_bias=True)
15211520

1521+
if do_model_average_for_mean_and_var:
1522+
do_model_average_for_mean_and_var = None
1523+
15221524
mean = helper.create_parameter(
15231525
attr=ParamAttr(
15241526
name=moving_mean_name,
15251527
initializer=Constant(0.0),
15261528
trainable=False,
1527-
average=average_variance),
1529+
do_model_average=do_model_average_for_mean_and_var),
15281530
shape=param_shape,
15291531
dtype=input.dtype)
15301532
mean.stop_gradient = True
@@ -1534,7 +1536,7 @@ def batch_norm(input,
15341536
name=moving_variance_name,
15351537
initializer=Constant(1.0),
15361538
trainable=False,
1537-
average=average_mean),
1539+
do_model_average=do_model_average_for_mean_and_var),
15381540
shape=param_shape,
15391541
dtype=input.dtype)
15401542
variance.stop_gradient = True
@@ -3352,14 +3354,14 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=True, name=None):
33523354
Here are some examples to explain it.
33533355
33543356
1. Given a 3-D tensor x with a shape [2, 4, 6], and the target shape
3355-
is [6, 8], the reshape operator will transform x into a 2-D tensor with
3357+
is [6, 8], the reshape operator will transform x into a 2-D tensor with
33563358
shape [6, 8] and leaving x's data unchanged.
33573359
33583360
2. Given a 3-D tensor x with a shape [2, 4, 6], and the target shape
33593361
specified is [2, 3, -1, 2], the reshape operator will transform x into a
33603362
4-D tensor with shape [2, 3, 4, 2] and leaving x's data unchanged. In this
3361-
case, one dimension of the target shape is set to -1, the value of this
3362-
dimension is inferred from the total element number of x and remaining
3363+
case, one dimension of the target shape is set to -1, the value of this
3364+
dimension is inferred from the total element number of x and remaining
33633365
dimensions.
33643366
33653367
3. Given a 3-D tensor x with a shape [2, 4, 6], and the target shape
@@ -3593,7 +3595,7 @@ def lrn(input, n=5, k=1.0, alpha=1e-4, beta=0.75, name=None):
35933595
def pad(x, paddings, pad_value=0., name=None):
35943596
"""
35953597
Pads a tensor with a constant value given by :attr:`pad_value`, and the
3596-
padded width is specified by :attr:`paddings`.
3598+
padded width is specified by :attr:`paddings`.
35973599
35983600
Specifically, the number of values padded before the contents of :attr:`x`
35993601
in dimension :attr:`i` is indicated by :attr:`paddings[i]`, and the number
@@ -3621,7 +3623,7 @@ def pad(x, paddings, pad_value=0., name=None):
36213623
x (Variable): The input tensor variable.
36223624
paddings (list): A list of integers. Its elements specify the padded
36233625
width before and after for each dimension in turn.
3624-
The length of :attr:paddings must be
3626+
The length of :attr:paddings must be
36253627
:math:`rank(x) \\times 2`.
36263628
pad_value (float): The constant value used to pad.
36273629
name(str|None): A name for this layer(optional). If set None, the layer

python/paddle/fluid/optimizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ class ModelAverage(Optimizer):
840840
"""
841841

842842
def __init__(self,
843-
average_window_rate=0.15,
843+
average_window_rate,
844844
params_grads=None,
845845
min_average_window=10000,
846846
max_average_window=10000,
@@ -856,7 +856,7 @@ def __init__(self,
856856
params[param.name] = (param, grad)
857857
for param in framework.default_main_program().global_block(
858858
).all_parameters():
859-
if param.name not in params and param.average:
859+
if param.name not in params and param.do_model_average != False:
860860
grad = param.block.create_var(
861861
name=unique_name.generate(".".join([param.name, 'tmp'])),
862862
dtype=param.dtype,

python/paddle/fluid/param_attr.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ def __init__(self,
2929
regularizer=None,
3030
trainable=True,
3131
gradient_clip=None,
32-
average=True):
32+
do_model_average=None):
3333
self.name = name
3434
self.initializer = initializer
3535
self.learning_rate = learning_rate
3636
self.regularizer = regularizer
3737
self.trainable = trainable
3838
self.gradient_clip = gradient_clip
39-
self.average = average
39+
self.model_average = do_model_average
4040

4141
def set_default_initializer(self, initializer):
4242
if initializer is None:
@@ -83,7 +83,7 @@ def to_kwargs(self, with_initializer=False):
8383
'regularizer': self.regularizer,
8484
'trainable': self.trainable,
8585
'gradient_clip_attr': self.gradient_clip,
86-
'average': self.average
86+
'model_average': self.model_average
8787
}
8888
if with_initializer:
8989
kwargs['initializer'] = self.initializer

0 commit comments

Comments
 (0)