1{ lib 2, stdenv 3, addOpenGLRunpath 4, autoPatchelfHook 5, buildPythonPackage 6, cudaPackages 7, fetchurl 8, ffmpeg_4 9, pythonAtLeast 10, pythonOlder 11, python 12, torch-bin 13}: 14 15buildPythonPackage rec { 16 pname = "torchaudio"; 17 version = "2.0.2"; 18 format = "wheel"; 19 20 src = 21 let pyVerNoDot = lib.replaceStrings [ "." ] [ "" ] python.pythonVersion; 22 unsupported = throw "Unsupported system"; 23 srcs = (import ./binary-hashes.nix version)."${stdenv.system}-${pyVerNoDot}" or unsupported; 24 in 25 fetchurl srcs; 26 27 disabled = (pythonOlder "3.8") || (pythonAtLeast "3.12"); 28 29 buildInputs = with cudaPackages; [ 30 # $out/${sitePackages}/torchaudio/lib/libtorchaudio*.so wants libcudart.so.11.0 but torch/lib only ships 31 # libcudart.$hash.so.11.0 32 cuda_cudart 33 34 # $out/${sitePackages}/torchaudio/lib/libtorchaudio*.so wants libnvToolsExt.so.2 but torch/lib only ships 35 # libnvToolsExt-$hash.so.1 36 cuda_nvtx 37 38 ffmpeg_4.lib 39 ]; 40 41 nativeBuildInputs = [ 42 autoPatchelfHook 43 addOpenGLRunpath 44 ]; 45 46 propagatedBuildInputs = [ 47 torch-bin 48 ]; 49 50 preInstall = '' 51 addAutoPatchelfSearchPath "${torch-bin}/${python.sitePackages}/torch" 52 ''; 53 54 # The wheel-binary is not stripped to avoid the error of `ImportError: libtorch_cuda_cpp.so: ELF load command address/offset not properly aligned.`. 55 dontStrip = true; 56 57 pythonImportsCheck = [ "torchaudio" ]; 58 59 meta = with lib; { 60 description = "PyTorch audio library"; 61 homepage = "https://pytorch.org/"; 62 changelog = "https://github.com/pytorch/audio/releases/tag/v${version}"; 63 # Includes CUDA and Intel MKL, but redistributions of the binary are not limited. 64 # https://docs.nvidia.com/cuda/eula/index.html 65 # https://www.intel.com/content/www/us/en/developer/articles/license/onemkl-license-faq.html 66 license = licenses.bsd3; 67 sourceProvenance = with sourceTypes; [ binaryNativeCode ]; 68 platforms = [ "aarch64-linux" "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ]; 69 maintainers = with maintainers; [ junjihashimoto ]; 70 }; 71}