2023-03-15 16:39:30 +00:00
|
|
|
{ buildPythonPackage
|
2021-01-05 17:05:55 +00:00
|
|
|
, fetchFromGitHub
|
2023-03-15 16:39:30 +00:00
|
|
|
, lib
|
2021-01-05 17:05:55 +00:00
|
|
|
, libjpeg_turbo
|
|
|
|
, libpng
|
2023-03-15 16:39:30 +00:00
|
|
|
, ninja
|
2020-04-24 23:36:52 +00:00
|
|
|
, numpy
|
|
|
|
, pillow
|
2021-01-05 17:05:55 +00:00
|
|
|
, pytest
|
2023-03-15 16:39:30 +00:00
|
|
|
, scipy
|
|
|
|
, symlinkJoin
|
|
|
|
, torch
|
|
|
|
, which
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
2021-08-08 23:34:03 +00:00
|
|
|
let
|
2023-03-24 00:07:29 +00:00
|
|
|
inherit (torch) cudaCapabilities cudaPackages cudaSupport;
|
|
|
|
inherit (cudaPackages) backendStdenv cudaVersion;
|
2023-03-15 16:39:30 +00:00
|
|
|
|
|
|
|
# NOTE: torchvision doesn't use cudnn; torch does!
|
|
|
|
# For this reason it is not included.
|
|
|
|
cuda-common-redist = with cudaPackages; [
|
|
|
|
cuda_cccl # <thrust/*>
|
|
|
|
libcublas # cublas_v2.h
|
|
|
|
libcusolver # cusolverDn.h
|
|
|
|
libcusparse # cusparse.h
|
|
|
|
];
|
2022-04-15 01:41:22 +00:00
|
|
|
|
2023-03-15 16:39:30 +00:00
|
|
|
cuda-native-redist = symlinkJoin {
|
|
|
|
name = "cuda-native-redist-${cudaVersion}";
|
|
|
|
paths = with cudaPackages; [
|
|
|
|
cuda_cudart # cuda_runtime.h
|
|
|
|
cuda_nvcc
|
|
|
|
] ++ cuda-common-redist;
|
2021-08-08 23:34:03 +00:00
|
|
|
};
|
2023-03-15 16:39:30 +00:00
|
|
|
|
|
|
|
cuda-redist = symlinkJoin {
|
|
|
|
name = "cuda-redist-${cudaVersion}";
|
|
|
|
paths = cuda-common-redist;
|
|
|
|
};
|
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
pname = "torchvision";
|
2023-05-24 13:37:59 +00:00
|
|
|
version = "0.15.2";
|
2023-03-15 16:39:30 +00:00
|
|
|
in
|
|
|
|
buildPythonPackage {
|
|
|
|
inherit pname version;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "pytorch";
|
|
|
|
repo = "vision";
|
2022-08-12 12:06:08 +00:00
|
|
|
rev = "refs/tags/v${version}";
|
2023-05-24 13:37:59 +00:00
|
|
|
hash = "sha256-KNbOgd6PCINZqZ24c/Ev+ODux3ik5iUlzem9uUfQArM=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-03-15 16:39:30 +00:00
|
|
|
nativeBuildInputs = [ libpng ninja which ] ++ lib.optionals cudaSupport [ cuda-native-redist ];
|
2021-01-05 17:05:55 +00:00
|
|
|
|
2023-03-15 16:39:30 +00:00
|
|
|
buildInputs = [ libjpeg_turbo libpng ] ++ lib.optionals cudaSupport [ cuda-redist ];
|
2021-01-05 17:05:55 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
propagatedBuildInputs = [ numpy pillow torch scipy ];
|
2021-01-05 17:05:55 +00:00
|
|
|
|
2023-03-15 16:39:30 +00:00
|
|
|
preConfigure = ''
|
|
|
|
export TORCHVISION_INCLUDE="${libjpeg_turbo.dev}/include/"
|
|
|
|
export TORCHVISION_LIBRARY="${libjpeg_turbo}/lib/"
|
|
|
|
''
|
|
|
|
# NOTE: We essentially override the compilers provided by stdenv because we don't have a hook
|
|
|
|
# for cudaPackages to swap in compilers supported by NVCC.
|
|
|
|
+ lib.optionalString cudaSupport ''
|
2023-03-24 00:07:29 +00:00
|
|
|
export CC=${backendStdenv.cc}/bin/cc
|
|
|
|
export CXX=${backendStdenv.cc}/bin/c++
|
|
|
|
export TORCH_CUDA_ARCH_LIST="${lib.concatStringsSep ";" cudaCapabilities}"
|
2021-08-08 23:34:03 +00:00
|
|
|
export FORCE_CUDA=1
|
|
|
|
'';
|
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
# tries to download many datasets for tests
|
|
|
|
doCheck = false;
|
|
|
|
|
2023-03-15 16:39:30 +00:00
|
|
|
pythonImportsCheck = [ "torchvision" ];
|
2021-01-05 17:05:55 +00:00
|
|
|
checkPhase = ''
|
|
|
|
HOME=$TMPDIR py.test test --ignore=test/test_datasets_download.py
|
|
|
|
'';
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeCheckInputs = [ pytest ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "PyTorch vision library";
|
2021-01-05 17:05:55 +00:00
|
|
|
homepage = "https://pytorch.org/";
|
|
|
|
license = licenses.bsd3;
|
2021-08-08 23:34:03 +00:00
|
|
|
platforms = with platforms; linux ++ lib.optionals (!cudaSupport) darwin;
|
2021-02-17 17:02:09 +00:00
|
|
|
maintainers = with maintainers; [ ericsagnes ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|