1{ lib
2, stdenv
3, buildPythonPackage
4, fetchurl
5, isPy37
6, isPy38
7, isPy39
8, isPy310
9, python
10, torch-bin
11, pythonOlder
12, pythonAtLeast
13}:
14
15buildPythonPackage rec {
16 pname = "torchaudio";
17 version = "0.12.1";
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 fetchurl srcs;
25
26 disabled = !(isPy37 || isPy38 || isPy39 || isPy310);
27
28 propagatedBuildInputs = [
29 torch-bin
30 ];
31
32 # The wheel-binary is not stripped to avoid the error of `ImportError: libtorch_cuda_cpp.so: ELF load command address/offset not properly aligned.`.
33 dontStrip = true;
34
35 pythonImportsCheck = [ "torchaudio" ];
36
37 postFixup = ''
38 # Note: after patchelf'ing, libcudart can still not be found. However, this should
39 # not be an issue, because PyTorch is loaded before torchvision and brings
40 # in the necessary symbols.
41 patchelf --set-rpath "${lib.makeLibraryPath [ stdenv.cc.cc.lib ]}:${torch-bin}/${python.sitePackages}/torch/lib:" \
42 "$out/${python.sitePackages}/torchaudio/_torchaudio.so"
43 '';
44
45 meta = with lib; {
46 description = "PyTorch audio library";
47 homepage = "https://pytorch.org/";
48 changelog = "https://github.com/pytorch/audio/releases/tag/v${version}";
49 # Includes CUDA and Intel MKL, but redistributions of the binary are not limited.
50 # https://docs.nvidia.com/cuda/eula/index.html
51 # https://www.intel.com/content/www/us/en/developer/articles/license/onemkl-license-faq.html
52 license = licenses.bsd3;
53 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
54 platforms = platforms.linux;
55 maintainers = with maintainers; [ junjihashimoto ];
56 };
57}