Skip to content

Commit 52e2817

Browse files
committed
Merge branch 'main' of github.com:pytorch/torchcodec into nvdecclean
2 parents 7edf916 + d14f642 commit 52e2817

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1487
-430
lines changed

.github/workflows/docs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ jobs:
5151
strategy:
5252
fail-fast: false
5353
matrix:
54-
# 3.9 corresponds to the minimum python version for which we build
54+
# 3.10 corresponds to the minimum python version for which we build
5555
# the wheel unless the label cliflow/binaries/all is present in the
5656
# PR.
57-
python-version: ['3.9']
57+
python-version: ['3.10']
5858
cuda-version: ['12.6']
5959
ffmpeg-version-for-tests: ['7']
6060
container:

.github/workflows/linux_cuda_wheel.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ jobs:
6161
strategy:
6262
fail-fast: false
6363
matrix:
64-
# 3.9 corresponds to the minimum python version for which we build
64+
# 3.10 corresponds to the minimum python version for which we build
6565
# the wheel unless the label cliflow/binaries/all is present in the
6666
# PR.
6767
# For the actual release we should add that label and change this to
6868
# include more python versions.
69-
python-version: ['3.9']
69+
python-version: ['3.10']
7070
# We test against 12.6 and 12.9 to avoid having too big of a CI matrix,
7171
# but for releases we should add 12.8.
7272
cuda-version: ['12.6', '12.9']

.github/workflows/linux_wheel.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
strategy:
6363
fail-fast: false
6464
matrix:
65-
python-version: ['3.9']
65+
python-version: ['3.10']
6666
ffmpeg-version-for-tests: ['4.4.2', '5.1.2', '6.1.1', '7.0.1']
6767
needs: build
6868
steps:

.github/workflows/macos_wheel.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
strategy:
6464
fail-fast: false
6565
matrix:
66-
python-version: ['3.9']
66+
python-version: ['3.10']
6767
ffmpeg-version-for-tests: ['4.4.2', '5.1.2', '6.1.1', '7.0.1']
6868
needs: build
6969
steps:

.github/workflows/reference_resources.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
pull_request:
66
paths:
7-
- test/generate_reference_resources.sh
7+
- test/generate_reference_resources.py
88
- .github/workflows/reference_resources.yaml # self reference
99
schedule:
1010
- cron: '0 0 * * 0' # on sunday
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
python-version: ['3.9']
22+
python-version: ['3.10']
2323
ffmpeg-version-for-tests: ['4.4.2', '5.1.2', '6.1.1', '7.0.1']
2424
steps:
2525
- name: Setup conda env
@@ -38,7 +38,7 @@ jobs:
3838
- name: Update pip
3939
run: python -m pip install --upgrade pip
4040

41-
- name: Instal generation dependencies
41+
- name: Install generation dependencies
4242
run: |
4343
# Note that we're installing stable - this is for running a script where we're a normal PyTorch
4444
# user, not for building TorhCodec.
@@ -50,4 +50,4 @@ jobs:
5050

5151
- name: Run generation reference resources
5252
run: |
53-
test/generate_reference_resources.sh
53+
python test/generate_reference_resources.py

.github/workflows/windows_wheel.yaml

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,20 @@ jobs:
3636
with-rocm: disable
3737
with-cuda: disable
3838
build-python-only: "disable"
39+
python-versions: '["3.10", "3.11", "3.12", "3.13"]'
40+
3941

4042
build:
4143
needs: generate-matrix
4244
strategy:
4345
fail-fast: false
4446
name: Build and Upload Windows wheel
45-
# TODO: use @main
46-
uses: nicolashug/test-infra/.github/workflows/build_wheels_windows.yml@build-platform-windows
47+
uses: pytorch/test-infra/.github/workflows/build_wheels_windows.yml@main
4748
with:
4849
repository: pytorch/torchcodec
4950
ref: ""
50-
test-infra-repository: nicolashug/test-infra
51-
test-infra-ref: build-platform-windows
51+
test-infra-repository: pytorch/test-infra
52+
test-infra-ref: main
5253
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
5354
pre-script: packaging/pre_build_script.sh
5455
# post-script: packaging/post_build_script.sh TODO: consider enabling post-build checks for Windows
@@ -60,3 +61,74 @@ jobs:
6061
# The BUILD_AGAINST_ALL_FFMPEG_FROM_S3 var, needed to build the wheel, is
6162
# set in vc_env_helper.bat Couldn't find a way to set it from here.
6263
build-command: "python -m build --wheel -vvv --no-isolation"
64+
65+
install-and-test:
66+
runs-on: windows-latest
67+
strategy:
68+
fail-fast: false
69+
matrix:
70+
python-version: ['3.10']
71+
# TODO: FFmpeg 5 on Windows segfaults in avcodec_open2() when passing
72+
# bad parameters.
73+
# See https://github.com/pytorch/torchcodec/pull/806
74+
ffmpeg-version-for-tests: ['4.4.2', '6.1.1', '7.0.1']
75+
needs: build
76+
steps:
77+
- uses: actions/download-artifact@v4
78+
with:
79+
name: pytorch_torchcodec__${{ matrix.python-version }}_cpu_x64
80+
path: pytorch/torchcodec/dist/
81+
- name: Setup conda env
82+
uses: conda-incubator/setup-miniconda@v2
83+
with:
84+
auto-update-conda: true
85+
miniconda-version: "latest"
86+
activate-environment: test
87+
python-version: ${{ matrix.python-version }}
88+
- name: Update pip
89+
run: python -m pip install --upgrade pip
90+
- name: Install PyTorch
91+
run: |
92+
python -m pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu
93+
- name: Install torchcodec from the wheel
94+
run: |
95+
wheel_path=`find pytorch/torchcodec/dist -type f -name "*.whl"`
96+
echo Installing $wheel_path
97+
python -m pip install $wheel_path -vvv
98+
- name: Check out repo
99+
uses: actions/checkout@v3
100+
- name: Install ffmpeg, post build
101+
run: |
102+
# Ideally we would have checked for that before installing the wheel,
103+
# but we need to checkout the repo to access this file, and we don't
104+
# want to checkout the repo before installing the wheel to avoid any
105+
# side-effect. It's OK.
106+
source packaging/helpers.sh
107+
assert_ffmpeg_not_installed
108+
conda install "ffmpeg=${{ matrix.ffmpeg-version-for-tests }}" -c conda-forge
109+
ffmpeg -version
110+
- name: Test torchcodec import after FFmpeg installation
111+
run: |
112+
echo "Testing torchcodec import after FFmpeg is installed and PATH is updated..."
113+
python -c "import torchcodec; print('TorchCodec import successful!')"
114+
- name: Install test dependencies
115+
run: |
116+
# Ideally we would find a way to get those dependencies from pyproject.toml
117+
python -m pip install numpy pytest pillow
118+
- name: Delete the src/ folder just for fun
119+
run: |
120+
# The only reason we checked-out the repo is to get access to the
121+
# tests. We don't care about the rest. Out of precaution, we delete
122+
# the src/ folder to be extra sure that we're running the code from
123+
# the installed wheel rather than from the source.
124+
# This is just to be extra cautious and very overkill because a)
125+
# there's no way the `torchcodec` package from src/ can be found from
126+
# the PythonPath: the main point of `src/` is precisely to protect
127+
# against that and b) if we ever were to execute code from
128+
# `src/torchcodec`, it would fail loudly because the built .so files
129+
# aren't present there.
130+
rm -r src/
131+
ls
132+
- name: Run Python tests
133+
run: |
134+
pytest test -vvv

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ The following table indicates the compatibility between versions of
130130

131131
| `torchcodec` | `torch` | Python |
132132
| ------------------ | ------------------ | ------------------- |
133-
| `main` / `nightly` | `main` / `nightly` | `>=3.9`, `<=3.13` |
133+
| `main` / `nightly` | `main` / `nightly` | `>=3.10`, `<=3.13` |
134134
| `0.6` | `2.8` | `>=3.9`, `<=3.13` |
135135
| `0.5` | `2.7` | `>=3.9`, `<=3.13` |
136136
| `0.4` | `2.7` | `>=3.9`, `<=3.13` |

benchmarks/decoders/benchmark_decoders_library.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def decode_first_n_frames(self, video_file, n):
4747
def decode_first_n_frames_description(self, n) -> str:
4848
return f"first {n} frames"
4949

50+
def init_decode_and_resize(self):
51+
pass
52+
5053
@abc.abstractmethod
5154
def decode_and_resize(self, video_file, pts_list, height, width, device):
5255
pass
@@ -107,9 +110,12 @@ def __init__(self, backend):
107110
self._backend = backend
108111
self._print_each_iteration_time = False
109112
import torchvision # noqa: F401
110-
from torchvision.transforms import v2 as transforms_v2
111113

112114
self.torchvision = torchvision
115+
116+
def init_decode_and_resize(self):
117+
from torchvision.transforms import v2 as transforms_v2
118+
113119
self.transforms_v2 = transforms_v2
114120

115121
def decode_frames(self, video_file, pts_list):
@@ -267,6 +273,7 @@ def __init__(
267273
self._color_conversion_library = color_conversion_library
268274
self._device = device
269275

276+
def init_decode_and_resize(self):
270277
from torchvision.transforms import v2 as transforms_v2
271278

272279
self.transforms_v2 = transforms_v2
@@ -379,6 +386,7 @@ def __init__(
379386
self._seek_mode = seek_mode
380387
self._stream_index = int(stream_index) if stream_index else None
381388

389+
def init_decode_and_resize(self):
382390
from torchvision.transforms import v2 as transforms_v2
383391

384392
self.transforms_v2 = transforms_v2
@@ -443,6 +451,7 @@ def __init__(
443451
self._device = device
444452
self._seek_mode = seek_mode
445453

454+
def init_decode_and_resize(self):
446455
from torchvision.transforms import v2 as transforms_v2
447456

448457
self.transforms_v2 = transforms_v2
@@ -546,10 +555,12 @@ def __init__(self, stream_index: str | None = None):
546555

547556
self.torchaudio = torchaudio
548557

558+
self._stream_index = int(stream_index) if stream_index else None
559+
560+
def init_decode_and_resize(self):
549561
from torchvision.transforms import v2 as transforms_v2
550562

551563
self.transforms_v2 = transforms_v2
552-
self._stream_index = int(stream_index) if stream_index else None
553564

554565
def decode_frames(self, video_file, pts_list):
555566
stream_reader = self.torchaudio.io.StreamReader(src=video_file)
@@ -883,6 +894,7 @@ def run_benchmarks(
883894

884895
if dataloader_parameters:
885896
bp = dataloader_parameters.batch_parameters
897+
decoder.init_decode_and_resize()
886898
description = (
887899
f"concurrency {bp.num_threads}"
888900
f"batch {bp.batch_size}"

examples/decoding/file_like.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def read(self, size: int) -> bytes:
215215
self.num_reads += 1
216216
return self._file.read(size)
217217

218-
def seek(self, offset: int, whence: int) -> bytes:
218+
def seek(self, offset: int, whence: int) -> int:
219219
self.num_seeks += 1
220220
return self._file.seek(offset, whence)
221221

setup.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,14 @@ def _build_all_extensions_with_cmake(self):
135135
["cmake", str(_ROOT_DIR)] + cmake_args, cwd=self.build_temp
136136
)
137137
print("Calling cmake --build", flush=True)
138-
subprocess.check_call(["cmake", "--build", "."], cwd=self.build_temp)
138+
subprocess.check_call(
139+
["cmake", "--build", ".", "--config", cmake_build_type], cwd=self.build_temp
140+
)
139141
print("Calling cmake --install", flush=True)
140-
subprocess.check_call(["cmake", "--install", "."], cwd=self.build_temp)
142+
subprocess.check_call(
143+
["cmake", "--install", ".", "--config", cmake_build_type],
144+
cwd=self.build_temp,
145+
)
141146

142147
def copy_extensions_to_source(self):
143148
"""Copy built extensions from temporary folder back into source tree.
@@ -156,7 +161,7 @@ def copy_extensions_to_source(self):
156161
# https://stackoverflow.com/a/2339910
157162
extensions = ["dylib", "so"]
158163
elif sys.platform in ("win32", "cygwin"):
159-
extensions = ["dll"]
164+
extensions = ["dll", "pyd"]
160165
else:
161166
raise NotImplementedError(f"Platform {sys.platform} is not supported")
162167

0 commit comments

Comments
 (0)