about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSandro <sandro.jaeckel@gmail.com>2021-11-16 10:38:14 +0100
committerGitHub <noreply@github.com>2021-11-16 10:38:14 +0100
commit7ba1fac583f5d75aba7d308c43322da8faef5590 (patch)
tree8c712a475acfd34a56b33c6070fb6a48b948bb73
parente8aa00d40a9e39d2bd2bc07ac1118c22fe4e902d (diff)
parent4d8d026e15e2aec296bc4e16b853116dbad78301 (diff)
Merge pull request #143525 from junjihashimoto/bump-pytorch
-rw-r--r--pkgs/development/libraries/science/math/libtorch/bin.nix68
-rw-r--r--pkgs/development/libraries/science/math/libtorch/binary-hashes.nix29
-rwxr-xr-xpkgs/development/libraries/science/math/libtorch/prefetch.sh38
-rw-r--r--pkgs/development/python-modules/pytorch/bin.nix10
-rw-r--r--pkgs/development/python-modules/pytorch/binary-hashes.nix20
-rwxr-xr-xpkgs/development/python-modules/pytorch/prefetch.sh13
-rw-r--r--pkgs/development/python-modules/torchaudio/bin.nix52
-rw-r--r--pkgs/development/python-modules/torchaudio/binary-hashes.nix26
-rwxr-xr-xpkgs/development/python-modules/torchaudio/prefetch.sh37
-rw-r--r--pkgs/development/python-modules/torchvision/bin.nix8
-rw-r--r--pkgs/development/python-modules/torchvision/binary-hashes.nix20
-rwxr-xr-xpkgs/development/python-modules/torchvision/prefetch.sh13
-rw-r--r--pkgs/top-level/python-packages.nix2
13 files changed, 245 insertions, 91 deletions
diff --git a/pkgs/development/libraries/science/math/libtorch/bin.nix b/pkgs/development/libraries/science/math/libtorch/bin.nix
index 712713c82be49..b00de428c8d46 100644
--- a/pkgs/development/libraries/science/math/libtorch/bin.nix
+++ b/pkgs/development/libraries/science/math/libtorch/bin.nix
@@ -2,14 +2,13 @@
 , stdenv
 , fetchzip
 , lib
+, libcxx
 
 , addOpenGLRunpath
 , patchelf
 , fixDarwinDylibNames
 
 , cudaSupport
-, cudatoolkit_11_1
-, cudnn_cudatoolkit_11_1
 }:
 
 let
@@ -18,10 +17,11 @@ let
   # this derivation. However, we should ensure on version bumps
   # that the CUDA toolkit for `passthru.tests` is still
   # up-to-date.
-  version = "1.9.0";
+  version = "1.10.0";
   device = if cudaSupport then "cuda" else "cpu";
   srcs = import ./binary-hashes.nix version;
   unavailable = throw "libtorch is not available for this platform";
+  libcxx-for-libtorch = if stdenv.hostPlatform.system == "x86_64-darwin" then libcxx else stdenv.cc.cc.lib;
 in stdenv.mkDerivation {
   inherit version;
   pname = "libtorch";
@@ -67,57 +67,37 @@ in stdenv.mkDerivation {
       ''}
     done
   '' + lib.optionalString stdenv.isDarwin ''
-    install_name_tool -change @rpath/libshm.dylib $out/lib/libshm.dylib $out/lib/libtorch_python.dylib
-    install_name_tool -change @rpath/libc10.dylib $out/lib/libc10.dylib $out/lib/libtorch_python.dylib
-    install_name_tool -change @rpath/libiomp5.dylib $out/lib/libiomp5.dylib $out/lib/libtorch_python.dylib
-    install_name_tool -change @rpath/libtorch.dylib $out/lib/libtorch.dylib $out/lib/libtorch_python.dylib
-    install_name_tool -change @rpath/libtorch_cpu.dylib $out/lib/libtorch_cpu.dylib $out/lib/libtorch_python.dylib
-
-    install_name_tool -change @rpath/libc10.dylib $out/lib/libc10.dylib $out/lib/libtorch.dylib
-    install_name_tool -change @rpath/libiomp5.dylib $out/lib/libiomp5.dylib $out/lib/libtorch.dylib
-    install_name_tool -change @rpath/libtorch_cpu.dylib $out/lib/libtorch_cpu.dylib $out/lib/libtorch.dylib
-
-    install_name_tool -change @rpath/libc10.dylib $out/lib/libc10.dylib $out/lib/libtorch_cpu.dylib
-    install_name_tool -change @rpath/libiomp5.dylib $out/lib/libiomp5.dylib $out/lib/libtorch_cpu.dylib
-    install_name_tool -change @rpath/libtensorpipe.dylib $out/lib/libtensorpipe.dylib $out/lib/libtorch_cpu.dylib
-
-    install_name_tool -change @rpath/libc10.dylib $out/lib/libc10.dylib $out/lib/libcaffe2_observers.dylib
-    install_name_tool -change @rpath/libiomp5.dylib $out/lib/libiomp5.dylib $out/lib/libcaffe2_observers.dylib
-    install_name_tool -change @rpath/libtorch.dylib $out/lib/libtorch.dylib $out/lib/libcaffe2_observers.dylib
-    install_name_tool -change @rpath/libtorch_cpu.dylib $out/lib/libtorch_cpu.dylib $out/lib/libcaffe2_observers.dylib
-
-    install_name_tool -change @rpath/libc10.dylib $out/lib/libc10.dylib $out/lib/libcaffe2_module_test_dynamic.dylib
-    install_name_tool -change @rpath/libiomp5.dylib $out/lib/libiomp5.dylib $out/lib/libcaffe2_module_test_dynamic.dylib
-    install_name_tool -change @rpath/libtorch.dylib $out/lib/libtorch.dylib $out/lib/libcaffe2_module_test_dynamic.dylib
-    install_name_tool -change @rpath/libtorch_cpu.dylib $out/lib/libtorch_cpu.dylib $out/lib/libcaffe2_module_test_dynamic.dylib
-
-    install_name_tool -change @rpath/libc10.dylib $out/lib/libc10.dylib $out/lib/libcaffe2_detectron_ops.dylib
-    install_name_tool -change @rpath/libiomp5.dylib $out/lib/libiomp5.dylib $out/lib/libcaffe2_detectron_ops.dylib
-    install_name_tool -change @rpath/libtorch.dylib $out/lib/libtorch.dylib $out/lib/libcaffe2_detectron_ops.dylib
-    install_name_tool -change @rpath/libtorch_cpu.dylib $out/lib/libtorch_cpu.dylib $out/lib/libcaffe2_detectron_ops.dylib
-
-    install_name_tool -change @rpath/libc10.dylib $out/lib/libc10.dylib $out/lib/libshm.dylib
-    install_name_tool -change @rpath/libiomp5.dylib $out/lib/libiomp5.dylib $out/lib/libshm.dylib
-    install_name_tool -change @rpath/libtorch.dylib $out/lib/libtorch.dylib $out/lib/libshm.dylib
-    install_name_tool -change @rpath/libtorch_cpu.dylib $out/lib/libtorch_cpu.dylib $out/lib/libshm.dylib
-
-    install_name_tool -change @rpath/libiomp5.dylib $out/lib/libiomp5.dylib $out/lib/libtorch_global_deps.dylib
-    install_name_tool -change @rpath/libtorch_cpu.dylib $out/lib/libtorch_cpu.dylib $out/lib/libtorch_global_deps.dylib
+    for f in $out/lib/*.dylib; do
+        otool -L $f
+    done
+    for f in $out/lib/*.dylib; do
+      install_name_tool -id $out/lib/$(basename $f) $f || true
+      for rpath in $(otool -L $f | grep rpath | awk '{print $1}');do
+        install_name_tool -change $rpath $out/lib/$(basename $rpath) $f
+      done
+      if otool -L $f | grep /usr/lib/libc++ >& /dev/null; then
+        install_name_tool -change /usr/lib/libc++.1.dylib ${libcxx-for-libtorch.outPath}/lib/libc++.1.0.dylib $f
+      fi
+    done
+    for f in $out/lib/*.dylib; do
+        otool -L $f
+    done
   '';
 
   outputs = [ "out" "dev" ];
 
   passthru.tests.cmake = callPackage ./test {
     inherit cudaSupport;
-    cudatoolkit = cudatoolkit_11_1;
-    cudnn = cudnn_cudatoolkit_11_1;
   };
 
   meta = with lib; {
     description = "C++ API of the PyTorch machine learning framework";
     homepage = "https://pytorch.org/";
-    license = licenses.unfree; # Includes CUDA and Intel MKL.
-    maintainers = with maintainers; [ ];
-    platforms = with platforms; linux ++ darwin;
+    # Includes CUDA and Intel MKL, but redistributions of the binary are not limited.
+    # https://docs.nvidia.com/cuda/eula/index.html
+    # https://www.intel.com/content/www/us/en/developer/articles/license/onemkl-license-faq.html
+    license = licenses.bsd3;
+    maintainers = with maintainers; [ junjihashimoto ];
+    platforms = platforms.unix;
   };
 }
diff --git a/pkgs/development/libraries/science/math/libtorch/binary-hashes.nix b/pkgs/development/libraries/science/math/libtorch/binary-hashes.nix
index 6ded62fb87c32..156515f6eb51a 100644
--- a/pkgs/development/libraries/science/math/libtorch/binary-hashes.nix
+++ b/pkgs/development/libraries/science/math/libtorch/binary-hashes.nix
@@ -1,14 +1,19 @@
-version: {
-  x86_64-darwin-cpu = {
-    url = "https://download.pytorch.org/libtorch/cpu/libtorch-macos-${version}.zip";
-    hash = "sha256-TOJ+iQpqazta46y4IzIbfEGMjz/fz+pRDV8fKqriB6Q=";
-  };
-  x86_64-linux-cpu = {
-    url = "https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-${version}%2Bcpu.zip";
-    hash = "sha256-gZMNLCzW3j+eplBqWo6lVvuHS5iRqtMD8NL3MoszsVg=";
-  };
-  x86_64-linux-cuda = {
-    url = "https://download.pytorch.org/libtorch/cu111/libtorch-cxx11-abi-shared-with-deps-${version}%2Bcu111.zip";
-    hash = "sha256-dRu4F8k2SAbtghwrPJNyX0u3tsODCbXfi9EqUdf4xYc=";
+version : builtins.getAttr version {
+  "1.10.0" = {
+    x86_64-darwin-cpu = {
+      name = "libtorch-macos-1.10.0.zip";
+      url = "https://download.pytorch.org/libtorch/cpu/libtorch-macos-1.10.0.zip";
+      hash = "sha256-HSisxHs466c6XwvZEbkV/1kVNBzJOy3uVw9Bh497Vk8=";
+    };
+    x86_64-linux-cpu = {
+      name = "libtorch-cxx11-abi-shared-with-deps-1.10.0-cpu.zip";
+      url = "https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.10.0%2Bcpu.zip";
+      hash = "sha256-wAtA+AZx3HjaFbsrbyfkSXjYM0BP8H5HwCgyHbgJXJ0=";
+    };
+    x86_64-linux-cuda = {
+      name = "libtorch-cxx11-abi-shared-with-deps-1.10.0-cu113.zip";
+      url = "https://download.pytorch.org/libtorch/cu113/libtorch-cxx11-abi-shared-with-deps-1.10.0%2Bcu113.zip";
+      hash = "sha256-jPylK4j0V8SEQ8cZU+O22P7kQ28wanIB0GkBzRGyTj8=";
+    };
   };
 }
diff --git a/pkgs/development/libraries/science/math/libtorch/prefetch.sh b/pkgs/development/libraries/science/math/libtorch/prefetch.sh
new file mode 100755
index 0000000000000..26b24198e235a
--- /dev/null
+++ b/pkgs/development/libraries/science/math/libtorch/prefetch.sh
@@ -0,0 +1,38 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p nix-prefetch-scripts
+
+set -eou pipefail
+
+version=$1
+
+bucket="https://download.pytorch.org/libtorch"
+CUDA_VERSION=cu113
+
+url_and_key_list=(
+  "x86_64-darwin-cpu $bucket/cpu/libtorch-macos-${version}.zip libtorch-macos-${version}.zip"
+  "x86_64-linux-cpu $bucket/cpu/libtorch-cxx11-abi-shared-with-deps-${version}%2Bcpu.zip libtorch-cxx11-abi-shared-with-deps-${version}-cpu.zip"
+  "x86_64-linux-cuda $bucket/${CUDA_VERSION}/libtorch-cxx11-abi-shared-with-deps-${version}%2B${CUDA_VERSION}.zip libtorch-cxx11-abi-shared-with-deps-${version}-${CUDA_VERSION}.zip"
+)
+
+hashfile="binary-hashes-$version.nix"
+echo "  \"$version\" = {" >> $hashfile
+
+for url_and_key in "${url_and_key_list[@]}"; do
+  key=$(echo "$url_and_key" | cut -d' ' -f1)
+  url=$(echo "$url_and_key" | cut -d' ' -f2)
+  name=$(echo "$url_and_key" | cut -d' ' -f3)
+
+  echo "prefetching ${url}..."
+  hash=$(nix hash to-sri --type sha256 $(nix-prefetch-url --unpack "$url" --name "$name"))
+
+  echo "    $key = {" >> $hashfile
+  echo "      name = \"$name\";" >> $hashfile
+  echo "      url = \"$url\";" >> $hashfile
+  echo "      hash = \"$hash\";" >> $hashfile
+  echo "    };" >> $hashfile
+
+  echo
+done
+
+echo "  };" >> $hashfile
+echo "done."
diff --git a/pkgs/development/python-modules/pytorch/bin.nix b/pkgs/development/python-modules/pytorch/bin.nix
index e9bc58321df59..f570a0a5c95a1 100644
--- a/pkgs/development/python-modules/pytorch/bin.nix
+++ b/pkgs/development/python-modules/pytorch/bin.nix
@@ -18,7 +18,7 @@ let
   pyVerNoDot = builtins.replaceStrings [ "." ] [ "" ] python.pythonVersion;
   srcs = import ./binary-hashes.nix version;
   unsupported = throw "Unsupported system";
-  version = "1.9.1";
+  version = "1.10.0";
 in buildPythonPackage {
   inherit version;
 
@@ -59,13 +59,19 @@ in buildPythonPackage {
     done
   '';
 
+  # The wheel-binary is not stripped to avoid the error of `ImportError: libtorch_cuda_cpp.so: ELF load command address/offset not properly aligned.`.
+  dontStrip = true;
+
   pythonImportsCheck = [ "torch" ];
 
   meta = with lib; {
     description = "Open source, prototype-to-production deep learning platform";
     homepage = "https://pytorch.org/";
     changelog = "https://github.com/pytorch/pytorch/releases/tag/v${version}";
-    license = licenses.unfree; # Includes CUDA and Intel MKL.
+    # Includes CUDA and Intel MKL, but redistributions of the binary are not limited.
+    # https://docs.nvidia.com/cuda/eula/index.html
+    # https://www.intel.com/content/www/us/en/developer/articles/license/onemkl-license-faq.html
+    license = licenses.bsd3;
     platforms = platforms.linux;
     maintainers = with maintainers; [ junjihashimoto ];
   };
diff --git a/pkgs/development/python-modules/pytorch/binary-hashes.nix b/pkgs/development/python-modules/pytorch/binary-hashes.nix
index 0fbf9ae91287a..dd3e5dc1ae3ec 100644
--- a/pkgs/development/python-modules/pytorch/binary-hashes.nix
+++ b/pkgs/development/python-modules/pytorch/binary-hashes.nix
@@ -6,21 +6,21 @@
 # To add a new version, run "prefetch.sh 'new-version'" to paste the generated file as follows.
 
 version : builtins.getAttr version {
-  "1.9.1" = {
+  "1.10.0" = {
     x86_64-linux-37 = {
-      name = "torch-1.9.1-cp37-cp37m-linux_x86_64.whl";
-      url = "https://download.pytorch.org/whl/cu111/torch-1.9.1%2Bcu111-cp37-cp37m-linux_x86_64.whl";
-      hash = "sha256-qzXbbpLX+ZlRv41oAyQRk3guU0n/6vuNzWw+nOieL6s=";
+      name = "torch-1.10.0-cp37-cp37m-linux_x86_64.whl";
+      url = "https://download.pytorch.org/whl/cu113/torch-1.10.0%2Bcu113-cp37-cp37m-linux_x86_64.whl";
+      hash = "sha256-KpDbklee2HXSqgrWr1U1nj8EJqUjBWp7SbACw8xtKtg=";
     };
     x86_64-linux-38 = {
-      name = "torch-1.9.1-cp38-cp38-linux_x86_64.whl";
-      url = "https://download.pytorch.org/whl/cu111/torch-1.9.1%2Bcu111-cp38-cp38-linux_x86_64.whl";
-      hash = "sha256-JUbcqugax08/iN1LKfXq0ohSpejmbKhbT0by7qMGAzw=";
+      name = "torch-1.10.0-cp38-cp38-linux_x86_64.whl";
+      url = "https://download.pytorch.org/whl/cu113/torch-1.10.0%2Bcu113-cp38-cp38-linux_x86_64.whl";
+      hash = "sha256-zM3cMriUG9A+3in/ChzOLytRETpe4ju4uXkxasIRQYM=";
     };
     x86_64-linux-39 = {
-      name = "torch-1.9.1-cp39-cp39-linux_x86_64.whl";
-      url = "https://download.pytorch.org/whl/cu111/torch-1.9.1%2Bcu111-cp39-cp39-linux_x86_64.whl";
-      hash = "sha256-wNLLtR9ZxKkVOTzwbAikM5H83pXyH+aPHVFyfrO4c1M=";
+      name = "torch-1.10.0-cp39-cp39-linux_x86_64.whl";
+      url = "https://download.pytorch.org/whl/cu113/torch-1.10.0%2Bcu113-cp39-cp39-linux_x86_64.whl";
+      hash = "sha256-w8UJDh4b5cgDu7ZSvDoKzNH4hiXEyRfvpycNOg+wJOg=";
     };
   };
 }
diff --git a/pkgs/development/python-modules/pytorch/prefetch.sh b/pkgs/development/python-modules/pytorch/prefetch.sh
index 65007f11bf7bc..debf26bfa20a1 100755
--- a/pkgs/development/python-modules/pytorch/prefetch.sh
+++ b/pkgs/development/python-modules/pytorch/prefetch.sh
@@ -1,18 +1,19 @@
 #!/usr/bin/env nix-shell
 #!nix-shell -i bash -p nix-prefetch-scripts
 
+set -eou pipefail
+
 version=$1
 
-bucket="https://download.pytorch.org/whl/cu111"
+bucket="https://download.pytorch.org/whl/cu113"
 
 url_and_key_list=(
-"x86_64-linux-37 $bucket/torch-${version}%2Bcu111-cp37-cp37m-linux_x86_64.whl torch-${version}-cp37-cp37m-linux_x86_64.whl"
-"x86_64-linux-38 $bucket/torch-${version}%2Bcu111-cp38-cp38-linux_x86_64.whl torch-${version}-cp38-cp38-linux_x86_64.whl"
-"x86_64-linux-39 $bucket/torch-${version}%2Bcu111-cp39-cp39-linux_x86_64.whl torch-${version}-cp39-cp39-linux_x86_64.whl"
+  "x86_64-linux-37 $bucket/torch-${version}%2Bcu113-cp37-cp37m-linux_x86_64.whl torch-${version}-cp37-cp37m-linux_x86_64.whl"
+  "x86_64-linux-38 $bucket/torch-${version}%2Bcu113-cp38-cp38-linux_x86_64.whl torch-${version}-cp38-cp38-linux_x86_64.whl"
+  "x86_64-linux-39 $bucket/torch-${version}%2Bcu113-cp39-cp39-linux_x86_64.whl torch-${version}-cp39-cp39-linux_x86_64.whl"
 )
 
-hashfile=binary-hashes-"$version".nix
-rm -f $hashfile
+hashfile="binary-hashes-$version.nix"
 echo "  \"$version\" = {" >> $hashfile
 
 for url_and_key in "${url_and_key_list[@]}"; do
diff --git a/pkgs/development/python-modules/torchaudio/bin.nix b/pkgs/development/python-modules/torchaudio/bin.nix
new file mode 100644
index 0000000000000..1f6ae80b03290
--- /dev/null
+++ b/pkgs/development/python-modules/torchaudio/bin.nix
@@ -0,0 +1,52 @@
+{ lib
+, stdenv
+, buildPythonPackage
+, fetchurl
+, python
+, pytorch-bin
+, pythonOlder
+, pythonAtLeast
+}:
+
+buildPythonPackage rec {
+  pname = "torchaudio";
+  version = "0.10.0";
+  format = "wheel";
+
+  src =
+    let pyVerNoDot = lib.replaceStrings [ "." ] [ "" ] python.pythonVersion;
+        unsupported = throw "Unsupported system";
+        srcs = (import ./binary-hashes.nix version)."${stdenv.system}-${pyVerNoDot}" or unsupported;
+    in fetchurl srcs;
+
+  disabled = ! (pythonAtLeast "3.7" && pythonOlder "3.10");
+
+  propagatedBuildInputs = [
+    pytorch-bin
+  ];
+
+  # The wheel-binary is not stripped to avoid the error of `ImportError: libtorch_cuda_cpp.so: ELF load command address/offset not properly aligned.`.
+  dontStrip = true;
+
+  pythonImportsCheck = [ "torchaudio" ];
+
+  postFixup = ''
+    # Note: after patchelf'ing, libcudart can still not be found. However, this should
+    #       not be an issue, because PyTorch is loaded before torchvision and brings
+    #       in the necessary symbols.
+    patchelf --set-rpath "${lib.makeLibraryPath [ stdenv.cc.cc.lib ]}:${pytorch-bin}/${python.sitePackages}/torch/lib:" \
+      "$out/${python.sitePackages}/torchaudio/_torchaudio.so"
+  '';
+
+  meta = with lib; {
+    description = "PyTorch audio library";
+    homepage = "https://pytorch.org/";
+    changelog = "https://github.com/pytorch/audio/releases/tag/v${version}";
+    # Includes CUDA and Intel MKL, but redistributions of the binary are not limited.
+    # https://docs.nvidia.com/cuda/eula/index.html
+    # https://www.intel.com/content/www/us/en/developer/articles/license/onemkl-license-faq.html
+    license = licenses.bsd3;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ junjihashimoto ];
+  };
+}
diff --git a/pkgs/development/python-modules/torchaudio/binary-hashes.nix b/pkgs/development/python-modules/torchaudio/binary-hashes.nix
new file mode 100644
index 0000000000000..764b9db426b9a
--- /dev/null
+++ b/pkgs/development/python-modules/torchaudio/binary-hashes.nix
@@ -0,0 +1,26 @@
+# Warning: Need to update at the same time as pytorch-bin
+#
+# Precompiled wheels can be found at:
+# https://download.pytorch.org/whl/torch_stable.html
+
+# To add a new version, run "prefetch.sh 'new-version'" to paste the generated file as follows.
+
+version : builtins.getAttr version {
+  "0.10.0" = {
+    x86_64-linux-37 = {
+      name = "torchaudio-0.10.0-cp37-cp37m-linux_x86_64.whl";
+      url = "https://download.pytorch.org/whl/cu113/torchaudio-0.10.0%2Bcu113-cp37-cp37m-linux_x86_64.whl";
+      hash = "sha256-FspXTTODdkO0nPUJcJm8+vLIvckUa8gRfBPBT9LcKPw=";
+    };
+    x86_64-linux-38 = {
+      name = "torchaudio-0.10.0-cp38-cp38-linux_x86_64.whl";
+      url = "https://download.pytorch.org/whl/cu113/torchaudio-0.10.0%2Bcu113-cp38-cp38-linux_x86_64.whl";
+      hash = "sha256-Mf7QdXBSIIWRfT7ACthEwFA1V2ieid8legbMnRQnzqI=";
+    };
+    x86_64-linux-39 = {
+      name = "torchaudio-0.10.0-cp39-cp39-linux_x86_64.whl";
+      url = "https://download.pytorch.org/whl/cu113/torchaudio-0.10.0%2Bcu113-cp39-cp39-linux_x86_64.whl";
+      hash = "sha256-LMSGNdmku1iHRy1jCRTTOYcQlRL+Oc9jjZC1nx++skA=";
+    };
+  };
+}
diff --git a/pkgs/development/python-modules/torchaudio/prefetch.sh b/pkgs/development/python-modules/torchaudio/prefetch.sh
new file mode 100755
index 0000000000000..4e62ab4ed359f
--- /dev/null
+++ b/pkgs/development/python-modules/torchaudio/prefetch.sh
@@ -0,0 +1,37 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p nix-prefetch-scripts
+
+set -eou pipefail
+
+version=$1
+
+bucket="https://download.pytorch.org/whl/cu113"
+
+url_and_key_list=(
+  "x86_64-linux-37 $bucket/torchaudio-${version}%2Bcu113-cp37-cp37m-linux_x86_64.whl torchaudio-${version}-cp37-cp37m-linux_x86_64.whl"
+  "x86_64-linux-38 $bucket/torchaudio-${version}%2Bcu113-cp38-cp38-linux_x86_64.whl torchaudio-${version}-cp38-cp38-linux_x86_64.whl"
+  "x86_64-linux-39 $bucket/torchaudio-${version}%2Bcu113-cp39-cp39-linux_x86_64.whl torchaudio-${version}-cp39-cp39-linux_x86_64.whl"
+)
+
+hashfile=binary-hashes-"$version".nix
+echo "  \"$version\" = {" >> $hashfile
+
+for url_and_key in "${url_and_key_list[@]}"; do
+  key=$(echo "$url_and_key" | cut -d' ' -f1)
+  url=$(echo "$url_and_key" | cut -d' ' -f2)
+  name=$(echo "$url_and_key" | cut -d' ' -f3)
+
+  echo "prefetching ${url}..."
+  hash=$(nix hash to-sri --type sha256 `nix-prefetch-url "$url" --name "$name"`)
+
+  echo "    $key = {" >> $hashfile
+  echo "      name = \"$name\";" >> $hashfile
+  echo "      url = \"$url\";" >> $hashfile
+  echo "      hash = \"$hash\";" >> $hashfile
+  echo "    };" >> $hashfile
+
+  echo
+done
+
+echo "  };" >> $hashfile
+echo "done."
diff --git a/pkgs/development/python-modules/torchvision/bin.nix b/pkgs/development/python-modules/torchvision/bin.nix
index a69531f2d0626..f7041dbb519de 100644
--- a/pkgs/development/python-modules/torchvision/bin.nix
+++ b/pkgs/development/python-modules/torchvision/bin.nix
@@ -15,7 +15,7 @@ let
   pyVerNoDot = builtins.replaceStrings [ "." ] [ "" ] python.pythonVersion;
   srcs = import ./binary-hashes.nix version;
   unsupported = throw "Unsupported system";
-  version = "0.10.1";
+  version = "0.11.1";
 in buildPythonPackage {
   inherit version;
 
@@ -36,6 +36,9 @@ in buildPythonPackage {
     pytorch-bin
   ];
 
+  # The wheel-binary is not stripped to avoid the error of `ImportError: libtorch_cuda_cpp.so: ELF load command address/offset not properly aligned.`.
+  dontStrip = true;
+
   pythonImportsCheck = [ "torchvision" ];
 
   postFixup = let
@@ -52,6 +55,9 @@ in buildPythonPackage {
     description = "PyTorch vision library";
     homepage = "https://pytorch.org/";
     changelog = "https://github.com/pytorch/vision/releases/tag/v${version}";
+    # Includes CUDA and Intel MKL, but redistributions of the binary are not limited.
+    # https://docs.nvidia.com/cuda/eula/index.html
+    # https://www.intel.com/content/www/us/en/developer/articles/license/onemkl-license-faq.html
     license = licenses.bsd3;
     platforms = platforms.linux;
     maintainers = with maintainers; [ junjihashimoto ];
diff --git a/pkgs/development/python-modules/torchvision/binary-hashes.nix b/pkgs/development/python-modules/torchvision/binary-hashes.nix
index 239db8bdb8648..b608bab24409f 100644
--- a/pkgs/development/python-modules/torchvision/binary-hashes.nix
+++ b/pkgs/development/python-modules/torchvision/binary-hashes.nix
@@ -6,21 +6,21 @@
 # To add a new version, run "prefetch.sh 'new-version'" to paste the generated file as follows.
 
 version : builtins.getAttr version {
-  "0.10.1" = {
+  "0.11.1" = {
     x86_64-linux-37 = {
-      name = "torchvision-0.10.1-cp37-cp37m-linux_x86_64.whl";
-      url = "https://download.pytorch.org/whl/cu111/torchvision-0.10.1%2Bcu111-cp37-cp37m-linux_x86_64.whl";
-      hash = "sha256-1MdsCrOLGkYpfbtv011/b6QG+yKaE+O0jUKeUVj2BJY=";
+      name = "torchvision-0.11.1-cp37-cp37m-linux_x86_64.whl";
+      url = "https://download.pytorch.org/whl/cu113/torchvision-0.11.1%2Bcu113-cp37-cp37m-linux_x86_64.whl";
+      hash = "sha256-2xKWqWNKqmOMyVJnPfbtF+B9PQ7z4S66J1T3P8EvM0I=";
     };
     x86_64-linux-38 = {
-      name = "torchvision-0.10.1-cp38-cp38-linux_x86_64.whl";
-      url = "https://download.pytorch.org/whl/cu111/torchvision-0.10.1%2Bcu111-cp38-cp38-linux_x86_64.whl";
-      hash = "sha256-LtmsnNSa9g3tCdjW1jhu7AZlGgfyYIVh5/2R+WwcxSo=";
+      name = "torchvision-0.11.1-cp38-cp38-linux_x86_64.whl";
+      url = "https://download.pytorch.org/whl/cu113/torchvision-0.11.1%2Bcu113-cp38-cp38-linux_x86_64.whl";
+      hash = "sha256-bFxvJaNEomytXXANHng+oU8YSLGkuO/TSzkoDskkaIE=";
     };
     x86_64-linux-39 = {
-      name = "torchvision-0.10.1-cp39-cp39-linux_x86_64.whl";
-      url = "https://download.pytorch.org/whl/cu111/torchvision-0.10.1%2Bcu111-cp39-cp39-linux_x86_64.whl";
-      hash = "sha256-ZOC/angyiLeOhe+7dAs0W6XlQRKK00T/iI+aBgFNpA0=";
+      name = "torchvision-0.11.1-cp39-cp39-linux_x86_64.whl";
+      url = "https://download.pytorch.org/whl/cu113/torchvision-0.11.1%2Bcu113-cp39-cp39-linux_x86_64.whl";
+      hash = "sha256-ysN3LmSKR+FVKYGnCGQJqa8lVApVT5rPMO+NHmmazAc=";
     };
   };
 }
diff --git a/pkgs/development/python-modules/torchvision/prefetch.sh b/pkgs/development/python-modules/torchvision/prefetch.sh
index f57ac96bdb63e..686d1b3e62002 100755
--- a/pkgs/development/python-modules/torchvision/prefetch.sh
+++ b/pkgs/development/python-modules/torchvision/prefetch.sh
@@ -1,18 +1,19 @@
 #!/usr/bin/env nix-shell
 #!nix-shell -i bash -p nix-prefetch-scripts
 
+set -eou pipefail
+
 version=$1
 
-bucket="https://download.pytorch.org/whl/cu111"
+bucket="https://download.pytorch.org/whl/cu113"
 
 url_and_key_list=(
-"x86_64-linux-37 $bucket/torchvision-${version}%2Bcu111-cp37-cp37m-linux_x86_64.whl torchvision-${version}-cp37-cp37m-linux_x86_64.whl"
-"x86_64-linux-38 $bucket/torchvision-${version}%2Bcu111-cp38-cp38-linux_x86_64.whl torchvision-${version}-cp38-cp38-linux_x86_64.whl"
-"x86_64-linux-39 $bucket/torchvision-${version}%2Bcu111-cp39-cp39-linux_x86_64.whl torchvision-${version}-cp39-cp39-linux_x86_64.whl"
+  "x86_64-linux-37 $bucket/torchvision-${version}%2Bcu113-cp37-cp37m-linux_x86_64.whl torchvision-${version}-cp37-cp37m-linux_x86_64.whl"
+  "x86_64-linux-38 $bucket/torchvision-${version}%2Bcu113-cp38-cp38-linux_x86_64.whl torchvision-${version}-cp38-cp38-linux_x86_64.whl"
+  "x86_64-linux-39 $bucket/torchvision-${version}%2Bcu113-cp39-cp39-linux_x86_64.whl torchvision-${version}-cp39-cp39-linux_x86_64.whl"
 )
 
-hashfile=binary-hashes-"$version".nix
-rm -f $hashfile
+hashfile="binary-hashes-$version.nix"
 echo "  \"$version\" = {" >> $hashfile
 
 for url_and_key in "${url_and_key_list[@]}"; do
diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index 24e242d3e1e7e..e7b7e9017fac8 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -9344,6 +9344,8 @@ in {
 
   toposort = callPackage ../development/python-modules/toposort { };
 
+  torchaudio-bin = callPackage ../development/python-modules/torchaudio/bin.nix { };
+
   torchgpipe = callPackage ../development/python-modules/torchgpipe { };
 
   torchvision = callPackage ../development/python-modules/torchvision { };