Add ability to build cuda wheels #74
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and test Linux CUDA wheels | |
on: | |
pull_request: | |
push: | |
branches: | |
- nightly | |
- main | |
- release/* | |
tags: | |
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+ | |
workflow_dispatch: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }} | |
cancel-in-progress: true | |
permissions: | |
id-token: write | |
contents: write | |
defaults: | |
run: | |
shell: bash -l -eo pipefail {0} | |
jobs: | |
generate-matrix: | |
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main | |
with: | |
package-type: wheel | |
os: linux | |
test-infra-repository: pytorch/test-infra | |
test-infra-ref: main | |
with-cpu: disable | |
with-xpu: disable | |
with-rocm: disable | |
with-cuda: enable | |
build-python-only: "disable" | |
build: | |
needs: generate-matrix | |
strategy: | |
fail-fast: false | |
name: Build and Upload wheel | |
uses: pytorch/test-infra/.github/workflows/build_wheels_linux.yml@main | |
with: | |
repository: pytorch/torchcodec | |
ref: "" | |
test-infra-repository: pytorch/test-infra | |
test-infra-ref: main | |
build-matrix: ${{ needs.generate-matrix.outputs.matrix }} | |
pre-script: packaging/linux_cuda_pre_build_script.sh | |
post-script: packaging/post_build_script.sh | |
smoke-test-script: packaging/fake_smoke_test.py | |
package-name: torchcodec | |
trigger-event: ${{ github.event_name }} | |
build-platform: "python-build-package" | |
build-command: "BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1 ENABLE_CUDA=1 python -m build --wheel -vvv --no-isolation" | |
install-and-test: | |
runs-on: linux.4xlarge.nvidia.gpu | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ['3.9', '3.10', '3.11', '3.12'] | |
cuda-version: ['12.4'] | |
ffmpeg-version-for-tests: ['5', '6', '7'] | |
container: | |
image: "pytorch/manylinux-builder:cuda${{ matrix.cuda-version }}" | |
options: "--gpus all -e NVIDIA_DRIVER_CAPABILITIES=video,compute,utility" | |
if: ${{ always() }} | |
needs: build | |
steps: | |
- name: Setup env vars | |
run: | | |
cuda_version_without_periods=$(echo "${{ matrix.cuda-version }}" | sed 's/\.//g') | |
echo cuda_version_without_periods=${cuda_version_without_periods} >> $GITHUB_ENV | |
- uses: actions/download-artifact@v3 | |
with: | |
# We use 3.9 because it's the minimum version we build. | |
# We test version 3.9 against all other python versions in the matrix. | |
name: pytorch_torchcodec__3.9_cu${{ env.cuda_version_without_periods }}_x86_64 | |
path: pytorch/torchcodec/dist/ | |
- name: Setup miniconda using test-infra | |
uses: ahmadsharif1/test-infra/.github/actions/setup-miniconda@14bc3c29f88d13b0237ab4ddf00aa409e45ade40 | |
with: | |
python-version: "3.9" | |
default-packages: "conda-forge::ffmpeg=${{ matrix.ffmpeg-version-for-tests }}" | |
- name: Check env | |
run: | | |
${CONDA_RUN} env | |
${CONDA_RUN} conda info | |
${CONDA_RUN} nvidia-smi | |
- name: Update pip | |
run: ${CONDA_RUN} python -m pip install --upgrade pip | |
- name: Install PyTorch | |
run: | | |
${CONDA_RUN} python -m pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cu${{ env.cuda_version_without_periods }} | |
${CONDA_RUN} python -c 'import torch; print(f"{torch.__version__}"); print(f"{torch.__file__}"); print(f"{torch.cuda.is_available()=}")' | |
- name: Install torchcodec from the wheel | |
run: | | |
wheel_path=`find pytorch/torchcodec/dist -type f -name "*.whl"` | |
echo Installing $wheel_path | |
${CONDA_RUN} python -m pip install $wheel_path -vvv | |
- name: Check out repo | |
uses: actions/checkout@v3 | |
- name: Install cuda runtime dependencies | |
run: | | |
${CONDA_RUN} conda install --yes nvidia::libnpp nvidia::cuda-nvrtc=12.4 nvidia::cuda-toolkit=12.4 nvidia::cuda-cudart=12.4 nvidia::cuda-driver-dev=12.4 | |
- name: Install test dependencies | |
run: | | |
${CONDA_RUN} python -m pip install --pre torchvision --index-url https://download.pytorch.org/whl/nightly/cpu | |
# Ideally we would find a way to get those dependencies from pyproject.toml | |
${CONDA_RUN} python -m pip install numpy pytest pillow | |
- name: Delete the src/ folder just for fun | |
run: | | |
# The only reason we checked-out the repo is to get access to the | |
# tests. We don't care about the rest. Out of precaution, we delete | |
# the src/ folder to be extra sure that we're running the code from | |
# the installed wheel rather than from the source. | |
# This is just to be extra cautious and very overkill because a) | |
# there's no way the `torchcodec` package from src/ can be found from | |
# the PythonPath: the main point of `src/` is precisely to protect | |
# against that and b) if we ever were to execute code from | |
# `src/torchcodec`, it would fail loudly because the built .so files | |
# aren't present there. | |
rm -r src/ | |
ls | |
- name: Smoke test | |
run: | | |
${CONDA_RUN} python test/decoders/manual_smoke_test.py | |
- name: Run Python tests | |
run: | | |
${CONDA_RUN} pytest test -vvv |