Skip to content

Commit 8a6257a

Browse files
committed
Workflow for benchmarks
1 parent 8ad2e1b commit 8a6257a

File tree

2 files changed

+93
-14
lines changed

2 files changed

+93
-14
lines changed

Diff for: .github/workflows/benchmarks.yaml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Benchmarks
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
paths:
8+
- src/torchcodec/*
9+
- benchmarks/*
10+
- .github/workflows/benchmarks.yaml
11+
12+
defaults:
13+
run:
14+
shell: bash -l -eo pipefail {0}
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
steps:
22+
- name: Check out repo
23+
uses: actions/checkout@v3
24+
- name: Setup conda env
25+
uses: conda-incubator/setup-miniconda@v2
26+
with:
27+
auto-update-conda: true
28+
miniconda-version: "latest"
29+
activate-environment: test
30+
python-version: '3.12'
31+
- name: Update pip
32+
run: python -m pip install --upgrade pip
33+
- name: Install dependencies and FFmpeg
34+
run: |
35+
# TODO: torchvision and torchaudio shouldn't be needed. They were only added
36+
# to silence an error as seen in https://github.com/pytorch/torchcodec/issues/203
37+
python -m pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cpu
38+
conda install "ffmpeg=7.0.1" pkg-config -c conda-forge
39+
ffmpeg -version
40+
- name: Build and install torchcodec
41+
run: |
42+
python -m pip install -e ".[dev]" --no-build-isolation -vvv
43+
- name: Test generic decoder benchmark
44+
run: |
45+
python benchmarks/decoders/benchmark_decoders.py --bm_video_speed_min_run_seconds 1
46+
- name: TEST README data geeneration benchmark
47+
run: |
48+
python benchmarks/decoders/generate_readme_data.py --test_run
49+

Diff for: benchmarks/decoders/generate_readme_data.py

+44-14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7+
import argparse
78
import json
89
import os
910
import platform
@@ -26,18 +27,48 @@
2627
def main() -> None:
2728
"""Benchmarks the performance of a few video decoders on synthetic videos"""
2829

30+
parser = argparse.ArgumentParser()
31+
parser.add_argument(
32+
"--test_run",
33+
help="Test run only; use small values for experiments to ensure everything works. Does not overwrite the data file.",
34+
action="store_true",
35+
)
36+
args = parser.parse_args()
37+
38+
# The logic is clearer internally if we invert the boolean. However, we want to
39+
# maintain the external default that a test run is off by default.
40+
data_generation_run = not args.test_run
41+
42+
if data_generation_run:
43+
resolutions = ["1280x720"]
44+
encodings = ["libx264"]
45+
patterns = ["mandelbrot"]
46+
fpses = [60]
47+
gop_sizes = [600]
48+
durations = [120]
49+
pix_fmts = ["yuv420p"]
50+
ffmpeg_path = "ffmpeg"
51+
min_runtime_seconds = 30
52+
53+
# These are the number of uniform seeks we do in the seek+decode benchmark.
54+
num_samples = 10
55+
else:
56+
resolutions = ["640x480"]
57+
encodings = ["libx264"]
58+
patterns = ["mandelbrot"]
59+
fpses = [30]
60+
gop_sizes = [20]
61+
durations = [10] # if this goes too low, we hit EOF errors in some decoders
62+
pix_fmts = ["yuv420p"]
63+
ffmpeg_path = "ffmpeg"
64+
min_runtime_seconds = 1
65+
66+
num_samples = 4
67+
2968
videos_dir_path = "/tmp/torchcodec_benchmarking_videos"
3069
shutil.rmtree(videos_dir_path, ignore_errors=True)
3170
os.makedirs(videos_dir_path)
3271

33-
resolutions = ["1280x720"]
34-
encodings = ["libx264"]
35-
patterns = ["mandelbrot"]
36-
fpses = [60]
37-
gop_sizes = [600]
38-
durations = [120]
39-
pix_fmts = ["yuv420p"]
40-
ffmpeg_path = "ffmpeg"
4172
generate_videos(
4273
resolutions,
4374
encodings,
@@ -61,15 +92,13 @@ def main() -> None:
6192
decoder_dict["TorchAudio"] = TorchAudioDecoder()
6293
decoder_dict["Decord"] = DecordAccurateBatch()
6394

64-
# These are the number of uniform seeks we do in the seek+decode benchmark.
65-
num_samples = 10
6695
video_files_paths = list(Path(videos_dir_path).glob("*.mp4"))
6796
df_data = run_benchmarks(
6897
decoder_dict,
6998
video_files_paths,
7099
num_samples,
71100
num_sequential_frames_from_start=[100],
72-
min_runtime_seconds=30,
101+
min_runtime_seconds=min_runtime_seconds,
73102
benchmark_video_creation=False,
74103
)
75104
df_data.append(
@@ -82,9 +111,10 @@ def main() -> None:
82111
}
83112
)
84113

85-
data_json = Path(__file__).parent / "benchmark_readme_data.json"
86-
with open(data_json, "w") as write_file:
87-
json.dump(df_data, write_file, sort_keys=True, indent=4)
114+
if data_generation_run:
115+
data_json = Path(__file__).parent / "benchmark_readme_data.json"
116+
with open(data_json, "w") as write_file:
117+
json.dump(df_data, write_file, sort_keys=True, indent=4)
88118

89119

90120
if __name__ == "__main__":

0 commit comments

Comments
 (0)