2021-01-15 22:18:51 +00:00
|
|
|
{ lib, stdenv
|
2020-09-25 04:45:31 +00:00
|
|
|
, buildPythonPackage
|
|
|
|
, fetchurl
|
|
|
|
, python
|
2023-05-24 13:37:59 +00:00
|
|
|
, pythonAtLeast
|
|
|
|
, pythonOlder
|
2020-09-25 04:45:31 +00:00
|
|
|
, addOpenGLRunpath
|
2023-05-24 13:37:59 +00:00
|
|
|
, cudaPackages
|
2020-09-25 04:45:31 +00:00
|
|
|
, future
|
|
|
|
, numpy
|
2023-05-24 13:37:59 +00:00
|
|
|
, autoPatchelfHook
|
2020-09-25 04:45:31 +00:00
|
|
|
, pyyaml
|
|
|
|
, requests
|
2022-01-19 23:45:15 +00:00
|
|
|
, setuptools
|
2020-11-03 02:18:15 +00:00
|
|
|
, typing-extensions
|
2023-05-24 13:37:59 +00:00
|
|
|
, sympy
|
|
|
|
, jinja2
|
|
|
|
, networkx
|
|
|
|
, filelock
|
|
|
|
, openai-triton
|
2020-09-25 04:45:31 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
pyVerNoDot = builtins.replaceStrings [ "." ] [ "" ] python.pythonVersion;
|
2020-11-03 02:18:15 +00:00
|
|
|
srcs = import ./binary-hashes.nix version;
|
2020-09-25 04:45:31 +00:00
|
|
|
unsupported = throw "Unsupported system";
|
2024-01-02 11:29:13 +00:00
|
|
|
version = "2.1.2";
|
2020-09-25 04:45:31 +00:00
|
|
|
in buildPythonPackage {
|
2020-11-03 02:18:15 +00:00
|
|
|
inherit version;
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
pname = "torch";
|
|
|
|
# Don't forget to update torch to the same version.
|
2020-09-25 04:45:31 +00:00
|
|
|
|
|
|
|
format = "wheel";
|
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
disabled = (pythonOlder "3.8") || (pythonAtLeast "3.12");
|
2020-09-25 04:45:31 +00:00
|
|
|
|
|
|
|
src = fetchurl srcs."${stdenv.system}-${pyVerNoDot}" or unsupported;
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
nativeBuildInputs = lib.optionals stdenv.isLinux [
|
2020-09-25 04:45:31 +00:00
|
|
|
addOpenGLRunpath
|
2023-05-24 13:37:59 +00:00
|
|
|
autoPatchelfHook
|
|
|
|
cudaPackages.autoAddOpenGLRunpathHook
|
2020-09-25 04:45:31 +00:00
|
|
|
];
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
buildInputs = lib.optionals stdenv.isLinux (with cudaPackages; [
|
2023-05-24 13:37:59 +00:00
|
|
|
# $out/${sitePackages}/nvfuser/_C*.so wants libnvToolsExt.so.1 but torch/lib only ships
|
|
|
|
# libnvToolsExt-$hash.so.1
|
|
|
|
cuda_nvtx
|
2023-07-15 17:15:38 +00:00
|
|
|
]);
|
2023-05-24 13:37:59 +00:00
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
autoPatchelfIgnoreMissingDeps = lib.optionals stdenv.isLinux [
|
2023-05-24 13:37:59 +00:00
|
|
|
# This is the hardware-dependent userspace driver that comes from
|
|
|
|
# nvidia_x11 package. It must be deployed at runtime in
|
|
|
|
# /run/opengl-driver/lib or pointed at by LD_LIBRARY_PATH variable, rather
|
|
|
|
# than pinned in runpath
|
|
|
|
"libcuda.so.1"
|
|
|
|
];
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
propagatedBuildInputs = [
|
|
|
|
future
|
|
|
|
numpy
|
|
|
|
pyyaml
|
|
|
|
requests
|
2022-01-19 23:45:15 +00:00
|
|
|
setuptools
|
2020-11-03 02:18:15 +00:00
|
|
|
typing-extensions
|
2023-05-24 13:37:59 +00:00
|
|
|
sympy
|
|
|
|
jinja2
|
|
|
|
networkx
|
|
|
|
filelock
|
|
|
|
] ++ lib.optionals stdenv.isx86_64 [
|
|
|
|
openai-triton
|
2020-11-03 02:18:15 +00:00
|
|
|
];
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
postInstall = ''
|
|
|
|
# ONNX conversion
|
|
|
|
rm -rf $out/bin
|
|
|
|
'';
|
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
postFixup = lib.optionalString stdenv.isLinux ''
|
2023-05-24 13:37:59 +00:00
|
|
|
addAutoPatchelfSearchPath "$out/${python.sitePackages}/torch/lib"
|
|
|
|
|
|
|
|
patchelf $out/${python.sitePackages}/torch/lib/libcudnn.so.8 --add-needed libcudnn_cnn_infer.so.8
|
|
|
|
|
|
|
|
pushd $out/${python.sitePackages}/torch/lib || exit 1
|
|
|
|
for LIBNVRTC in ./libnvrtc*
|
|
|
|
do
|
|
|
|
case "$LIBNVRTC" in
|
|
|
|
./libnvrtc-builtins*) true;;
|
|
|
|
./libnvrtc*) patchelf "$LIBNVRTC" --add-needed libnvrtc-builtins* ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
popd || exit 1
|
2020-09-25 04:45:31 +00:00
|
|
|
'';
|
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
# 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;
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
pythonImportsCheck = [ "torch" ];
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2022-09-09 14:08:57 +00:00
|
|
|
description = "PyTorch: Tensors and Dynamic neural networks in Python with strong GPU acceleration";
|
2020-09-25 04:45:31 +00:00
|
|
|
homepage = "https://pytorch.org/";
|
2021-05-20 23:08:51 +00:00
|
|
|
changelog = "https://github.com/pytorch/pytorch/releases/tag/v${version}";
|
2021-12-06 16:07:01 +00:00
|
|
|
# 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
|
2023-05-24 13:37:59 +00:00
|
|
|
# torch's license is BSD3.
|
|
|
|
# torch-bin includes CUDA and MKL binaries, therefore unfreeRedistributable is set.
|
|
|
|
license = with licenses; [ bsd3 issl unfreeRedistributable ];
|
2022-06-26 10:26:21 +00:00
|
|
|
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
|
2023-02-22 10:55:15 +00:00
|
|
|
platforms = [ "aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux" ];
|
2022-04-27 09:35:20 +00:00
|
|
|
hydraPlatforms = []; # output size 3.2G on 1.11.0
|
2021-09-26 12:46:18 +00:00
|
|
|
maintainers = with maintainers; [ junjihashimoto ];
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
|
|
|
}
|