2024-06-05 15:53:02 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
stdenv,
|
|
|
|
buildPythonPackage,
|
|
|
|
autoAddDriverRunpath,
|
|
|
|
fetchurl,
|
|
|
|
python,
|
|
|
|
pythonAtLeast,
|
|
|
|
pythonOlder,
|
|
|
|
addOpenGLRunpath,
|
|
|
|
cudaPackages,
|
|
|
|
future,
|
|
|
|
numpy,
|
|
|
|
autoPatchelfHook,
|
|
|
|
pyyaml,
|
|
|
|
requests,
|
|
|
|
setuptools,
|
|
|
|
typing-extensions,
|
|
|
|
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-05-15 15:35:15 +00:00
|
|
|
version = "2.3.0";
|
2024-06-05 15:53:02 +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";
|
|
|
|
|
2024-05-15 15:35:15 +00:00
|
|
|
disabled = (pythonOlder "3.8") || (pythonAtLeast "3.13");
|
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
|
2024-04-21 15:54:59 +00:00
|
|
|
autoAddDriverRunpath
|
2020-09-25 04:45:31 +00:00
|
|
|
];
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
buildInputs = lib.optionals stdenv.isLinux (
|
|
|
|
with cudaPackages;
|
|
|
|
[
|
|
|
|
# $out/${sitePackages}/nvfuser/_C*.so wants libnvToolsExt.so.1 but torch/lib only ships
|
|
|
|
# libnvToolsExt-$hash.so.1
|
|
|
|
cuda_nvtx
|
2024-02-29 20:09:43 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
cuda_cudart
|
|
|
|
cuda_cupti
|
|
|
|
cuda_nvrtc
|
|
|
|
cudnn
|
|
|
|
libcublas
|
|
|
|
libcufft
|
|
|
|
libcurand
|
|
|
|
libcusolver
|
|
|
|
libcusparse
|
|
|
|
nccl
|
|
|
|
]
|
|
|
|
);
|
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
|
2024-06-05 15:53:02 +00:00
|
|
|
] ++ lib.optionals (stdenv.isLinux && 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"
|
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.
|
2024-02-29 20:09:43 +00:00
|
|
|
# torch-bin used to vendor CUDA. It still links against CUDA and MKL.
|
2024-06-05 15:53:02 +00:00
|
|
|
license = with licenses; [
|
|
|
|
bsd3
|
|
|
|
issl
|
|
|
|
unfreeRedistributable
|
|
|
|
];
|
2022-06-26 10:26:21 +00:00
|
|
|
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
|
2024-06-05 15:53:02 +00:00
|
|
|
platforms = [
|
|
|
|
"aarch64-darwin"
|
|
|
|
"aarch64-linux"
|
|
|
|
"x86_64-linux"
|
|
|
|
];
|
|
|
|
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
|
|
|
};
|
|
|
|
}
|