Skip to content

Commit

Permalink
Merge pull request #27715 from hadim/torchaudio
Browse files Browse the repository at this point in the history
add torchaudio
  • Loading branch information
hmaarrfk authored Oct 13, 2024
2 parents 9ce885c + c17800d commit 976b48d
Show file tree
Hide file tree
Showing 7 changed files with 382 additions and 0 deletions.
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/0004-add-missing-ffmpeg-skip.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")

183 changes: 183 additions & 0 deletions recipes/torchaudio/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# 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/0004-add-missing-ffmpeg-skip.patch

build:
number: ${{ build_number }}
skip:
- win
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

- 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
- h-vetinari
75 changes: 75 additions & 0 deletions recipes/torchaudio/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/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}"
tests_to_skip="test_quantize_torchscript_1_wav2vec2_large or ${tests_to_skip}"
tests_to_skip="test_quantize_torchscript_2_wav2vec2_large_lv60k or ${tests_to_skip}"


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

0 comments on commit 976b48d

Please sign in to comment.