Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Commit 4af78a7

Browse files
T2T TeamRyan Sepassi
authored andcommitted
s/keep_dims/keepdims since keep_dims in tf.reduce_mean is deprecated.
PiperOrigin-RevId: 197200583
1 parent 2b2b46d commit 4af78a7

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

tensor2tensor/layers/common_layers.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ def standardize_images(x):
228228
"""Image standardization on batches."""
229229
with tf.name_scope("standardize_images", [x]):
230230
x = tf.to_float(x)
231-
x_mean = tf.reduce_mean(x, axis=[1, 2, 3], keep_dims=True)
231+
x_mean = tf.reduce_mean(x, axis=[1, 2, 3], keepdims=True)
232232
x_variance = tf.reduce_mean(
233-
tf.square(x - x_mean), axis=[1, 2, 3], keep_dims=True)
233+
tf.square(x - x_mean), axis=[1, 2, 3], keepdims=True)
234234
x_shape = shape_list(x)
235235
num_pixels = tf.to_float(x_shape[1] * x_shape[2] * x_shape[3])
236236
x = (x - x_mean) / tf.maximum(tf.sqrt(x_variance), tf.rsqrt(num_pixels))
@@ -604,8 +604,8 @@ def layer_norm_vars(filters):
604604
def layer_norm_compute_python(x, epsilon, scale, bias):
605605
"""Layer norm raw computation."""
606606
epsilon, scale, bias = [tf.cast(t, x.dtype) for t in [epsilon, scale, bias]]
607-
mean = tf.reduce_mean(x, axis=[-1], keep_dims=True)
608-
variance = tf.reduce_mean(tf.square(x - mean), axis=[-1], keep_dims=True)
607+
mean = tf.reduce_mean(x, axis=[-1], keepdims=True)
608+
variance = tf.reduce_mean(tf.square(x - mean), axis=[-1], keepdims=True)
609609
norm_x = (x - mean) * tf.rsqrt(variance + epsilon)
610610
return norm_x * scale + bias
611611

@@ -1289,7 +1289,7 @@ def mask_from_embedding(emb):
12891289
Returns:
12901290
a 0.0/1.0 Tensor with shape [batch, width, height, 1].
12911291
"""
1292-
return weights_nonzero(tf.reduce_sum(tf.abs(emb), axis=3, keep_dims=True))
1292+
return weights_nonzero(tf.reduce_sum(tf.abs(emb), axis=3, keepdims=True))
12931293

12941294

12951295
def mask_leq(target_length, source_length):
@@ -1913,7 +1913,7 @@ def global_pool_1d(inputs, pooling_type="MAX", mask=None):
19131913
if mask is not None:
19141914
# Some elems are dummy elems so we can't just reduce the average.
19151915
output = tf.reduce_sum(inputs, axis=1)
1916-
num_elems = tf.reduce_sum(mask, axis=1, keep_dims=True)
1916+
num_elems = tf.reduce_sum(mask, axis=1, keepdims=True)
19171917
output = tf.div(output, tf.maximum(num_elems, 1))
19181918
else:
19191919
output = tf.reduce_mean(inputs, axis=1)
@@ -2977,7 +2977,7 @@ def argmax_with_score(logits, axis=None):
29772977

29782978

29792979
def log_prob_from_logits(logits, reduce_axis=-1):
2980-
return logits - tf.reduce_logsumexp(logits, axis=reduce_axis, keep_dims=True)
2980+
return logits - tf.reduce_logsumexp(logits, axis=reduce_axis, keepdims=True)
29812981

29822982

29832983
def top_1_tpu(inputs):
@@ -2992,7 +2992,7 @@ def top_1_tpu(inputs):
29922992
values: a Tensor with shape [...]
29932993
indices: a Tensor with shape [...]
29942994
"""
2995-
inputs_max = tf.reduce_max(inputs, axis=-1, keep_dims=True)
2995+
inputs_max = tf.reduce_max(inputs, axis=-1, keepdims=True)
29962996
mask = tf.to_int32(tf.equal(inputs_max, inputs))
29972997
index = tf.range(tf.shape(inputs)[-1]) * mask
29982998
return tf.squeeze(inputs_max, -1), tf.reduce_max(index, axis=-1)

tensor2tensor/models/research/basic_conv_gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def body(self, features):
113113
x = x[:, :inputs_shape[1], :inputs_shape[2], :]
114114

115115
# Reward prediction.
116-
reward_pred = tf.reduce_mean(x, axis=[1, 2], keep_dims=True)
116+
reward_pred = tf.reduce_mean(x, axis=[1, 2], keepdims=True)
117117
return {"targets": x, "target_reward": reward_pred}
118118

119119
def infer(self, features, *args, **kwargs):

tensor2tensor/models/research/transformer_vae.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ def top_k_softmax(x, k):
9292
"""Calculate softmax(x), select top-k and rescale to sum to 1."""
9393
x = tf.nn.softmax(x)
9494
top_x, _ = tf.nn.top_k(x, k=k+1)
95-
min_top = tf.reduce_min(top_x, axis=-1, keep_dims=True)
95+
min_top = tf.reduce_min(top_x, axis=-1, keepdims=True)
9696
x = tf.nn.relu((x - min_top) + 1e-12)
97-
x /= tf.reduce_sum(x, axis=-1, keep_dims=True)
97+
x /= tf.reduce_sum(x, axis=-1, keepdims=True)
9898
return x, tf.reduce_max(top_x, axis=-1)
9999

100100

tensor2tensor/utils/adafactor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def _resource_apply_dense(self, grad, var):
237237
vr_update = tf.assign(vr, new_vr, use_locking=self._use_locking)
238238
vc_update = tf.assign(vc, new_vc, use_locking=self._use_locking)
239239
updates = [vr_update, vc_update]
240-
long_term_mean = tf.reduce_mean(new_vr, -1, keep_dims=True)
240+
long_term_mean = tf.reduce_mean(new_vr, -1, keepdims=True)
241241
r_factor = tf.rsqrt(new_vr / long_term_mean)
242242
c_factor = tf.rsqrt(new_vc)
243243
x = grad * tf.expand_dims(r_factor, -1) * tf.expand_dims(c_factor, -2)

tensor2tensor/utils/diet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@ def update_variable(self, var, grad_var):
192192
beta2_pow = tf.pow(params.beta2, global_step)
193193
if params.factored_second_moment_accumulator and len(var.shape) == 2:
194194
vr_update = tf.assign(slots["adam_vr"], slots["adam_vr"] * params.beta2 +
195-
tf.reduce_mean(grad_squared, 1, keep_dims=True) *
195+
tf.reduce_mean(grad_squared, 1, keepdims=True) *
196196
(1.0 - params.beta2))
197197
vc_update = tf.assign(slots["adam_vc"], slots["adam_vc"] * params.beta2 +
198-
tf.reduce_mean(grad_squared, 0, keep_dims=True) *
198+
tf.reduce_mean(grad_squared, 0, keepdims=True) *
199199
(1.0 - params.beta2))
200200
with tf.control_dependencies([vr_update, vc_update]):
201201
vr = tf.sqrt(slots["adam_vr"] / (1.0 - beta2_pow)) + params.epsilon

tensor2tensor/utils/expert_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ def local_moe_tpu(inputs,
12571257
mask_1 *= tf.to_float(tf.less(position_in_expert_1, expert_capacity_f))
12581258
# [batch, 1, num_experts]
12591259
# How many examples in this sequence go to this expert
1260-
mask_1_count = tf.reduce_sum(mask_1, axis=1, keep_dims=True)
1260+
mask_1_count = tf.reduce_sum(mask_1, axis=1, keepdims=True)
12611261
# [batch, length] - mostly ones, but zeros where something didn't fit
12621262
mask_1_flat = tf.reduce_sum(mask_1, axis=2)
12631263
position_in_expert_1 = tf.reduce_sum(position_in_expert_1, axis=2)
@@ -1284,7 +1284,7 @@ def local_moe_tpu(inputs,
12841284
common_layers.cumsum(mask_2, axis=1, exclusive=True) + mask_1_count)
12851285
position_in_expert_2 *= mask_2
12861286
mask_2 *= tf.to_float(tf.less(position_in_expert_2, expert_capacity_f))
1287-
mask_2_count = tf.reduce_sum(mask_2, axis=1, keep_dims=True)
1287+
mask_2_count = tf.reduce_sum(mask_2, axis=1, keepdims=True)
12881288
mask_2_flat = tf.reduce_sum(mask_2, axis=2)
12891289
position_in_expert_2 = tf.reduce_sum(position_in_expert_2, axis=2)
12901290
gate_2 *= mask_2_flat

tensor2tensor/utils/quantization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def simulated_quantize(x, num_bits, noise):
8888
shape = x.get_shape().as_list()
8989
if not (len(shape) >= 2 and shape[-1] > 1):
9090
return x
91-
max_abs = tf.reduce_max(tf.abs(x), -1, keep_dims=True) + 1e-9
91+
max_abs = tf.reduce_max(tf.abs(x), -1, keepdims=True) + 1e-9
9292
max_int = 2 ** (num_bits - 1) - 1
9393
scale = max_abs / max_int
9494
x /= scale

0 commit comments

Comments
 (0)