Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add torchaudio #27715

Merged
merged 70 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
264666a
add torchaudio
hadim Sep 28, 2024
5c06f57
ninja
hadim Sep 28, 2024
4c391cf
remove fairseq
hadim Sep 28, 2024
3078b4e
ci env
hadim Sep 28, 2024
67e56b5
false/true
hadim Sep 28, 2024
43be3b7
no tests
hadim Sep 28, 2024
ffe289f
Merge branch 'main' into torchaudio
hadim Sep 29, 2024
ef0c734
Update recipe.yaml
hadim Sep 30, 2024
a8cd229
Merge branch 'main' into torchaudio
hadim Sep 30, 2024
d054089
Update recipe.yaml
hadim Sep 30, 2024
db0183c
Merge branch 'main' into torchaudio
hadim Sep 30, 2024
df8ad65
Merge branch 'main' into torchaudio
hadim Oct 1, 2024
bbc4c2f
Merge branch 'main' into torchaudio
hadim Oct 1, 2024
1becc34
run tests
hadim Oct 2, 2024
66b0c26
Merge branch 'main' into torchaudio
hadim Oct 2, 2024
013a142
Merge branch 'main' into torchaudio
hadim Oct 4, 2024
722a832
wip
hadim Oct 4, 2024
d6f462e
wip
hadim Oct 4, 2024
3bcbce9
WIP
hadim Oct 4, 2024
0f0739c
WIP
hadim Oct 4, 2024
3618216
Disable ROCm for now; fix FFMPEG_ROOT
Tobias-Fischer Oct 6, 2024
87859da
Add missing test deps; add missing third party license
Tobias-Fischer Oct 6, 2024
f2dfc8d
Add missing skip for test
Tobias-Fischer Oct 6, 2024
710cb99
Skip some failing tests
Tobias-Fischer Oct 6, 2024
110ab56
Lint
Tobias-Fischer Oct 6, 2024
d0c3aaf
Disable ffmpeg/sox/rnnt
Tobias-Fischer Oct 7, 2024
3f91b04
Skip sox/ffmpeg tests
Tobias-Fischer Oct 7, 2024
6ce9f55
Skip more tests
Tobias-Fischer Oct 8, 2024
134dbfc
Try fix cuda issues
Tobias-Fischer Oct 8, 2024
172843b
Skip segfault test
Tobias-Fischer Oct 8, 2024
8f073f9
Do not install sox/ffmpeg
Tobias-Fischer Oct 8, 2024
07569a2
Use workaround from https://github.com/conda-forge/staged-recipes/pul…
Tobias-Fischer Oct 8, 2024
3778715
Update run_tests
Tobias-Fischer Oct 8, 2024
826dd50
Skip
Tobias-Fischer Oct 8, 2024
5988179
Next round of addressing segfaults
Tobias-Fischer Oct 9, 2024
5b7d0f6
Swap maintainers
Tobias-Fischer Oct 9, 2024
ac7d7bc
Tidy up run_tests.sh
Tobias-Fischer Oct 9, 2024
1d21508
One more failing test
Tobias-Fischer Oct 9, 2024
4098634
Skip more segfault tests
Tobias-Fischer Oct 9, 2024
ac4b49d
Debug nvcc for cuda12
Tobias-Fischer Oct 9, 2024
d802a77
Typo
Tobias-Fischer Oct 9, 2024
7999fea
More segfaults
Tobias-Fischer Oct 9, 2024
85793f0
Use CUDACXX
Tobias-Fischer Oct 9, 2024
2154c08
Segfault
Tobias-Fischer Oct 9, 2024
ae73876
Segfault
Tobias-Fischer Oct 9, 2024
1763fd5
Only build cuda 12
Tobias-Fischer Oct 9, 2024
8b701fd
Devug
Tobias-Fischer Oct 9, 2024
c39e7a0
Update build.sh
Tobias-Fischer Oct 9, 2024
befe6b0
Create 0002-use-conda-cuda.patch
Tobias-Fischer Oct 9, 2024
869700b
use 0002-use-conda-cuda.patch
Tobias-Fischer Oct 9, 2024
4d01e36
Fixup
Tobias-Fischer Oct 9, 2024
64fdf3a
Formatting
Tobias-Fischer Oct 9, 2024
dbe3eb9
Update recipe.yaml
Tobias-Fischer Oct 9, 2024
12ba915
Update build.sh
Tobias-Fischer Oct 9, 2024
d361e0b
Update build.sh
Tobias-Fischer Oct 9, 2024
5516bb6
explicitly set CUDA_INCLUDE_DIRS
Tobias-Fischer Oct 9, 2024
d7c5ef6
Create 0003-Apply-CMAKE_ARGS-if-set.patch
Tobias-Fischer Oct 9, 2024
777196b
Update recipe.yaml
Tobias-Fischer Oct 9, 2024
69a0116
Update build.sh
Tobias-Fischer Oct 9, 2024
e62b41f
Debug
Tobias-Fischer Oct 10, 2024
796a15c
Update build.sh
Tobias-Fischer Oct 10, 2024
459d54e
Update build.sh
Tobias-Fischer Oct 10, 2024
c01e56a
Fixup
Tobias-Fischer Oct 10, 2024
137bcbc
Cleanup
Tobias-Fischer Oct 10, 2024
894a89f
Enable all builds again to see if they still work
Tobias-Fischer Oct 10, 2024
240eab8
Add all builds, add @h-vetinari as maintainer
Tobias-Fischer Oct 10, 2024
f3ae343
Rename 3837.patch to 0004-add-missing-ffmpeg-skip.patch
Tobias-Fischer Oct 10, 2024
4162e17
Update recipe.yaml
Tobias-Fischer Oct 10, 2024
415e262
Merge branch 'main' into torchaudio
Tobias-Fischer Oct 10, 2024
c17800d
A few more skips
Tobias-Fischer Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions recipes/torchaudio/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
set -ex

if [[ ${cuda_compiler_version} != "None" ]]; then
# Set the CUDA arch list from
# https://github.com/conda-forge/pytorch-cpu-feedstock/blob/main/recipe/build_pytorch.sh
if [[ ${cuda_compiler_version} == 11.8 ]]; then
export TORCH_CUDA_ARCH_LIST="3.5;5.0;6.0;6.1;7.0;7.5;8.0;8.6;8.9+PTX"
export CUDA_TOOLKIT_ROOT_DIR=$CUDA_HOME
elif [[ ${cuda_compiler_version} == 12.0 ]]; then
export TORCH_CUDA_ARCH_LIST="5.0;6.0;6.1;7.0;7.5;8.0;8.6;8.9;9.0+PTX"
# $CUDA_HOME not set in CUDA 12.0. Using $PREFIX
export CUDA_TOOLKIT_ROOT_DIR="${PREFIX}"
# CUDA_HOME must be set for the build to work in torchaudio
export CUDA_HOME="${PREFIX}"
else
echo "unsupported cuda version. edit build.sh"
exit 1
fi

if [[ "${target_platform}" != "${build_platform}" ]]; then
export CUDA_TOOLKIT_ROOT=${PREFIX}
fi

export USE_CUDA=1
export BUILD_CUDA_CTC_DECODER=1
else
export USE_CUDA=0
export BUILD_CUDA_CTC_DECODER=0
fi

export USE_ROCM=0
export USE_OPENMP=1
export BUILD_CPP_TEST=0

# sox is buggy
export BUILD_SOX=0

# FFMPEG is buggy
export USE_FFMPEG=0
# export FFMPEG_ROOT="${PREFIX}"

# RNNT loss is buggy
export BUILD_RNNT=0

export CMAKE_C_COMPILER="$CC"
export CMAKE_CXX_COMPILER="$CXX"
export CMAKE_GENERATOR="Ninja"

python -m pip install . -vv
16 changes: 16 additions & 0 deletions recipes/torchaudio/patches/0001-point-to-correct-prefix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/tools/setup_helpers/extension.py b/tools/setup_helpers/extension.py
index 2415bbae..f724c4b8 100644
--- a/tools/setup_helpers/extension.py
+++ b/tools/setup_helpers/extension.py
@@ -124,8 +124,9 @@ class CMakeBuild(build_ext):

cmake_args = [
f"-DCMAKE_BUILD_TYPE={cfg}",
- f"-DCMAKE_PREFIX_PATH={torch.utils.cmake_prefix_path}",
- f"-DCMAKE_INSTALL_PREFIX={extdir}",
+ f"-DCMAKE_PREFIX_PATH={os.environ['PREFIX']}",
+ f"-DCMAKE_LIBRARY_PREFIX={os.environ['PREFIX']}",
+ f"-DCMAKE_INSTALL_PREFIX={os.environ['SP_DIR']}/torch/lib",
"-DCMAKE_VERBOSE_MAKEFILE=ON",
f"-DPython_INCLUDE_DIR={distutils.sysconfig.get_python_inc()}",
f"-DBUILD_CPP_TEST={'ON' if _BUILD_CPP_TEST else 'OFF'}",
15 changes: 15 additions & 0 deletions recipes/torchaudio/patches/0002-use-conda-cuda.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/tools/setup_helpers/extension.py b/tools/setup_helpers/extension.py
index 2415bbaedb..fcf6a69d93 100644
--- a/tools/setup_helpers/extension.py
+++ b/tools/setup_helpers/extension.py
@@ -150,10 +150,6 @@ def build_extension(self, ext):
_arches = [arch[:-4] if arch.endswith("+PTX") else f"{arch}-real" for arch in _arches]
cmake_args += [f"-DCMAKE_CUDA_ARCHITECTURES={';'.join(_arches)}"]

- if platform.system() != "Windows" and CUDA_HOME is not None:
- cmake_args += [f"-DCMAKE_CUDA_COMPILER='{CUDA_HOME}/bin/nvcc'"]
- cmake_args += [f"-DCUDA_TOOLKIT_ROOT_DIR='{CUDA_HOME}'"]
-
# Default to Ninja
if "CMAKE_GENERATOR" not in os.environ or platform.system() == "Windows":
cmake_args += ["-GNinja"]
22 changes: 22 additions & 0 deletions recipes/torchaudio/patches/0003-Apply-CMAKE_ARGS-if-set.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/tools/setup_helpers/extension.py b/tools/setup_helpers/extension.py
index 2415bbaedb..2b6243a790 100644
--- a/tools/setup_helpers/extension.py
+++ b/tools/setup_helpers/extension.py
@@ -3,6 +3,7 @@
import platform
import subprocess
from pathlib import Path
+import shlex

import torch
from setuptools import Extension
@@ -141,6 +142,9 @@ def build_extension(self, ext):
f"-DUSE_OPENMP:BOOL={'ON' if _USE_OPENMP else 'OFF'}",
f"-DUSE_FFMPEG:BOOL={'ON' if _USE_FFMPEG else 'OFF'}",
]
+ if "CMAKE_ARGS" in os.environ:
+ cmake_args += shlex.split(os.environ["CMAKE_ARGS"])
+
build_args = ["--target", "install"]
# Pass CUDA architecture to cmake
if _TORCH_CUDA_ARCH_LIST is not None:
21 changes: 21 additions & 0 deletions recipes/torchaudio/patches/3837.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
From d7e13dfe2ff32c9a6020bd56e97b1731e508243e Mon Sep 17 00:00:00 2001
From: Tobias Fischer <[email protected]>
Date: Sat, 5 Oct 2024 20:52:42 +1000
Subject: [PATCH] Add missing @skipIfNoFFmpeg for TestFileObject

---
test/torchaudio_unittest/backend/dispatcher/ffmpeg/info_test.py | 1 +
1 file changed, 1 insertion(+)

diff --git a/test/torchaudio_unittest/backend/dispatcher/ffmpeg/info_test.py b/test/torchaudio_unittest/backend/dispatcher/ffmpeg/info_test.py
index 58a085636b..bf93a75289 100644
--- a/test/torchaudio_unittest/backend/dispatcher/ffmpeg/info_test.py
+++ b/test/torchaudio_unittest/backend/dispatcher/ffmpeg/info_test.py
@@ -404,6 +404,7 @@ def read(self, n):


@skipIfNoExec("sox")
+@skipIfNoFFmpeg
class TestFileObject(FileObjTestBase, PytorchTestCase):
_info = partial(get_info_func(), backend="ffmpeg")

184 changes: 184 additions & 0 deletions recipes/torchaudio/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/prefix-dev/recipe-format/main/schema.json

context:
name: torchaudio
version: "2.4.1"
build_number: 0
cuda_version: ${{ env.get("CONDA_OVERRIDE_CUDA", default="None") }}
cuda: ${{ "true" if cuda_version != "None" else "false" }}
cuda_build_string: cuda_${{ cuda_version | version_to_buildstring }}
string_prefix: ${{ cuda_build_string if cuda == "true" else "cpu_" }}

package:
name: ${{ name|lower }}
version: ${{ version }}

source:
- url: https://github.com/pytorch/audio/archive/refs/tags/v${{ version }}.tar.gz
sha256: a6b7e1b606ae353b9c4db1c8e754263f53f0457e9ab538e9669c0af0c46a0d5c
patches:
- patches/0001-point-to-correct-prefix.patch
- patches/0002-use-conda-cuda.patch
- patches/0003-Apply-CMAKE_ARGS-if-set.patch
- patches/3837.patch

build:
number: ${{ build_number }}
skip:
- win
# - match(cuda_version, "!=12")
- match(python, "!=3.11")
string: ${{ string_prefix }}py${{ python | version_to_buildstring }}h${{ hash }}_${{ build_number }}
variant:
use_keys:
# use cuda from the variant config, e.g. to build multiple CUDA variants
- ${{ "cuda" if cuda == "true" }}
# this will down-prioritize the cuda variant versus other variants of the package
down_prioritize_variant: ${{ 1 if cuda == "true" else 0 }}
script:
file: build
env:
cuda_compiler_version: ${{ cuda_version | default('None') }}

requirements:
build:
- if: build_platform != target_platform
then:
- python
- cross-python_${{ target_platform }}
- pytorch
hadim marked this conversation as resolved.
Show resolved Hide resolved

- if: match(cuda_version, ">=12")
then:
- cuda-driver-dev
- cuda-cudart-dev
- cuda-nvrtc-dev
- cuda-nvtx-dev
- cuda-nvml-dev
- cuda-profiler-api
- libcublas-dev
- libcufft-dev
- libcurand-dev
- libcusolver-dev
- libcusparse-dev

- ${{ compiler('cxx') }}
- ${{ compiler('c') }}
- ${{ stdlib("c") }}
- cmake
- ninja
- ccache
- git

- if: cuda == "true"
then:
- ${{ compiler('cuda') }}
- cuda-version ==${{ cuda_version }}

host:
- python
- pip
- setuptools
- pytorch
- ${{ "pytorch * cuda*" if cuda == "true" }}
- ${{ "pytorch * cpu*" if cuda == "false" }}

- bzip2
- kaldi
- pybind11
# - sox
# - ffmpeg
- xz
- zlib

- if: cuda == "true"
then:
- cuda-version ==${{ cuda_version }}

- if: match(cuda_version, ">=12")
then:
- cuda-driver-dev
- cuda-cudart-dev
- cuda-nvrtc-dev
- cuda-nvtx-dev
- cuda-nvml-dev
- cuda-profiler-api
- libcublas-dev
- libcufft-dev
- libcurand-dev
- libcusolver-dev
- libcusparse-dev
run:
- python
- numpy
- kaldi
- ${{ "pytorch * cuda*" if cuda == "true" }}
- ${{ "pytorch * cpu*" if cuda == "false" }}

ignore_run_exports:
from_package:
- if: match(cuda_version, ">=12")
then:
- cuda-nvrtc-dev
- cuda-nvtx-dev
- libcublas-dev
- libcufft-dev
- libcurand-dev
- libcusolver-dev
- libcusparse-dev

tests:
- python:
imports:
- torchaudio
- torchaudio.backend
- torchaudio.compliance
- torchaudio.datasets
- torchaudio.functional
- torchaudio.models
- torchaudio.pipelines
- torchaudio.kaldi_io
- torchaudio.utils
- torchaudio.sox_effects
- torchaudio.transforms
pip_check: true

- requirements:
run:
- pytest
- scipy
- numpy
- librosa
- expecttest
- requests
- hypothesis
- inflect
- kaldi_io
- parameterized
- pysoundfile
- transformers
- unidecode
- inflect
# - sox
- pytorch-lightning
- sentencepiece
files:
source:
- test/
- examples/
recipe:
- run_tests.sh
script:
- bash run_tests.sh

about:
homepage: https://github.com/pytorch/audio
license: BSD-2-Clause
license_file:
- LICENSE
- third_party/LICENSES_BUNDLED.txt
summary: Data manipulation and transformation for audio signal processing, powered by PyTorch

extra:
recipe-maintainers:
- Tobias-Fischer
72 changes: 72 additions & 0 deletions recipes/torchaudio/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash
set -ex

export CI=true

export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_CMD_APPLY_CMVN_SLIDING="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_CMD_COMPUTE_FBANK_FEATS="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_CMD_COMPUTE_KALDI_PITCH_FEATS="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_CMD_COMPUTE_MFCC_FEATS="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_CMD_COMPUTE_SPECTROGRAM_FEATS="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_KALDI="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_CUDA="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_HW_ACCEL="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_ON_PYTHON_310="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_AUDIO_OUT_DEVICE="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MACOS="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_TEMPORARY_DISABLED="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_DECODER="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX_ENCODER="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_CTC_DECODER="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_demucs="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_MOD_fairseq="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_QUANTIZATION="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_RIR="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_FFMPEG="true"
export TORCHAUDIO_TEST_ALLOW_SKIP_IF_NO_SOX="true"


## OVERVIEW OF SKIPPED TESTS

# Output 0 of UnbindBackward0 is a view and is being modified inplace.
# This view is the output of a function that returns multiple views.
# Such functions do not allow the output views to be modified inplace.
# You should replace the inplace operation by an out-of-place one.
tests_to_skip="TestAutogradLfilterCPU"
tests_to_skip="test_deemphasis or ${tests_to_skip}"

# 'torchaudio' object has no attribute 'rnnt_loss'
tests_to_skip="rnnt or ${tests_to_skip}"

# 'torchaudio' object has no attribute 'ray_tracing'
tests_to_skip="ray_tracing or ${tests_to_skip}"

# object has no attribute _simulate_rir:
tests_to_skip="test_simulate_rir or ${tests_to_skip}"

# ValueError: invalid version number '0.10.2.post1'
tests_to_skip="test_create_mel or ${tests_to_skip}"

# RuntimeError: torchaudio.functional._alignment.forced_align Requires alignment extension, but TorchAudio is not compiled with it.
# Please build TorchAudio with alignment support.
tests_to_skip="test_forced_align or ${tests_to_skip}"

# Very slow on CI:
tests_to_skip="hubert_large or ${tests_to_skip}"
tests_to_skip="hubert_xlarge or ${tests_to_skip}"
tests_to_skip="hubert_pretrain_large or ${tests_to_skip}"
tests_to_skip="hubert_pretrain_xlarge or ${tests_to_skip}"
tests_to_skip="wavlm_large or ${tests_to_skip}"
tests_to_skip="test_masking_iid or ${tests_to_skip}"
tests_to_skip="test_mvdr_0_ref_channel or ${tests_to_skip}"
tests_to_skip="test_rtf_mvdr or ${tests_to_skip}"
tests_to_skip="test_souden_mvdr or ${tests_to_skip}"

# Segfault on CI (probably due to limited memory):
tests_to_skip="test_pitch_shift_shape_2 or ${tests_to_skip}"
tests_to_skip="test_paper_configuration or ${tests_to_skip}"
tests_to_skip="test_oscillator_bank or ${tests_to_skip}"
tests_to_skip="test_PitchShift or ${tests_to_skip}"
tests_to_skip="test_pitch_shift_resample_kernel or ${tests_to_skip}"

pytest -v test/torchaudio_unittest/ -k "not (${tests_to_skip})"