Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 039fa95

Browse files
tensorflower-gardenerreedwm
authored andcommitted
Squash commit.
PiperOrigin-RevId: 517247440
1 parent f9affd5 commit 039fa95

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+129
-349
lines changed

scripts/tf_cnn_benchmarks/all_reduce_benchmark.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424
TODO(reedwm): Allow custom sizes to be specified.
2525
"""
2626

27-
from __future__ import absolute_import
28-
from __future__ import division
29-
from __future__ import print_function
30-
31-
3227
import os
3328
import time
3429

@@ -43,14 +38,14 @@
4338
from cnn_util import log_fn
4439

4540

46-
absl_flags.DEFINE_integer('iters_per_step', 5,
47-
'Number of iterations to run all-reduce for, per '
48-
'step. Every step, a session will be run on a Graph '
49-
'that contains this many copies of the all-reduce. '
50-
'The copies are run sequentially. Setting this above '
51-
'1 is useful to lower the overhead of starting the '
52-
'session run, running the VariableV2 ops at the '
53-
'start of the step, etc.')
41+
_ITERS_PER_STEP = absl_flags.DEFINE_integer(
42+
'iters_per_step', 5, 'Number of iterations to run all-reduce for, per '
43+
'step. Every step, a session will be run on a Graph '
44+
'that contains this many copies of the all-reduce. '
45+
'The copies are run sequentially. Setting this above '
46+
'1 is useful to lower the overhead of starting the '
47+
'session run, running the VariableV2 ops at the '
48+
'start of the step, etc.')
5449

5550

5651
flags.define_flags()
@@ -283,7 +278,7 @@ def main(positional_arguments):
283278
tfversion = cnn_util.tensorflow_version_tuple()
284279
log_fn('TensorFlow: %i.%i' % (tfversion[0], tfversion[1]))
285280

286-
run_benchmark(bench, absl_flags.FLAGS.iters_per_step)
281+
run_benchmark(bench, _ITERS_PER_STEP.value)
287282

288283
if __name__ == '__main__':
289284
tf.disable_v2_behavior()

scripts/tf_cnn_benchmarks/all_reduce_benchmark_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
# ==============================================================================
1515
"""Tests for all_reduce_benchmark.py."""
1616

17-
from __future__ import absolute_import
18-
from __future__ import division
19-
from __future__ import print_function
20-
2117
import tensorflow.compat.v1 as tf
2218

2319
import all_reduce_benchmark

scripts/tf_cnn_benchmarks/allreduce.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@
1414
# ==============================================================================
1515
"""Utilities for allreduce."""
1616

17-
from __future__ import absolute_import
18-
from __future__ import division
19-
from __future__ import print_function
20-
2117
import collections as pycoll
2218
import re
2319

24-
from six.moves import xrange # pylint: disable=redefined-builtin
2520
import tensorflow.compat.v1 as tf
2621

2722
# pylint: disable=g-direct-tensorflow-import,g-import-not-at-top
@@ -451,7 +446,7 @@ def sum_gradients_all_reduce(single_session,
451446
gv = list(zip(*tower_grads))
452447
merge_scope = allreduce_merge_scope if allreduce_merge_scope > 0 else 1
453448
chunked_gv = [gv[x:x + merge_scope]
454-
for x in xrange(0, len(gv), merge_scope)]
449+
for x in range(0, len(gv), merge_scope)]
455450
for chunk in chunked_gv:
456451
with tf.name_scope('allreduce'):
457452
for grad_and_vars in chunk:
@@ -638,7 +633,7 @@ def unpack_small_tensors(tower_grads, packing):
638633
num_packed = len(packing.keys()) // num_devices
639634
for dev_idx, gv_list in enumerate(tower_grads):
640635
new_gv_list = gv_list[num_packed:]
641-
for i in xrange(0, num_packed):
636+
for i in range(0, num_packed):
642637
k = '%d:%d' % (dev_idx, i)
643638
gpt = packing[k]
644639
gv = unpack_grad_tuple(gv_list[i], gpt)

scripts/tf_cnn_benchmarks/allreduce_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515

1616
"""Tests for tf_cnn_benchmark.allreduce."""
1717

18-
from __future__ import absolute_import
19-
from __future__ import division
20-
from __future__ import print_function
21-
2218
import collections as pycoll
2319

2420
import numpy as np

scripts/tf_cnn_benchmarks/batch_allreduce.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@
2424
across devices and inter-device tensor transfers across device links.
2525
"""
2626

27-
from __future__ import absolute_import
28-
from __future__ import division
29-
from __future__ import print_function
30-
3127
# TODO(reedwm): Support distributed all-reduces in this file.
3228
# TODO(reedwm): Merge this code with allreduce.py, which contains some batch
3329
# all-reduce code that this file calls. allreduce.py also supports distributed
3430
# batch-reduce while this file only supports single-machine all-reduce.
3531

3632
import abc
3733

38-
import six
3934
import tensorflow.compat.v1 as tf
4035

4136
from tensorflow.python.ops import data_flow_ops
@@ -60,8 +55,7 @@ def _all_reduce_using_copy(tensors_across_devices, use_mean):
6055
return reduced_tensor
6156

6257

63-
@six.add_metaclass(abc.ABCMeta)
64-
class BatchAllReduceAlgorithm(object):
58+
class BatchAllReduceAlgorithm(metaclass=abc.ABCMeta):
6559
"""Represents an algorithm for performing a batch all-reduce operation."""
6660

6761
def batch_all_reduce(self,

scripts/tf_cnn_benchmarks/benchmark_cnn.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
See the README for more information.
1818
"""
1919

20-
from __future__ import absolute_import
21-
from __future__ import division
22-
from __future__ import print_function
23-
2420
import argparse
2521
from collections import namedtuple
2622
import contextlib
@@ -34,9 +30,6 @@
3430

3531
from absl import flags as absl_flags
3632
import numpy as np
37-
38-
import six
39-
from six.moves import xrange # pylint: disable=redefined-builtin
4033
import tensorflow.compat.v1 as tf
4134

4235
# pylint: disable=g-direct-tensorflow-import
@@ -54,7 +47,7 @@
5447
from tensorflow.core.protobuf import rewriter_config_pb2
5548
from tensorflow.python import debug as tf_debug
5649
from tensorflow.python.client import timeline
57-
from tensorflow.python.framework import graph_util
50+
from tensorflow.python.framework import convert_to_constants
5851
from tensorflow.python.framework import graph_util_impl
5952
from tensorflow.python.framework import importer
6053
from tensorflow.python.ops import data_flow_ops
@@ -1526,7 +1519,7 @@ def __init__(self, params, dataset=None, model=None):
15261519
# compute device, and never on a parameter server device.
15271520
self.raw_devices = [
15281521
'%s/%s:%i' % (worker_prefix, self.params.device, i)
1529-
for i in xrange(self.num_gpus)
1522+
for i in range(self.num_gpus)
15301523
]
15311524

15321525
subset = 'validation' if params.eval else 'train'
@@ -1747,7 +1740,7 @@ def reset_devices_for_task(self, task_num, is_local=False):
17471740
self.cpu_device = '%s/cpu:0' % worker_prefix
17481741
self.raw_devices = [
17491742
'%s/%s:%i' % (worker_prefix, self.params.device, i)
1750-
for i in xrange(self.num_gpus)
1743+
for i in range(self.num_gpus)
17511744
]
17521745
self.devices = self.variable_mgr.get_devices()
17531746

@@ -1759,8 +1752,8 @@ def raw_devices_across_tasks(self, is_local=False):
17591752
else:
17601753
return [
17611754
'job:worker/replica:0/task%s/%s:%i' % (t, self.params.device, i)
1762-
for t in xrange(self.num_workers)
1763-
for i in xrange(self.num_gpus)
1755+
for t in range(self.num_workers)
1756+
for i in range(self.num_gpus)
17641757
]
17651758

17661759
def print_info(self):
@@ -1985,7 +1978,7 @@ def _initialize_eval_graph(self, enqueue_ops, input_producer_op,
19851978
self.params.use_python32_barrier)
19861979
image_producer.start()
19871980
if enqueue_ops:
1988-
for i in xrange(len(enqueue_ops)):
1981+
for i in range(len(enqueue_ops)):
19891982
sess.run(enqueue_ops[:(i + 1)])
19901983
if image_producer is not None:
19911984
image_producer.notify_image_consumption()
@@ -2003,7 +1996,7 @@ def _eval_once(self, sess, summary_writer, fetches, summary_op,
20031996
top_1_accuracy_sum = 0.0
20041997
top_5_accuracy_sum = 0.0
20051998
total_eval_count = self.num_batches * self.batch_size
2006-
for step in xrange(self.num_batches):
1999+
for step in range(self.num_batches):
20072000
if (summary_writer and self.params.save_summaries_steps > 0 and
20082001
(step + 1) % self.params.save_summaries_steps == 0):
20092002
results, summary_str = sess.run([fetches, summary_op])
@@ -2339,7 +2332,7 @@ def benchmark_with_session(self, sess, supervisor, graph_info,
23392332
self.params.use_python32_barrier)
23402333
image_producer.start()
23412334
if graph_info.enqueue_ops:
2342-
for i in xrange(len(graph_info.enqueue_ops)):
2335+
for i in range(len(graph_info.enqueue_ops)):
23432336
sess.run(graph_info.enqueue_ops[:(i + 1)])
23442337
if image_producer is not None:
23452338
image_producer.notify_image_consumption()
@@ -2617,7 +2610,7 @@ def _preprocess_graph(self, graph, graph_info):
26172610
with tf.Session(config=create_config_proto(self.params)) as sess:
26182611
sess.run(tf.global_variables_initializer())
26192612
sess.run(tf.local_variables_initializer())
2620-
graphdef = graph_util.convert_variables_to_constants(
2613+
graphdef = convert_to_constants.convert_variables_to_constants(
26212614
sess,
26222615
graphdef,
26232616
output_node_names,
@@ -2749,7 +2742,7 @@ def _build_input_processing(self, shift_ratio=0):
27492742
shared_name='input_producer_staging_area_%d_eval_%s' %
27502743
(device_num, self._doing_eval))
27512744
input_producer_stages.append(staging_area)
2752-
for group_index in xrange(self.batch_group_size):
2745+
for group_index in range(self.batch_group_size):
27532746
batch_index = group_index + device_num * self.batch_group_size
27542747
put_op = staging_area.put(
27552748
[parts[batch_index] for parts in input_list])
@@ -2868,7 +2861,8 @@ def _build_model(self):
28682861
if self.variable_mgr.supports_staged_vars():
28692862
for staging_ops in self.variable_mgr.staging_vars_on_devices:
28702863
gpu_compute_stage_ops.extend(
2871-
[put_op for _, (put_op, _) in six.iteritems(staging_ops)])
2864+
[put_op for _, (put_op, _) in staging_ops.items()]
2865+
)
28722866
enqueue_ops.append(tf.group(*gpu_compute_stage_ops,
28732867
name='gpu_compute_stage_ops_group'))
28742868
if gpu_grad_stage_ops:

scripts/tf_cnn_benchmarks/benchmark_cnn_distributed_test.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
The output for each process is written to disk and can be viewed to debug tests.
2121
See get_test_output_dir() in platforms/default/util.py for more info.
2222
"""
23-
24-
from __future__ import absolute_import
25-
from __future__ import division
26-
from __future__ import print_function
2723
from collections import namedtuple
2824
import os
2925
import subprocess
@@ -32,7 +28,6 @@
3228

3329
from absl import flags as absl_flags
3430
import portpicker
35-
import six
3631
import tensorflow.compat.v1 as tf
3732
import flags
3833
import test_util
@@ -55,7 +50,8 @@ def _convert_params_to_flags_list(params):
5550
A list of flags.
5651
"""
5752
return [
58-
'--%s=%s' % (k, str(v)) for k, v in six.iteritems(params._asdict())
53+
'--%s=%s' % (k, str(v))
54+
for k, v in params._asdict().items()
5955
if v != flags.param_specs[k].default_value
6056
]
6157

scripts/tf_cnn_benchmarks/benchmark_cnn_distributed_test_runner.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
file is spawned as a Python process, which supports the added functionality.
2222
"""
2323

24-
from __future__ import absolute_import
25-
from __future__ import division
26-
from __future__ import print_function
27-
2824
from absl import flags as absl_flags
2925
import numpy as np
3026
import tensorflow.compat.v1 as tf
@@ -34,8 +30,8 @@
3430
import test_util
3531

3632

37-
absl_flags.DEFINE_string('fake_input', 'none',
38-
"""What fake input to inject into benchmark_cnn. This
33+
_FAKE_INPUT = absl_flags.DEFINE_string(
34+
'fake_input', 'none', """What fake input to inject into benchmark_cnn. This
3935
is ignored if --model=test_model.
4036
Options are:
4137
none: Do not inject any fake input.
@@ -44,7 +40,6 @@
4440
label of 1.""")
4541

4642
flags.define_flags()
47-
FLAGS = flags.FLAGS
4843

4944

5045
def get_test_image_preprocessor(batch_size, params):
@@ -60,9 +55,9 @@ def get_test_image_preprocessor(batch_size, params):
6055
Raises:
6156
ValueError: Flag --fake_input is an invalid value.
6257
"""
63-
if FLAGS.fake_input == 'none':
58+
if _FAKE_INPUT.value == 'none':
6459
return None
65-
elif FLAGS.fake_input == 'zeros_and_ones':
60+
elif _FAKE_INPUT.value == 'zeros_and_ones':
6661
half_batch_size = batch_size // 2
6762
images = np.zeros((batch_size, 227, 227, 3), dtype=np.float32)
6863
images[half_batch_size:, :, :, :] = 1
@@ -75,7 +70,7 @@ def get_test_image_preprocessor(batch_size, params):
7570
preprocessor.expected_subset = 'validation' if params.eval else 'train'
7671
return preprocessor
7772
else:
78-
raise ValueError('Invalid --fake_input: %s' % FLAGS.fake_input)
73+
raise ValueError('Invalid --fake_input: %s' % _FAKE_INPUT.value)
7974

8075

8176
def run_with_real_model(params):

scripts/tf_cnn_benchmarks/benchmark_cnn_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
# ==============================================================================
1515

1616
"""Tests for benchmark_cnn."""
17-
18-
from __future__ import absolute_import
19-
from __future__ import division
20-
from __future__ import print_function
2117
import glob
2218
import os
2319
import re

scripts/tf_cnn_benchmarks/cnn_util.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
# ==============================================================================
1515

1616
"""Utilities for CNN benchmarks."""
17-
from __future__ import absolute_import
18-
from __future__ import division
19-
from __future__ import print_function
2017

2118
import sys
2219
import threading

scripts/tf_cnn_benchmarks/cnn_util_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515

1616
"""Tests for tf_cnn_benchmarks.cnn_util."""
1717

18-
from __future__ import absolute_import
19-
from __future__ import division
20-
from __future__ import print_function
21-
2218
import threading
2319
import time
2420

scripts/tf_cnn_benchmarks/coco_metric.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,14 @@
1919
COCO API: github.com/cocodataset/cocoapi/
2020
"""
2121

22-
from __future__ import absolute_import
23-
from __future__ import division
24-
from __future__ import print_function
25-
2622
import atexit
2723
import tempfile
2824

2925
from absl import flags
30-
3126
import numpy as np
27+
import pycocotools.coco
3228
from pycocotools.coco import COCO
3329
from pycocotools.cocoeval import COCOeval
34-
import six
35-
3630
import tensorflow.compat.v1 as tf
3731

3832
import mlperf
@@ -42,9 +36,8 @@
4236

4337

4438
# https://github.com/cocodataset/cocoapi/issues/49
45-
if six.PY3:
46-
import pycocotools.coco
47-
pycocotools.coco.unicode = str
39+
40+
pycocotools.coco.unicode = str
4841

4942

5043
def async_eval_runner(queue_predictions, queue_results, val_json_file):

scripts/tf_cnn_benchmarks/constants.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
# ==============================================================================
1515
"""Constants used in tf_cnn_benchmarks."""
1616

17-
from __future__ import absolute_import
18-
from __future__ import division
19-
from __future__ import print_function
20-
2117
from enum import Enum
2218

2319
# Results fetched with this prefix will not be reduced. Instead, they will be

0 commit comments

Comments
 (0)