[Docs] Benchmark docs (#5360)

* first doc version

* add benchmark docs

* fix typos

* improve README

* Update docs/source/benchmarks.rst

Co-authored-by: Lysandre Debut <lysandre@huggingface.co>

* fix naming and docs

Co-authored-by: Lysandre Debut <lysandre@huggingface.co>
This commit is contained in:
Patrick von Platen
2020-06-29 16:08:57 +02:00
committed by GitHub
parent 482c9178d3
commit 4bcc35cd69
10 changed files with 373 additions and 109 deletions

View File

@@ -10,7 +10,7 @@ from .utils import require_tf
if is_tf_available():
import tensorflow as tf
from transformers import TensorflowBenchmark, TensorflowBenchmarkArguments
from transformers import TensorFlowBenchmark, TensorFlowBenchmarkArguments
@require_tf
@@ -23,7 +23,7 @@ class TFBenchmarkTest(unittest.TestCase):
def test_inference_no_configs_eager(self):
MODEL_ID = "sshleifer/tiny-gpt2"
benchmark_args = TensorflowBenchmarkArguments(
benchmark_args = TensorFlowBenchmarkArguments(
models=[MODEL_ID],
training=False,
no_inference=False,
@@ -32,14 +32,14 @@ class TFBenchmarkTest(unittest.TestCase):
eager_mode=True,
no_multi_process=True,
)
benchmark = TensorflowBenchmark(benchmark_args)
benchmark = TensorFlowBenchmark(benchmark_args)
results = benchmark.run()
self.check_results_dict_not_empty(results.time_inference_result)
self.check_results_dict_not_empty(results.memory_inference_result)
def test_inference_no_configs_only_pretrain(self):
MODEL_ID = "sshleifer/tiny-distilbert-base-uncased-finetuned-sst-2-english"
benchmark_args = TensorflowBenchmarkArguments(
benchmark_args = TensorFlowBenchmarkArguments(
models=[MODEL_ID],
training=False,
no_inference=False,
@@ -48,14 +48,14 @@ class TFBenchmarkTest(unittest.TestCase):
no_multi_process=True,
only_pretrain_model=True,
)
benchmark = TensorflowBenchmark(benchmark_args)
benchmark = TensorFlowBenchmark(benchmark_args)
results = benchmark.run()
self.check_results_dict_not_empty(results.time_inference_result)
self.check_results_dict_not_empty(results.memory_inference_result)
def test_inference_no_configs_graph(self):
MODEL_ID = "sshleifer/tiny-gpt2"
benchmark_args = TensorflowBenchmarkArguments(
benchmark_args = TensorFlowBenchmarkArguments(
models=[MODEL_ID],
training=False,
no_inference=False,
@@ -63,7 +63,7 @@ class TFBenchmarkTest(unittest.TestCase):
batch_sizes=[1],
no_multi_process=True,
)
benchmark = TensorflowBenchmark(benchmark_args)
benchmark = TensorFlowBenchmark(benchmark_args)
results = benchmark.run()
self.check_results_dict_not_empty(results.time_inference_result)
self.check_results_dict_not_empty(results.memory_inference_result)
@@ -71,7 +71,7 @@ class TFBenchmarkTest(unittest.TestCase):
def test_inference_with_configs_eager(self):
MODEL_ID = "sshleifer/tiny-gpt2"
config = AutoConfig.from_pretrained(MODEL_ID)
benchmark_args = TensorflowBenchmarkArguments(
benchmark_args = TensorFlowBenchmarkArguments(
models=[MODEL_ID],
training=False,
no_inference=False,
@@ -80,7 +80,7 @@ class TFBenchmarkTest(unittest.TestCase):
eager_mode=True,
no_multi_process=True,
)
benchmark = TensorflowBenchmark(benchmark_args, [config])
benchmark = TensorFlowBenchmark(benchmark_args, [config])
results = benchmark.run()
self.check_results_dict_not_empty(results.time_inference_result)
self.check_results_dict_not_empty(results.memory_inference_result)
@@ -88,7 +88,7 @@ class TFBenchmarkTest(unittest.TestCase):
def test_inference_with_configs_graph(self):
MODEL_ID = "sshleifer/tiny-gpt2"
config = AutoConfig.from_pretrained(MODEL_ID)
benchmark_args = TensorflowBenchmarkArguments(
benchmark_args = TensorFlowBenchmarkArguments(
models=[MODEL_ID],
training=False,
no_inference=False,
@@ -96,7 +96,7 @@ class TFBenchmarkTest(unittest.TestCase):
batch_sizes=[1],
no_multi_process=True,
)
benchmark = TensorflowBenchmark(benchmark_args, [config])
benchmark = TensorFlowBenchmark(benchmark_args, [config])
results = benchmark.run()
self.check_results_dict_not_empty(results.time_inference_result)
self.check_results_dict_not_empty(results.memory_inference_result)
@@ -104,7 +104,7 @@ class TFBenchmarkTest(unittest.TestCase):
def test_inference_encoder_decoder_with_configs(self):
MODEL_ID = "patrickvonplaten/t5-tiny-random"
config = AutoConfig.from_pretrained(MODEL_ID)
benchmark_args = TensorflowBenchmarkArguments(
benchmark_args = TensorFlowBenchmarkArguments(
models=[MODEL_ID],
training=False,
no_inference=False,
@@ -112,7 +112,7 @@ class TFBenchmarkTest(unittest.TestCase):
batch_sizes=[1],
no_multi_process=True,
)
benchmark = TensorflowBenchmark(benchmark_args, configs=[config])
benchmark = TensorFlowBenchmark(benchmark_args, configs=[config])
results = benchmark.run()
self.check_results_dict_not_empty(results.time_inference_result)
self.check_results_dict_not_empty(results.memory_inference_result)
@@ -120,7 +120,7 @@ class TFBenchmarkTest(unittest.TestCase):
@unittest.skipIf(is_tf_available() and len(tf.config.list_physical_devices("GPU")) == 0, "Cannot do xla on CPU.")
def test_inference_no_configs_xla(self):
MODEL_ID = "sshleifer/tiny-gpt2"
benchmark_args = TensorflowBenchmarkArguments(
benchmark_args = TensorFlowBenchmarkArguments(
models=[MODEL_ID],
training=False,
no_inference=False,
@@ -129,7 +129,7 @@ class TFBenchmarkTest(unittest.TestCase):
use_xla=True,
no_multi_process=True,
)
benchmark = TensorflowBenchmark(benchmark_args)
benchmark = TensorFlowBenchmark(benchmark_args)
results = benchmark.run()
self.check_results_dict_not_empty(results.time_inference_result)
self.check_results_dict_not_empty(results.memory_inference_result)
@@ -137,7 +137,7 @@ class TFBenchmarkTest(unittest.TestCase):
def test_save_csv_files(self):
MODEL_ID = "sshleifer/tiny-gpt2"
with tempfile.TemporaryDirectory() as tmp_dir:
benchmark_args = TensorflowBenchmarkArguments(
benchmark_args = TensorFlowBenchmarkArguments(
models=[MODEL_ID],
no_inference=False,
save_to_csv=True,
@@ -148,7 +148,7 @@ class TFBenchmarkTest(unittest.TestCase):
env_info_csv_file=os.path.join(tmp_dir, "env.csv"),
no_multi_process=True,
)
benchmark = TensorflowBenchmark(benchmark_args)
benchmark = TensorFlowBenchmark(benchmark_args)
benchmark.run()
self.assertTrue(Path(os.path.join(tmp_dir, "inf_time.csv")).exists())
self.assertTrue(Path(os.path.join(tmp_dir, "inf_mem.csv")).exists())
@@ -164,7 +164,7 @@ class TFBenchmarkTest(unittest.TestCase):
self.assertTrue(hasattr(summary, "total"))
with tempfile.TemporaryDirectory() as tmp_dir:
benchmark_args = TensorflowBenchmarkArguments(
benchmark_args = TensorFlowBenchmarkArguments(
models=[MODEL_ID],
no_inference=False,
sequence_lengths=[8],
@@ -175,7 +175,7 @@ class TFBenchmarkTest(unittest.TestCase):
eager_mode=True,
no_multi_process=True,
)
benchmark = TensorflowBenchmark(benchmark_args)
benchmark = TensorFlowBenchmark(benchmark_args)
result = benchmark.run()
_check_summary_is_not_empty(result.inference_summary)
self.assertTrue(Path(os.path.join(tmp_dir, "log.txt")).exists())