Benchmark name cleanup.
PiperOrigin-RevId: 248562139
This commit is contained in:
parent
dab8b395cd
commit
0ccca332e6
tensorflow/python/data
benchmarks
experimental/benchmarks
@ -35,7 +35,7 @@ from tensorflow.python.platform import test
|
|||||||
class ListFilesBenchmark(test.Benchmark):
|
class ListFilesBenchmark(test.Benchmark):
|
||||||
"""Benchmarks for `tf.data.Dataset.list_files()`."""
|
"""Benchmarks for `tf.data.Dataset.list_files()`."""
|
||||||
|
|
||||||
def benchmarkNestedDirectories(self):
|
def benchmark_nested_directories(self):
|
||||||
tmp_dir = tempfile.mkdtemp()
|
tmp_dir = tempfile.mkdtemp()
|
||||||
width = 1024
|
width = 1024
|
||||||
depth = 16
|
depth = 16
|
||||||
|
@ -40,19 +40,19 @@ class MetaBenchmark(test.Benchmark):
|
|||||||
options.experimental_optimization.apply_default_optimizations = False
|
options.experimental_optimization.apply_default_optimizations = False
|
||||||
return dataset_ops.Dataset.range(10000**2).with_options(options)
|
return dataset_ops.Dataset.range(10000**2).with_options(options)
|
||||||
|
|
||||||
def benchmarkFastDatasetWithOnlyCppIterations(self):
|
def benchmark_fast_dataset_with_only_cpp_iterations(self):
|
||||||
dataset = self.setup_fast_dataset()
|
dataset = self.setup_fast_dataset()
|
||||||
self.run_benchmark_with_only_cpp_iterations(dataset)
|
self.run_benchmark_with_only_cpp_iterations(dataset)
|
||||||
|
|
||||||
def benchmarkFastDatasetWithSessionRun(self):
|
def benchmark_fast_dataset_with_session_run(self):
|
||||||
dataset = self.setup_fast_dataset()
|
dataset = self.setup_fast_dataset()
|
||||||
self.run_benchmark_with_session_run(dataset)
|
self.run_benchmark_with_session_run(dataset)
|
||||||
|
|
||||||
def benchmarkFastDatasetWithSessionCallable(self):
|
def benchmark_fast_dataset_with_session_callable(self):
|
||||||
dataset = self.setup_fast_dataset()
|
dataset = self.setup_fast_dataset()
|
||||||
self.run_benchmark_with_session_run(dataset, make_callable=True)
|
self.run_benchmark_with_session_run(dataset, make_callable=True)
|
||||||
|
|
||||||
def benchmarkFastDatasetInEager(self):
|
def benchmark_fast_dataset_in_eager(self):
|
||||||
with context.eager_mode():
|
with context.eager_mode():
|
||||||
dataset = self.setup_fast_dataset()
|
dataset = self.setup_fast_dataset()
|
||||||
self.run_benchmark_in_eager(dataset)
|
self.run_benchmark_in_eager(dataset)
|
||||||
@ -63,19 +63,19 @@ class MetaBenchmark(test.Benchmark):
|
|||||||
# sleep for 1e-3s per iteration
|
# sleep for 1e-3s per iteration
|
||||||
return dataset.apply(sleep.sleep(1000))
|
return dataset.apply(sleep.sleep(1000))
|
||||||
|
|
||||||
def benchmarkSlowDatasetWithOnlyCppIterations(self):
|
def benchmark_slow_dataset_with_only_cpp_iterations(self):
|
||||||
dataset = self.setup_slow_dataset()
|
dataset = self.setup_slow_dataset()
|
||||||
self.run_benchmark_with_only_cpp_iterations(dataset)
|
self.run_benchmark_with_only_cpp_iterations(dataset)
|
||||||
|
|
||||||
def benchmarkSlowDatasetWithSessionRun(self):
|
def benchmark_slow_dataset_with_session_run(self):
|
||||||
dataset = self.setup_slow_dataset()
|
dataset = self.setup_slow_dataset()
|
||||||
self.run_benchmark_with_session_run(dataset)
|
self.run_benchmark_with_session_run(dataset)
|
||||||
|
|
||||||
def benchmarkSlowDatasetWithSessionCallable(self):
|
def benchmark_slow_dataset_with_session_callable(self):
|
||||||
dataset = self.setup_slow_dataset()
|
dataset = self.setup_slow_dataset()
|
||||||
self.run_benchmark_with_session_run(dataset, make_callable=True)
|
self.run_benchmark_with_session_run(dataset, make_callable=True)
|
||||||
|
|
||||||
def benchmarkSlowDatasetInEager(self):
|
def benchmark_slow_dataset_in_eager(self):
|
||||||
with context.eager_mode():
|
with context.eager_mode():
|
||||||
dataset = self.setup_slow_dataset()
|
dataset = self.setup_slow_dataset()
|
||||||
self.run_benchmark_in_eager(dataset)
|
self.run_benchmark_in_eager(dataset)
|
||||||
|
@ -31,12 +31,12 @@ from tensorflow.python.platform import test
|
|||||||
class AutotuneBenchmark(test.Benchmark):
|
class AutotuneBenchmark(test.Benchmark):
|
||||||
"""Benchmarks for autotuning performance knobs."""
|
"""Benchmarks for autotuning performance knobs."""
|
||||||
|
|
||||||
def benchmarkMap(self):
|
def benchmark_map(self):
|
||||||
a = self._benchmarkMap(autotune=False)
|
a = self._benchmark_map(autotune=False)
|
||||||
b = self._benchmarkMap(autotune=True)
|
b = self._benchmark_map(autotune=True)
|
||||||
print("speedup: %f" % (a / b))
|
print("speedup: %f" % (a / b))
|
||||||
|
|
||||||
def _benchmarkMap(self, autotune):
|
def _benchmark_map(self, autotune):
|
||||||
k = 1024 * 1024
|
k = 1024 * 1024
|
||||||
dataset = dataset_ops.Dataset.from_tensors((np.random.rand(1, 4 * k),
|
dataset = dataset_ops.Dataset.from_tensors((np.random.rand(1, 4 * k),
|
||||||
np.random.rand(4 * k,
|
np.random.rand(4 * k,
|
||||||
@ -66,12 +66,12 @@ class AutotuneBenchmark(test.Benchmark):
|
|||||||
name="map" + ("_autotune" if autotune else ""))
|
name="map" + ("_autotune" if autotune else ""))
|
||||||
return np.median(deltas)
|
return np.median(deltas)
|
||||||
|
|
||||||
def benchmarkMapAndBatch(self):
|
def benchmark_map_and_batch(self):
|
||||||
a = self._benchmarkMapAndBatch(autotune=False)
|
a = self._benchmark_map_and_batch(autotune=False)
|
||||||
b = self._benchmarkMapAndBatch(autotune=True)
|
b = self._benchmark_map_and_batch(autotune=True)
|
||||||
print("speedup: %f" % (a / b))
|
print("speedup: %f" % (a / b))
|
||||||
|
|
||||||
def _benchmarkMapAndBatch(self, autotune):
|
def _benchmark_map_and_batch(self, autotune):
|
||||||
batch_size = 16
|
batch_size = 16
|
||||||
k = 1024 * 1024
|
k = 1024 * 1024
|
||||||
dataset = dataset_ops.Dataset.from_tensors((np.random.rand(1, 4 * k),
|
dataset = dataset_ops.Dataset.from_tensors((np.random.rand(1, 4 * k),
|
||||||
@ -104,12 +104,12 @@ class AutotuneBenchmark(test.Benchmark):
|
|||||||
name="map_and_batch" + ("_autotune" if autotune else ""))
|
name="map_and_batch" + ("_autotune" if autotune else ""))
|
||||||
return np.median(deltas)
|
return np.median(deltas)
|
||||||
|
|
||||||
def benchmarkInterleave(self):
|
def benchmark_interleave(self):
|
||||||
a = self._benchmarkInterleave(autotune=False)
|
a = self._benchmark_interleave(autotune=False)
|
||||||
b = self._benchmarkInterleave(autotune=True)
|
b = self._benchmark_interleave(autotune=True)
|
||||||
print("speedup: %f" % (a / b))
|
print("speedup: %f" % (a / b))
|
||||||
|
|
||||||
def _benchmarkInterleave(self, autotune):
|
def _benchmark_interleave(self, autotune):
|
||||||
k = 1024 * 1024
|
k = 1024 * 1024
|
||||||
dataset = dataset_ops.Dataset.from_tensors((np.random.rand(1, 4 * k),
|
dataset = dataset_ops.Dataset.from_tensors((np.random.rand(1, 4 * k),
|
||||||
np.random.rand(4 * k,
|
np.random.rand(4 * k,
|
||||||
@ -142,12 +142,12 @@ class AutotuneBenchmark(test.Benchmark):
|
|||||||
name="interleave" + ("_autotune" if autotune else ""))
|
name="interleave" + ("_autotune" if autotune else ""))
|
||||||
return np.median(deltas)
|
return np.median(deltas)
|
||||||
|
|
||||||
def benchmarkMapAndInterleave(self):
|
def benchmark_map_and_interleave(self):
|
||||||
a = self._benchmarkMapAndInterleave(autotune=False)
|
a = self._benchmark_map_and_interleave(autotune=False)
|
||||||
b = self._benchmarkMapAndInterleave(autotune=True)
|
b = self._benchmark_map_and_interleave(autotune=True)
|
||||||
print("speedup: %f" % (a / b))
|
print("speedup: %f" % (a / b))
|
||||||
|
|
||||||
def _benchmarkMapAndInterleave(self, autotune):
|
def _benchmark_map_and_interleave(self, autotune):
|
||||||
k = 1024 * 1024
|
k = 1024 * 1024
|
||||||
a = (np.random.rand(1, 8 * k), np.random.rand(8 * k, 1))
|
a = (np.random.rand(1, 8 * k), np.random.rand(8 * k, 1))
|
||||||
b = (np.random.rand(1, 4 * k), np.random.rand(4 * k, 1))
|
b = (np.random.rand(1, 4 * k), np.random.rand(4 * k, 1))
|
||||||
|
@ -31,7 +31,7 @@ from tensorflow.python.platform import test
|
|||||||
class ChooseFastestBenchmark(test.Benchmark):
|
class ChooseFastestBenchmark(test.Benchmark):
|
||||||
"""Benchmarks for static optimizations."""
|
"""Benchmarks for static optimizations."""
|
||||||
|
|
||||||
def benchmarkChooseFastest(self):
|
def benchmark_choose_fastest(self):
|
||||||
|
|
||||||
dataset = dataset_ops.Dataset.range(1000**2).repeat()
|
dataset = dataset_ops.Dataset.range(1000**2).repeat()
|
||||||
options = dataset_ops.Options()
|
options = dataset_ops.Options()
|
||||||
@ -46,7 +46,7 @@ class ChooseFastestBenchmark(test.Benchmark):
|
|||||||
self._benchmark(batch_map_dataset, "batch_map_dataset")
|
self._benchmark(batch_map_dataset, "batch_map_dataset")
|
||||||
self._benchmark(merge_dataset, "merge_dataset")
|
self._benchmark(merge_dataset, "merge_dataset")
|
||||||
|
|
||||||
def benchmarkChooseFastestFirstNIterations(self):
|
def benchmark_choose_fastest_first_n_iterations(self):
|
||||||
|
|
||||||
dataset = dataset_ops.Dataset.range(1000**2).repeat()
|
dataset = dataset_ops.Dataset.range(1000**2).repeat()
|
||||||
options = dataset_ops.Options()
|
options = dataset_ops.Options()
|
||||||
@ -58,11 +58,11 @@ class ChooseFastestBenchmark(test.Benchmark):
|
|||||||
merge_dataset = optimization._ChooseFastestDataset( # pylint: disable=protected-access
|
merge_dataset = optimization._ChooseFastestDataset( # pylint: disable=protected-access
|
||||||
[batch_map_dataset, map_batch_dataset])
|
[batch_map_dataset, map_batch_dataset])
|
||||||
|
|
||||||
self._benchmarkFirstN(map_batch_dataset, "map_batch_dataset")
|
self._benchmark_first_n(map_batch_dataset, "map_batch_dataset")
|
||||||
self._benchmarkFirstN(batch_map_dataset, "batch_map_dataset")
|
self._benchmark_first_n(batch_map_dataset, "batch_map_dataset")
|
||||||
self._benchmarkFirstN(merge_dataset, "merge_dataset")
|
self._benchmark_first_n(merge_dataset, "merge_dataset")
|
||||||
|
|
||||||
def _benchmarkFirstN(self, dataset, name):
|
def _benchmark_first_n(self, dataset, name):
|
||||||
n = 10 # The default num_experiments for ChooseFastestDataset
|
n = 10 # The default num_experiments for ChooseFastestDataset
|
||||||
iterator = dataset_ops.make_one_shot_iterator(dataset)
|
iterator = dataset_ops.make_one_shot_iterator(dataset)
|
||||||
next_element = iterator.get_next()
|
next_element = iterator.get_next()
|
||||||
|
@ -53,7 +53,7 @@ class ChooseFastestBranchBenchmark(benchmark_base.DatasetBenchmarkBase):
|
|||||||
|
|
||||||
return self.make_benchmark_datasets(dataset, branch_0, branch_1, 100)
|
return self.make_benchmark_datasets(dataset, branch_0, branch_1, 100)
|
||||||
|
|
||||||
def benchmarkChooseFastest(self):
|
def benchmark_choose_fastest(self):
|
||||||
map_batch, batch_map, choose_fastest = self.make_simple_benchmark_datasets()
|
map_batch, batch_map, choose_fastest = self.make_simple_benchmark_datasets()
|
||||||
|
|
||||||
def benchmark(dataset, name):
|
def benchmark(dataset, name):
|
||||||
@ -63,7 +63,7 @@ class ChooseFastestBranchBenchmark(benchmark_base.DatasetBenchmarkBase):
|
|||||||
benchmark(batch_map, "batch_map_dataset")
|
benchmark(batch_map, "batch_map_dataset")
|
||||||
benchmark(choose_fastest, "choose_fastest_dataset")
|
benchmark(choose_fastest, "choose_fastest_dataset")
|
||||||
|
|
||||||
def benchmarkChooseFastestFirstNIterations(self):
|
def benchmark_choose_fastest_first_n_iterations(self):
|
||||||
|
|
||||||
map_batch, batch_map, choose_fastest = self.make_simple_benchmark_datasets()
|
map_batch, batch_map, choose_fastest = self.make_simple_benchmark_datasets()
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ class ChooseFastestBranchBenchmark(benchmark_base.DatasetBenchmarkBase):
|
|||||||
benchmark(batch_map, "batch_map_dataset")
|
benchmark(batch_map, "batch_map_dataset")
|
||||||
benchmark(choose_fastest, "choose_fastest_dataset")
|
benchmark(choose_fastest, "choose_fastest_dataset")
|
||||||
|
|
||||||
def benchmarkWithInputSkew(self):
|
def benchmark_with_input_skew(self):
|
||||||
|
|
||||||
def make_dataset(time_us, num_elements):
|
def make_dataset(time_us, num_elements):
|
||||||
return dataset_ops.Dataset.range(num_elements).apply(sleep.sleep(time_us))
|
return dataset_ops.Dataset.range(num_elements).apply(sleep.sleep(time_us))
|
||||||
|
@ -41,7 +41,7 @@ class CsvDatasetBenchmark(test.Benchmark):
|
|||||||
FLOAT_VAL = '1.23456E12'
|
FLOAT_VAL = '1.23456E12'
|
||||||
STR_VAL = string.ascii_letters * 10
|
STR_VAL = string.ascii_letters * 10
|
||||||
|
|
||||||
def _setUp(self, str_val):
|
def _set_up(self, str_val):
|
||||||
# Since this isn't test.TestCase, have to manually create a test dir
|
# Since this isn't test.TestCase, have to manually create a test dir
|
||||||
gfile.MakeDirs(googletest.GetTempDir())
|
gfile.MakeDirs(googletest.GetTempDir())
|
||||||
self._temp_dir = tempfile.mkdtemp(dir=googletest.GetTempDir())
|
self._temp_dir = tempfile.mkdtemp(dir=googletest.GetTempDir())
|
||||||
@ -58,10 +58,10 @@ class CsvDatasetBenchmark(test.Benchmark):
|
|||||||
f.write('\n'.join([row for _ in range(100)]))
|
f.write('\n'.join([row for _ in range(100)]))
|
||||||
self._filenames.append(fn)
|
self._filenames.append(fn)
|
||||||
|
|
||||||
def _tearDown(self):
|
def _tear_down(self):
|
||||||
gfile.DeleteRecursively(self._temp_dir)
|
gfile.DeleteRecursively(self._temp_dir)
|
||||||
|
|
||||||
def _runBenchmark(self, dataset, num_cols, prefix):
|
def _run_benchmark(self, dataset, num_cols, prefix):
|
||||||
dataset = dataset.skip(self._num_per_iter - 1)
|
dataset = dataset.skip(self._num_per_iter - 1)
|
||||||
options = dataset_ops.Options()
|
options = dataset_ops.Options()
|
||||||
options.experimental_optimization.apply_default_optimizations = False
|
options.experimental_optimization.apply_default_optimizations = False
|
||||||
@ -87,45 +87,45 @@ class CsvDatasetBenchmark(test.Benchmark):
|
|||||||
wall_time=median_wall_time,
|
wall_time=median_wall_time,
|
||||||
name='%s_with_cols_%d' % (prefix, num_cols))
|
name='%s_with_cols_%d' % (prefix, num_cols))
|
||||||
|
|
||||||
def benchmarkMapWithFloats(self):
|
def benchmark_map_with_floats(self):
|
||||||
self._setUp(self.FLOAT_VAL)
|
self._set_up(self.FLOAT_VAL)
|
||||||
for i in range(len(self._filenames)):
|
for i in range(len(self._filenames)):
|
||||||
num_cols = self._num_cols[i]
|
num_cols = self._num_cols[i]
|
||||||
kwargs = {'record_defaults': [[0.0]] * num_cols}
|
kwargs = {'record_defaults': [[0.0]] * num_cols}
|
||||||
dataset = core_readers.TextLineDataset(self._filenames[i]).repeat()
|
dataset = core_readers.TextLineDataset(self._filenames[i]).repeat()
|
||||||
dataset = dataset.map(lambda l: parsing_ops.decode_csv(l, **kwargs)) # pylint: disable=cell-var-from-loop
|
dataset = dataset.map(lambda l: parsing_ops.decode_csv(l, **kwargs)) # pylint: disable=cell-var-from-loop
|
||||||
self._runBenchmark(dataset, num_cols, 'csv_float_map_decode_csv')
|
self._run_benchmark(dataset, num_cols, 'csv_float_map_decode_csv')
|
||||||
self._tearDown()
|
self._tear_down()
|
||||||
|
|
||||||
def benchmarkMapWithStrings(self):
|
def benchmark_map_with_strings(self):
|
||||||
self._setUp(self.STR_VAL)
|
self._set_up(self.STR_VAL)
|
||||||
for i in range(len(self._filenames)):
|
for i in range(len(self._filenames)):
|
||||||
num_cols = self._num_cols[i]
|
num_cols = self._num_cols[i]
|
||||||
kwargs = {'record_defaults': [['']] * num_cols}
|
kwargs = {'record_defaults': [['']] * num_cols}
|
||||||
dataset = core_readers.TextLineDataset(self._filenames[i]).repeat()
|
dataset = core_readers.TextLineDataset(self._filenames[i]).repeat()
|
||||||
dataset = dataset.map(lambda l: parsing_ops.decode_csv(l, **kwargs)) # pylint: disable=cell-var-from-loop
|
dataset = dataset.map(lambda l: parsing_ops.decode_csv(l, **kwargs)) # pylint: disable=cell-var-from-loop
|
||||||
self._runBenchmark(dataset, num_cols, 'csv_strings_map_decode_csv')
|
self._run_benchmark(dataset, num_cols, 'csv_strings_map_decode_csv')
|
||||||
self._tearDown()
|
self._tear_down()
|
||||||
|
|
||||||
def benchmarkCsvDatasetWithFloats(self):
|
def benchmark_csv_dataset_with_floats(self):
|
||||||
self._setUp(self.FLOAT_VAL)
|
self._set_up(self.FLOAT_VAL)
|
||||||
for i in range(len(self._filenames)):
|
for i in range(len(self._filenames)):
|
||||||
num_cols = self._num_cols[i]
|
num_cols = self._num_cols[i]
|
||||||
kwargs = {'record_defaults': [[0.0]] * num_cols}
|
kwargs = {'record_defaults': [[0.0]] * num_cols}
|
||||||
dataset = core_readers.TextLineDataset(self._filenames[i]).repeat()
|
dataset = core_readers.TextLineDataset(self._filenames[i]).repeat()
|
||||||
dataset = readers.CsvDataset(self._filenames[i], **kwargs).repeat() # pylint: disable=cell-var-from-loop
|
dataset = readers.CsvDataset(self._filenames[i], **kwargs).repeat() # pylint: disable=cell-var-from-loop
|
||||||
self._runBenchmark(dataset, num_cols, 'csv_float_fused_dataset')
|
self._run_benchmark(dataset, num_cols, 'csv_float_fused_dataset')
|
||||||
self._tearDown()
|
self._tear_down()
|
||||||
|
|
||||||
def benchmarkCsvDatasetWithStrings(self):
|
def benchmark_csv_dataset_with_strings(self):
|
||||||
self._setUp(self.STR_VAL)
|
self._set_up(self.STR_VAL)
|
||||||
for i in range(len(self._filenames)):
|
for i in range(len(self._filenames)):
|
||||||
num_cols = self._num_cols[i]
|
num_cols = self._num_cols[i]
|
||||||
kwargs = {'record_defaults': [['']] * num_cols}
|
kwargs = {'record_defaults': [['']] * num_cols}
|
||||||
dataset = core_readers.TextLineDataset(self._filenames[i]).repeat()
|
dataset = core_readers.TextLineDataset(self._filenames[i]).repeat()
|
||||||
dataset = readers.CsvDataset(self._filenames[i], **kwargs).repeat() # pylint: disable=cell-var-from-loop
|
dataset = readers.CsvDataset(self._filenames[i], **kwargs).repeat() # pylint: disable=cell-var-from-loop
|
||||||
self._runBenchmark(dataset, num_cols, 'csv_strings_fused_dataset')
|
self._run_benchmark(dataset, num_cols, 'csv_strings_fused_dataset')
|
||||||
self._tearDown()
|
self._tear_down()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test.main()
|
test.main()
|
||||||
|
@ -40,7 +40,7 @@ _NUMPY_RANDOM_SEED = 42
|
|||||||
class MapAndBatchBenchmark(test.Benchmark):
|
class MapAndBatchBenchmark(test.Benchmark):
|
||||||
"""Benchmarks for `tf.data.experimental.map_and_batch()`."""
|
"""Benchmarks for `tf.data.experimental.map_and_batch()`."""
|
||||||
|
|
||||||
def benchmarkMapAndBatch(self):
|
def benchmark_map_and_batch(self):
|
||||||
"""Measures the performance of parallelized batching."""
|
"""Measures the performance of parallelized batching."""
|
||||||
shapes = [(), (10,), (10, 10), (10, 10, 10), (224, 224, 3)]
|
shapes = [(), (10,), (10, 10), (10, 10, 10), (224, 224, 3)]
|
||||||
batch_size_values = [1, 32, 64, 128, 1024]
|
batch_size_values = [1, 32, 64, 128, 1024]
|
||||||
@ -94,7 +94,7 @@ class MapAndBatchBenchmark(test.Benchmark):
|
|||||||
iters=iters, wall_time=median_wall_time,
|
iters=iters, wall_time=median_wall_time,
|
||||||
name="num_elements_%d_batch_size_%d" % (np.prod(shape), batch_size))
|
name="num_elements_%d_batch_size_%d" % (np.prod(shape), batch_size))
|
||||||
|
|
||||||
def benchmarkMapAndBatchChainingVersusFusing(self):
|
def benchmark_map_and_batch_chaining_versus_fusing(self):
|
||||||
"""Compares the performance of chaining and fusing map and batch.
|
"""Compares the performance of chaining and fusing map and batch.
|
||||||
|
|
||||||
NOTE: It is recommended to build the benchmark with
|
NOTE: It is recommended to build the benchmark with
|
||||||
|
@ -49,7 +49,7 @@ class MapDefunBenchmark(test.Benchmark):
|
|||||||
wall_time=mean_us,
|
wall_time=mean_us,
|
||||||
extras={"examples_per_sec": num_iters / (end - start)})
|
extras={"examples_per_sec": num_iters / (end - start)})
|
||||||
|
|
||||||
def benchmarkDefunVsMapFn(self):
|
def benchmark_defun_vs_map_fn(self):
|
||||||
"""Benchmarks to compare the performance of MapDefun vs tf.map_fn."""
|
"""Benchmarks to compare the performance of MapDefun vs tf.map_fn."""
|
||||||
|
|
||||||
@function.defun(input_signature=[tensor_spec.TensorSpec([], dtypes.int32)])
|
@function.defun(input_signature=[tensor_spec.TensorSpec([], dtypes.int32)])
|
||||||
|
@ -144,32 +144,32 @@ class MapVectorizationBenchmark(test.Benchmark):
|
|||||||
(unoptimized_time / optimized_time)))
|
(unoptimized_time / optimized_time)))
|
||||||
|
|
||||||
# Known cheap functions
|
# Known cheap functions
|
||||||
def benchmarkIdentity(self):
|
def benchmark_identity(self):
|
||||||
self._benchmark_helper(lambda *args: [array_ops.identity(x) for x in args],
|
self._benchmark_helper(lambda *args: [array_ops.identity(x) for x in args],
|
||||||
"identity")
|
"identity")
|
||||||
|
|
||||||
def benchmarkAddConst(self):
|
def benchmark_add_const(self):
|
||||||
self._benchmark_helper(lambda *args: [x + 1 for x in args], "add_const")
|
self._benchmark_helper(lambda *args: [x + 1 for x in args], "add_const")
|
||||||
|
|
||||||
def benchmarkReturnConst(self):
|
def benchmark_return_const(self):
|
||||||
self._benchmark_helper(lambda *args: [constant_op.constant(2)], "ret_const")
|
self._benchmark_helper(lambda *args: [constant_op.constant(2)], "ret_const")
|
||||||
|
|
||||||
def benchmarkSelect(self):
|
def benchmark_select(self):
|
||||||
self._benchmark_helper(lambda *args: args[0], "select")
|
self._benchmark_helper(lambda *args: args[0], "select")
|
||||||
|
|
||||||
def benchmarkCast(self):
|
def benchmark_cast(self):
|
||||||
self._benchmark_helper(
|
self._benchmark_helper(
|
||||||
lambda *args: [math_ops.cast(x, dtypes.float32) for x in args], "cast")
|
lambda *args: [math_ops.cast(x, dtypes.float32) for x in args], "cast")
|
||||||
|
|
||||||
def benchmarkReshape(self):
|
def benchmark_reshape(self):
|
||||||
self._benchmark_helper(
|
self._benchmark_helper(
|
||||||
lambda *args: [array_ops.reshape(x, (-1, 30)) for x in args], "reshape")
|
lambda *args: [array_ops.reshape(x, (-1, 30)) for x in args], "reshape")
|
||||||
|
|
||||||
def benchmarkDecodeCSV(self):
|
def benchmark_decode_csv(self):
|
||||||
csv_fn, csv_factory = _generate_csv_test_case()
|
csv_fn, csv_factory = _generate_csv_test_case()
|
||||||
self._benchmark_helper(csv_fn, "decode_csv", lambda: [csv_factory()])
|
self._benchmark_helper(csv_fn, "decode_csv", lambda: [csv_factory()])
|
||||||
|
|
||||||
def benchmarkParseSingleExample(self):
|
def benchmark_parse_single_example(self):
|
||||||
# NOTE: Since we haven't implemented a vectorizer for "SerializeSparse",
|
# NOTE: Since we haven't implemented a vectorizer for "SerializeSparse",
|
||||||
# this function is only naively vectorized.
|
# this function is only naively vectorized.
|
||||||
parse_fn, parse_factory = _generate_parse_single_example_test_case()
|
parse_fn, parse_factory = _generate_parse_single_example_test_case()
|
||||||
|
@ -35,7 +35,7 @@ from tensorflow.python.platform import test
|
|||||||
class MatchingFilesBenchmark(test.Benchmark):
|
class MatchingFilesBenchmark(test.Benchmark):
|
||||||
"""Benchmark for the experimental `MatchingFilesDataset`."""
|
"""Benchmark for the experimental `MatchingFilesDataset`."""
|
||||||
|
|
||||||
def benchmarkNestedDirectories(self):
|
def benchmark_nested_directories(self):
|
||||||
tmp_dir = tempfile.mkdtemp()
|
tmp_dir = tempfile.mkdtemp()
|
||||||
width = 500
|
width = 500
|
||||||
depth = 10
|
depth = 10
|
||||||
|
@ -32,15 +32,15 @@ from tensorflow.python.platform import test
|
|||||||
class OptimizationBenchmark(test.Benchmark):
|
class OptimizationBenchmark(test.Benchmark):
|
||||||
"""Benchmarks for static optimizations."""
|
"""Benchmarks for static optimizations."""
|
||||||
|
|
||||||
def benchmarkMapFusion(self):
|
def benchmark_map_fusion(self):
|
||||||
"""Evaluates performance map of fusion."""
|
"""Evaluates performance map of fusion."""
|
||||||
|
|
||||||
chain_lengths = [0, 1, 2, 5, 10, 20, 50]
|
chain_lengths = [0, 1, 2, 5, 10, 20, 50]
|
||||||
for chain_length in chain_lengths:
|
for chain_length in chain_lengths:
|
||||||
self._benchmarkMapFusion(chain_length, False)
|
self._benchmark_map_fusion(chain_length, False)
|
||||||
self._benchmarkMapFusion(chain_length, True)
|
self._benchmark_map_fusion(chain_length, True)
|
||||||
|
|
||||||
def _benchmarkMapFusion(self, chain_length, optimize_dataset):
|
def _benchmark_map_fusion(self, chain_length, optimize_dataset):
|
||||||
with ops.Graph().as_default():
|
with ops.Graph().as_default():
|
||||||
dataset = dataset_ops.Dataset.from_tensors(0).repeat(None)
|
dataset = dataset_ops.Dataset.from_tensors(0).repeat(None)
|
||||||
for _ in range(chain_length):
|
for _ in range(chain_length):
|
||||||
@ -73,15 +73,15 @@ class OptimizationBenchmark(test.Benchmark):
|
|||||||
name="map_fusion_{}_chain_length_{}".format(
|
name="map_fusion_{}_chain_length_{}".format(
|
||||||
opt_mark, chain_length))
|
opt_mark, chain_length))
|
||||||
|
|
||||||
def benchmarkMapAndFilterFusion(self):
|
def benchmark_map_and_filter_fusion(self):
|
||||||
"""Evaluates performance map of fusion."""
|
"""Evaluates performance map of fusion."""
|
||||||
|
|
||||||
chain_lengths = [0, 1, 2, 5, 10, 20, 50]
|
chain_lengths = [0, 1, 2, 5, 10, 20, 50]
|
||||||
for chain_length in chain_lengths:
|
for chain_length in chain_lengths:
|
||||||
self._benchmarkMapAndFilterFusion(chain_length, False)
|
self._benchmark_map_and_filter_fusion(chain_length, False)
|
||||||
self._benchmarkMapAndFilterFusion(chain_length, True)
|
self._benchmark_map_and_filter_fusion(chain_length, True)
|
||||||
|
|
||||||
def _benchmarkMapAndFilterFusion(self, chain_length, optimize_dataset):
|
def _benchmark_map_and_filter_fusion(self, chain_length, optimize_dataset):
|
||||||
with ops.Graph().as_default():
|
with ops.Graph().as_default():
|
||||||
dataset = dataset_ops.Dataset.from_tensors(0).repeat(None)
|
dataset = dataset_ops.Dataset.from_tensors(0).repeat(None)
|
||||||
for _ in range(chain_length):
|
for _ in range(chain_length):
|
||||||
@ -116,13 +116,13 @@ class OptimizationBenchmark(test.Benchmark):
|
|||||||
|
|
||||||
# This benchmark compares the performance of pipeline with multiple chained
|
# This benchmark compares the performance of pipeline with multiple chained
|
||||||
# filter with and without filter fusion.
|
# filter with and without filter fusion.
|
||||||
def benchmarkFilterFusion(self):
|
def benchmark_filter_fusion(self):
|
||||||
chain_lengths = [0, 1, 2, 5, 10, 20, 50]
|
chain_lengths = [0, 1, 2, 5, 10, 20, 50]
|
||||||
for chain_length in chain_lengths:
|
for chain_length in chain_lengths:
|
||||||
self._benchmarkFilterFusion(chain_length, False)
|
self._benchmark_filter_fusion(chain_length, False)
|
||||||
self._benchmarkFilterFusion(chain_length, True)
|
self._benchmark_filter_fusion(chain_length, True)
|
||||||
|
|
||||||
def _benchmarkFilterFusion(self, chain_length, optimize_dataset):
|
def _benchmark_filter_fusion(self, chain_length, optimize_dataset):
|
||||||
with ops.Graph().as_default():
|
with ops.Graph().as_default():
|
||||||
dataset = dataset_ops.Dataset.from_tensors(5).repeat(None)
|
dataset = dataset_ops.Dataset.from_tensors(5).repeat(None)
|
||||||
for _ in range(chain_length):
|
for _ in range(chain_length):
|
||||||
|
@ -56,7 +56,7 @@ def _time_resampling(data_np, target_dist, init_dist, num_to_sample): # pylint:
|
|||||||
class RejectionResampleBenchmark(test.Benchmark):
|
class RejectionResampleBenchmark(test.Benchmark):
|
||||||
"""Benchmarks for `tf.data.experimental.rejection_resample()`."""
|
"""Benchmarks for `tf.data.experimental.rejection_resample()`."""
|
||||||
|
|
||||||
def benchmarkResamplePerformance(self):
|
def benchmark_resample_performance(self):
|
||||||
init_dist = [0.25, 0.25, 0.25, 0.25]
|
init_dist = [0.25, 0.25, 0.25, 0.25]
|
||||||
target_dist = [0.0, 0.0, 0.0, 1.0]
|
target_dist = [0.0, 0.0, 0.0, 1.0]
|
||||||
num_classes = len(init_dist)
|
num_classes = len(init_dist)
|
||||||
|
@ -33,7 +33,7 @@ from tensorflow.python.platform import test
|
|||||||
class UnbatchBenchmark(test.Benchmark):
|
class UnbatchBenchmark(test.Benchmark):
|
||||||
"""Benchmarks for `tf.data.experimental.unbatch()`."""
|
"""Benchmarks for `tf.data.experimental.unbatch()`."""
|
||||||
|
|
||||||
def benchmarkNativeUnbatch(self):
|
def benchmark_native_unbatch(self):
|
||||||
batch_sizes = [1, 2, 5, 10, 20, 50]
|
batch_sizes = [1, 2, 5, 10, 20, 50]
|
||||||
elems_per_trial = 10000
|
elems_per_trial = 10000
|
||||||
with ops.Graph().as_default():
|
with ops.Graph().as_default():
|
||||||
@ -70,7 +70,7 @@ class UnbatchBenchmark(test.Benchmark):
|
|||||||
# Include a benchmark of the previous `unbatch()` implementation that uses
|
# Include a benchmark of the previous `unbatch()` implementation that uses
|
||||||
# a composition of more primitive ops. Eventually we'd hope to generate code
|
# a composition of more primitive ops. Eventually we'd hope to generate code
|
||||||
# that is as good in both cases.
|
# that is as good in both cases.
|
||||||
def benchmarkOldUnbatchImplementation(self):
|
def benchmark_old_unbatch_implementation(self):
|
||||||
batch_sizes = [1, 2, 5, 10, 20, 50]
|
batch_sizes = [1, 2, 5, 10, 20, 50]
|
||||||
elems_per_trial = 10000
|
elems_per_trial = 10000
|
||||||
with ops.Graph().as_default():
|
with ops.Graph().as_default():
|
||||||
|
Loading…
Reference in New Issue
Block a user