Skip to content

Commit 312d0e8

Browse files
Change default for assign_moving_average to perform 0-debiasing. This is a semantic breaking change.
Change: 139237086
1 parent f97cd45 commit 312d0e8

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

tensorflow/python/training/moving_averages.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030

3131
# TODO(touts): switch to variables.Variable.
32-
def assign_moving_average(variable, value, decay, zero_debias=False, name=None):
32+
def assign_moving_average(variable, value, decay, zero_debias=True, name=None):
3333
"""Compute the moving average of a variable.
3434
3535
The moving average of 'variable' updated with 'value' is:
@@ -124,8 +124,10 @@ def weighted_moving_average(value,
124124
dtype=weight.dtype),
125125
trainable=False,
126126
collections=collections)
127-
numerator = assign_moving_average(value_x_weight_var, value * weight, decay)
128-
denominator = assign_moving_average(weight_var, weight, decay)
127+
numerator = assign_moving_average(
128+
value_x_weight_var, value * weight, decay, zero_debias=False)
129+
denominator = assign_moving_average(
130+
weight_var, weight, decay, zero_debias=False)
129131

130132
if truediv:
131133
return math_ops.truediv(numerator, denominator, name=scope.name)

tensorflow/python/training/moving_averages_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@
2525

2626
class MovingAveragesTest(tf.test.TestCase):
2727

28-
def testAssignMovingAverage(self):
28+
def testAssignMovingAverageWithoutZeroDebias(self):
2929
with self.test_session():
3030
var = tf.Variable([10.0, 11.0])
3131
val = tf.constant([1.0, 2.0], tf.float32)
3232
decay = 0.25
33-
assign = moving_averages.assign_moving_average(var, val, decay)
33+
assign = moving_averages.assign_moving_average(
34+
var, val, decay, zero_debias=False)
3435
tf.global_variables_initializer().run()
3536
self.assertAllClose([10.0, 11.0], var.eval())
3637
assign.op.run()
3738
self.assertAllClose([10.0 * 0.25 + 1.0 * (1.0 - 0.25),
3839
11.0 * 0.25 + 2.0 * (1.0 - 0.25)],
3940
var.eval())
4041

41-
def testAssignMovingAverageWithZeroDebias(self):
42+
def testAssignMovingAverage(self):
4243
with self.test_session():
4344
var = tf.Variable([0.0, 0.0])
4445
val = tf.constant([1.0, 2.0], tf.float32)
4546
decay = 0.25
46-
assign = moving_averages.assign_moving_average(
47-
var, val, decay, zero_debias=True)
47+
assign = moving_averages.assign_moving_average(var, val, decay)
4848
tf.global_variables_initializer().run()
4949
self.assertAllClose([0.0, 0.0], var.eval())
5050
assign.op.run()
@@ -293,8 +293,8 @@ def testAverageVariablesDeviceAssignment(self):
293293
with tf.device("/job:dev_v0"):
294294
v0 = tf.Variable(10.0, name="v0")
295295
with tf.device("/job:dev_v1"):
296-
v1 = gen_state_ops._variable(shape=[1], dtype=tf.float32,
297-
name="v1", container="", shared_name="")
296+
v1 = gen_state_ops._variable(shape=[1], dtype=tf.float32,
297+
name="v1", container="", shared_name="")
298298
v1.set_shape([1])
299299
tensor2 = v0 + v1
300300
ema = tf.train.ExponentialMovingAverage(0.25, name="foo_avg")

0 commit comments

Comments
 (0)