pytorch/benchmarks/dynamo
Sam Larsen 966ebd2e24 Add --warm-start-latency to benchmark harness (#125353)
Summary: This change introduces a new flagg to perform a "warm start" test from the benchmark harness. The idea is to test a model twice: first with a fresh inductor cache (i.e., a "cold start"), and then a second run in a fresh process with the cache available (i.e. a "warm start"). We can later add this mode to CI runs to collect compile times for warm start.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/125353
Approved by: https://github.com/eellison, https://github.com/desertfire
2024-05-09 21:12:15 +00:00
..
ci_expected_accuracy [dynamo][prepare for nn module guards] Guard nn modules for a few benchmarks (#125324) 2024-05-04 22:08:56 +00:00
microbenchmarks [inductor] Refactor runtime files into torch._inductor.runtime (part 3) (#124557) 2024-04-22 18:46:24 +00:00
__init__.py
all_torchbench_models_list.txt
benchmarks.py [BE]: enable ruff rules PLR1722 and PLW3301 (#109461) 2023-09-18 02:07:21 +00:00
check_accuracy.py
check_csv.py
check_graph_breaks.py
check_memory_compression_ratio.py
check_perf_csv.py [aotinductor] Add a perf smoke test for AOTInductor (#110972) 2023-10-11 13:30:05 +00:00
combine_csv.py [BE] Enable ruff's UP rules and autoformat benchmarks/ (#105429) 2023-07-19 04:46:37 +00:00
common.py Add --warm-start-latency to benchmark harness (#125353) 2024-05-09 21:12:15 +00:00
dist_util.py remove jit from dynamo benchmark (#113338) 2023-11-10 18:02:08 +00:00
distributed.py
expected_ci_perf_inductor_torchbench.csv
expected_ci_speedup_inductor_torchbench_cpu.csv [CI] Add initial inductor cpu smoketest for performance (#116456) 2024-02-21 20:04:50 +00:00
huggingface_models_list_cpu.txt
huggingface_models_list.txt
huggingface.py Enable in oss (#124031) 2024-04-19 20:28:55 +00:00
Makefile Fix build-deps in benchmarks/dynamo/Makefile (#114815) 2023-11-30 19:10:56 +00:00
parse_logs.py [BE] Enable ruff's UP rules and autoformat benchmarks/ (#105429) 2023-07-19 04:46:37 +00:00
README.md [doc] Rewrite benchmarks/dynamo/README.md (#115485) 2023-12-10 00:37:53 +00:00
run_all.sh
run_delta.sh
runner.py [BE]: Ruff - TRY401 - Avoid verbose exception logging (#125126) 2024-04-28 21:44:33 +00:00
summarize_perf.py [BE]: Enable RUF015 codebase wide (#115507) 2023-12-11 15:51:01 +00:00
test.py Fix torchbench errors (#122735) 2024-03-27 06:59:16 +00:00
timm_models_list_cpu.txt [CI] Update the pinned timm version (#108076) 2023-09-07 11:38:13 +00:00
timm_models_list.txt tune down batch-size for res2net to avoid OOM (#122977) 2024-03-30 03:54:53 +00:00
timm_models.py [dynamo][prepare for nn module guards] Guard nn modules for a few benchmarks (#125324) 2024-05-04 22:08:56 +00:00
torchbench_models_list_cpu.txt
torchbench_models_list.txt
torchbench.py [dynamo][prepare for nn module guards] Guard nn modules for a few benchmarks (#125324) 2024-05-04 22:08:56 +00:00
torchbench.yaml Force upsample to be float32 (#121324) 2024-04-24 23:14:41 +00:00
training_loss.py

torch.compile() Benchmarking

This directory contains benchmarking code for TorchDynamo and many backends including TorchInductor. It includes three main benchmark suites:

  • TorchBenchmark: A diverse set of models, initially seeded from highly cited research models as ranked by Papers With Code. See torchbench installation and torchbench.py for the low-level runner. Makefile also contains the commands needed to setup TorchBenchmark to match the versions used in PyTorch CI.

  • Models from HuggingFace: Primarily transformer models, with representative models chosen for each category available. The low-level runner (huggingface.py) automatically downloads and installs the needed dependencies on first run.

  • Models from TIMM: Primarily vision models, with representative models chosen for each category available. The low-level runner (timm_models.py) automatically downloads and installs the needed dependencies on first run.

GPU Performance Dashboard

Daily results from the benchmarks here are available in the TorchInductor Performance Dashboard, currently run on an NVIDIA A100 GPU.

The inductor-perf-test-nightly.yml workflow generates the data in the performance dashboard. If you have the needed permissions, you can benchmark your own branch on the PyTorch GitHub repo by:

  1. Select "Run workflow" in the top right of the workflow
  2. Select your branch you want to benchmark
  3. Choose the options (such as training vs inference)
  4. Click "Run workflow"
  5. Wait for the job to complete (4 to 12 hours depending on backlog)
  6. Go to the dashboard
  7. Select your branch and commit at the top of the dashboard

The dashboard compares two commits a "Base Commit" and a "New Commit". An entry such as 2.38x → 2.41x means that the performance improved from 2.38x in the base to 2.41x in the new commit. All performance results are normalized to eager mode PyTorch (1x), and higher is better.

CPU Performance Dashboard

The TorchInductor CPU Performance Dashboard is tracked on a GitHub issue and updated periodically.

Running Locally

Raw commands used to generate the data for the performance dashboards can be found here.

To summarize there are three scripts to run each set of benchmarks:

  • ./benchmarks/dynamo/torchbench.py ...
  • ./benchmarks/dynamo/huggingface.py ...
  • ./benchmarks/dynamo/timm_models.py ...

Each of these scripts takes the same set of arguments. The ones used by dashboards are:

  • --accuracy or --performance: selects between checking correctness and measuring speedup (both are run for dashboard).
  • --training or --inference: selects between measuring training or inference (both are run for dashboard).
  • --device=cuda or --device=cpu: selects device to measure.
  • --amp, --bfloat16, --float16, --float32: selects precision to use --amp is used for training and --bfloat16 for inference.
  • --cold-start-latency: disables caching to accurately measure compile times.
  • --backend=inductor: selects TorchInductor as the compiler backend to measure. Many more are available, see --help.
  • --output=<filename>.csv: where to write results to.
  • --dynamic-shapes --dynamic-batch-only: used when the dynamic config is enabled.
  • --disable-cudagraphs: used by configurations without cudagraphs enabled (default).
  • --freezing: enable additional inference-only optimizations.
  • --cpp-wrapper: enable C++ wrapper code to lower overheads.
  • TORCHINDUCTOR_MAX_AUTOTUNE=1 (environment variable): used to measure max-autotune mode, which is run weekly due to longer compile times.
  • --export-aot-inductor: benchmarks ahead-of-time compilation mode.
  • --total-partitions and --partition-id: used to parallel benchmarking across different machines.

For debugging you can run just a single benchmark by adding the --only=<NAME> flag.

A complete list of options can be seen by running each of the runners with the --help flag.

As an example, the commands to run first line of the dashboard (performance only) would be:

./benchmarks/dynamo/torchbench.py --performance --training --amp --backend=inductor --output=torchbench_training.csv
./benchmarks/dynamo/torchbench.py --performance --inference --bfloat16 --backend=inductor --output=torchbench_inference.csv

./benchmarks/dynamo/huggingface.py --performance --training --amp --backend=inductor --output=huggingface_training.csv
./benchmarks/dynamo/huggingface.py --performance --inference --bfloat16 --backend=inductor --output=huggingface_inference.csv

./benchmarks/dynamo/timm_models.py --performance --training --amp --backend=inductor --output=timm_models_training.csv
./benchmarks/dynamo/timm_models.py --performance --inference --bfloat16 --backend=inductor --output=timm_models_inference.csv