@@ -1,6 +1,6 @@
1−{ buildPythonPackage, pythonOlder,
1+{ stdenv, fetchurl, buildPythonPackage, pythonOlder,
22 cudaSupport ? false, cudatoolkit ? null, cudnn ? null,
3− fetchFromGitHub, lib, numpy, pyyaml, cffi, typing, cmake,
3+ fetchFromGitHub, lib, numpy, pyyaml, cffi, typing, cmake, hypothesis, numactl,
44 linkFarm, symlinkJoin,
55 utillinux, which }:
66
@@ -25,7 +25,7 @@ let
2525 "LD_LIBRARY_PATH=${cudaStub}\${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} ";
2626
2727in buildPythonPackage rec {
28− version = "0.4.1";
28+ version = "1.0.0";
2929 pname = "pytorch";
3030
3131 src = fetchFromGitHub {
@@ -33,9 +33,17 @@ in buildPythonPackage rec {
3333 repo = "pytorch";
3434 rev = "v${version}";
3535 fetchSubmodules = true;
36− sha256 = "1cr8h47jxgfar5bamyvlayvqymnb2qvp7rr0ka2d2d4rdldf9lrp";
36+ sha256 = "076cpbig4sywn9vv674c0xdg832sdrd5pk1d0725pjkm436kpvlm";
3737 };
3838
39+ patches =
40+ [ # Skips two tests that are only meant to run on multi GPUs
41+ (fetchurl {
42+ url = "https://github.com/pytorch/pytorch/commit/bfa666eb0deebac21b03486e26642fd70d66e478.patch";
43+ sha256 = "1fgblcj02gjc0y62svwc5gnml879q3x2z7m69c9gax79dpr37s9i";
44+ })
45+ ];
46+
3947 preConfigure = lib.optionalString cudaSupport ''
4048 export CC=${cudatoolkit.cc}/bin/gcc CXX=${cudatoolkit.cc}/bin/g++
4149 '' + lib.optionalString (cudaSupport && cudnn != null) ''
@@ -58,12 +66,24 @@ in buildPythonPackage rec {
5866 done
5967 '';
6068
69+ # Override the (weirdly) wrong version set by default. See
70+ # https://github.com/NixOS/nixpkgs/pull/52437#issuecomment-449718038
71+ # https://github.com/pytorch/pytorch/blob/v1.0.0/setup.py#L267
72+ PYTORCH_BUILD_VERSION = version;
73+ PYTORCH_BUILD_NUMBER = 0;
74+
75+ # Suppress a weird warning in mkl-dnn, part of ideep in pytorch
76+ # (upstream seems to have fixed this in the wrong place?)
77+ # https://github.com/intel/mkl-dnn/commit/8134d346cdb7fe1695a2aa55771071d455fae0bc
78+ NIX_CFLAGS_COMPILE = lib.optionals (numpy.blasImplementation == "mkl") [ "-Wno-error=array-bounds" ];
79+
6180 buildInputs = [
6281 cmake
6382 numpy.blas
6483 utillinux
6584 which
66− ] ++ lib.optionals cudaSupport [cudatoolkit_joined cudnn];
85+ ] ++ lib.optionals cudaSupport [ cudatoolkit_joined cudnn ]
86+ ++ lib.optionals stdenv.isLinux [ numactl ];
6787
6888 propagatedBuildInputs = [
6989 cffi
@@ -71,15 +91,16 @@ in buildPythonPackage rec {
7191 pyyaml
7292 ] ++ lib.optional (pythonOlder "3.5") typing;
7393
94+ checkInputs = [ hypothesis ];
7495 checkPhase = ''
75− ${cudaStubEnv}python test/run_test.py --exclude dataloader sparse torch utils distributed
96+ ${cudaStubEnv}python test/run_test.py --exclude dataloader sparse torch utils thd_distributed distributed cpp_extensions
7697 '';
7798
7899 meta = {
79− description = "Tensors and Dynamic neural networks in Python with strong GPU acceleration.";
80− homepage = https://pytorch.org/;
81− license = lib.licenses.bsd3;
82− platforms = lib.platforms.linux;
83− maintainers = with lib.maintainers; [ teh ];
100+ description = "Open source, prototype-to-production deep learning platform";
101+ homepage = https://pytorch.org/;
102+ license = lib.licenses.bsd3;
103+ platforms = lib.platforms.linux;
104+ maintainers = with lib.maintainers; [ teh thoughtpolice ];
84105 };
85106}