Name Date Size #Lines LOC

..--

README.mdH A D25-Apr-20252.5 KiB6849

audio_text_models.pyH A D25-Apr-20254.9 KiB158114

compare.pyH A D25-Apr-20252.1 KiB7665

functional_autograd_benchmark.pyH A D25-Apr-202510.4 KiB343264

ppl_models.pyH A D25-Apr-20253.4 KiB10464

torchaudio_models.pyH A D25-Apr-202525.8 KiB699611

torchvision_models.pyH A D25-Apr-202534.2 KiB958733

utils.pyH A D25-Apr-20254 KiB11981

vision_models.pyH A D25-Apr-20254 KiB141104

README.md

1# Benchmarking tool for the autograd API
2
3This folder contain a set of self-contained scripts that allows you to benchmark autograd with different common models.
4It is designed to run the benchmark before and after your change and will generate a table to share on the PR.
5
6To do so, you can use `functional_autograd_benchmark.py` to run the benchmarks before your change (using as output `before.txt`) and after your change (using as output `after.txt`).
7You can then use `compare.py` to get a markdown table comparing the two runs.
8
9The default arguments of `functional_autograd_benchmark.py` should be used in general. You can change them though to force a given device or force running even the (very) slow settings.
10
11### Sample usage
12
13```bash
14# Make sure you compile pytorch in release mode and with the same flags before/after
15export DEBUG=0
16# When running on CPU, it might be required to limit the number of cores to avoid oversubscription
17export OMP_NUM_THREADS=10
18
19# Compile pytorch with the base revision
20git checkout master
21python setup.py develop
22
23# Install dependencies:
24# Scipy is required by detr
25pip install scipy
26
27# Run the benchmark for the base
28# This will use the GPU if available.
29pushd benchmarks/functional_autograd_benchmark
30python functional_autograd_benchmark.py --output before.txt
31
32# Compile pytorch with your change
33popd
34git checkout your_feature_branch
35python setup.py develop
36
37# Run the benchmark for the new version
38pushd benchmarks/functional_autograd_benchmark
39python functional_autograd_benchmark.py --output after.txt
40
41# Get the markdown table that you can paste in your github PR
42python compare.py
43
44popd
45
46```
47
48### Files in this folder:
49- `functional_autograd_benchmark.py` is the main entry point to run the benchmark.
50- `compare.py` is the entry point to run the comparison script that generates a markdown table.
51- `torchaudio_models.py` and `torchvision_models.py`  contains code extracted from torchaudio and torchvision to be able to run the models without having a specific version of these libraries installed.
52- `ppl_models.py`, `vision_models.py` and `audio_text_models.py` contain all the getter functions used for the benchmark.
53
54
55### Benchmarking against `functorch`
56
57```bash
58# Install stable functorch:
59pip install functorch
60# or install from source:
61pip install git+https://github.com/pytorch/functorch
62
63# Run the benchmark for the base
64# This will use the GPU if available.
65pushd benchmarks/functional_autograd_benchmark
66python functional_autograd_benchmark.py --output bench-with-functorch.txt
67```
68