2024-06-05 15:53:02 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
buildPythonPackage,
|
|
|
|
fetchFromGitHub,
|
|
|
|
cmake,
|
|
|
|
symlinkJoin,
|
|
|
|
ffmpeg-full,
|
|
|
|
pkg-config,
|
|
|
|
ninja,
|
|
|
|
pybind11,
|
|
|
|
sox,
|
|
|
|
torch,
|
|
|
|
|
|
|
|
cudaSupport ? torch.cudaSupport,
|
|
|
|
cudaPackages,
|
|
|
|
rocmSupport ? torch.rocmSupport,
|
|
|
|
rocmPackages,
|
|
|
|
|
|
|
|
gpuTargets ? [ ],
|
2023-04-12 12:48:02 +00:00
|
|
|
}:
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
let
|
|
|
|
# TODO: Reuse one defined in torch?
|
|
|
|
# Some of those dependencies are probbly not required,
|
|
|
|
# but it breaks when the store path is different between torch and torchaudio
|
|
|
|
rocmtoolkit_joined = symlinkJoin {
|
|
|
|
name = "rocm-merged";
|
|
|
|
|
|
|
|
paths = with rocmPackages; [
|
|
|
|
rocm-core
|
|
|
|
clr
|
|
|
|
rccl
|
|
|
|
miopen
|
|
|
|
miopengemm
|
|
|
|
rocrand
|
|
|
|
rocblas
|
|
|
|
rocsparse
|
|
|
|
hipsparse
|
|
|
|
rocthrust
|
|
|
|
rocprim
|
|
|
|
hipcub
|
|
|
|
roctracer
|
|
|
|
rocfft
|
|
|
|
rocsolver
|
|
|
|
hipfft
|
|
|
|
hipsolver
|
|
|
|
hipblas
|
|
|
|
rocminfo
|
|
|
|
rocm-thunk
|
|
|
|
rocm-comgr
|
|
|
|
rocm-device-libs
|
|
|
|
rocm-runtime
|
|
|
|
clr.icd
|
|
|
|
hipify
|
|
|
|
];
|
|
|
|
|
|
|
|
# Fix `setuptools` not being found
|
|
|
|
postBuild = ''
|
|
|
|
rm -rf $out/nix-support
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
# Only used for ROCm
|
|
|
|
gpuTargetString = lib.strings.concatStringsSep ";" (
|
|
|
|
if gpuTargets != [ ] then
|
|
|
|
# If gpuTargets is specified, it always takes priority.
|
|
|
|
gpuTargets
|
|
|
|
else if rocmSupport then
|
|
|
|
rocmPackages.clr.gpuTargets
|
|
|
|
else
|
|
|
|
throw "No GPU targets specified"
|
|
|
|
);
|
|
|
|
in
|
2023-04-12 12:48:02 +00:00
|
|
|
buildPythonPackage rec {
|
|
|
|
pname = "torchaudio";
|
2024-06-20 14:57:18 +00:00
|
|
|
version = "2.3.1";
|
2024-02-29 20:09:43 +00:00
|
|
|
pyproject = true;
|
2023-04-12 12:48:02 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "pytorch";
|
|
|
|
repo = "audio";
|
2024-01-02 11:29:13 +00:00
|
|
|
rev = "refs/tags/v${version}";
|
2024-06-20 14:57:18 +00:00
|
|
|
hash = "sha256-PYaqRNKIhQ1DnFRZYyJJfBszVM2Bmu7A/lvvzJ6lL3g=";
|
2023-04-12 12:48:02 +00:00
|
|
|
};
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
patches = [ ./0001-setup.py-propagate-cmakeFlags.patch ];
|
2024-01-02 11:29:13 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
postPatch =
|
|
|
|
''
|
|
|
|
substituteInPlace setup.py \
|
|
|
|
--replace 'print(" --- Initializing submodules")' "return" \
|
|
|
|
--replace "_fetch_archives(_parse_sources())" "pass"
|
|
|
|
''
|
|
|
|
+ lib.optionalString rocmSupport ''
|
|
|
|
# There is no .info/version-dev, only .info/version
|
|
|
|
substituteInPlace cmake/LoadHIP.cmake \
|
|
|
|
--replace "/.info/version-dev" "/.info/version"
|
|
|
|
'';
|
2023-04-12 12:48:02 +00:00
|
|
|
|
2023-10-19 13:55:26 +00:00
|
|
|
env = {
|
|
|
|
TORCH_CUDA_ARCH_LIST = "${lib.concatStringsSep ";" torch.cudaCapabilities}";
|
|
|
|
};
|
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
# https://github.com/pytorch/audio/blob/v2.1.0/docs/source/build.linux.rst#optional-build-torchaudio-with-a-custom-built-ffmpeg
|
|
|
|
FFMPEG_ROOT = symlinkJoin {
|
|
|
|
name = "ffmpeg";
|
|
|
|
paths = [
|
|
|
|
ffmpeg-full.bin
|
|
|
|
ffmpeg-full.dev
|
|
|
|
ffmpeg-full.lib
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
nativeBuildInputs =
|
|
|
|
[
|
|
|
|
cmake
|
|
|
|
pkg-config
|
|
|
|
ninja
|
|
|
|
]
|
|
|
|
++ lib.optionals cudaSupport [ cudaPackages.cuda_nvcc ]
|
|
|
|
++ lib.optionals rocmSupport (
|
|
|
|
with rocmPackages;
|
|
|
|
[
|
|
|
|
clr
|
|
|
|
rocblas
|
|
|
|
hipblas
|
|
|
|
]
|
|
|
|
);
|
2024-01-02 11:29:13 +00:00
|
|
|
|
2023-04-12 12:48:02 +00:00
|
|
|
buildInputs = [
|
2024-01-02 11:29:13 +00:00
|
|
|
ffmpeg-full
|
2023-04-12 12:48:02 +00:00
|
|
|
pybind11
|
2024-01-02 11:29:13 +00:00
|
|
|
sox
|
|
|
|
torch.cxxdev
|
2023-04-12 12:48:02 +00:00
|
|
|
];
|
2024-01-02 11:29:13 +00:00
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
dependencies = [ torch ];
|
2023-04-12 12:48:02 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
BUILD_SOX = 0;
|
|
|
|
BUILD_KALDI = 0;
|
|
|
|
BUILD_RNNT = 0;
|
|
|
|
BUILD_CTC_DECODER = 0;
|
|
|
|
|
|
|
|
preConfigure = lib.optionalString rocmSupport ''
|
|
|
|
export ROCM_PATH=${rocmtoolkit_joined}
|
|
|
|
export PYTORCH_ROCM_ARCH="${gpuTargetString}"
|
|
|
|
'';
|
2023-04-12 12:48:02 +00:00
|
|
|
|
|
|
|
dontUseCmakeConfigure = true;
|
|
|
|
|
|
|
|
doCheck = false; # requires sox backend
|
|
|
|
|
2024-06-20 14:57:18 +00:00
|
|
|
meta = {
|
2023-04-12 12:48:02 +00:00
|
|
|
description = "PyTorch audio library";
|
|
|
|
homepage = "https://pytorch.org/";
|
|
|
|
changelog = "https://github.com/pytorch/audio/releases/tag/v${version}";
|
2024-06-20 14:57:18 +00:00
|
|
|
license = lib.licenses.bsd2;
|
2024-06-05 15:53:02 +00:00
|
|
|
platforms = [
|
|
|
|
"aarch64-darwin"
|
|
|
|
"aarch64-linux"
|
|
|
|
"x86_64-linux"
|
|
|
|
];
|
2024-06-20 14:57:18 +00:00
|
|
|
maintainers = with lib.maintainers; [ junjihashimoto ];
|
2023-04-12 12:48:02 +00:00
|
|
|
};
|
|
|
|
}
|