Repository: spack/spack

Issue:
Installation Issue: py-torch fails to fetch sub-repos when running without networking
This is happening @ Argonne Leadership Computing Facility, for the Theta supercomputer.  I am trying to install py-torch however it can not compile on the login nodes, since they are haswell chips and the compute nodes are KNL (I think this is the cause, AVX512 is missing, but it's not clear).

Installing on the login nodes fails for unclear reasons:
```
==> Error: ProcessError: Command exited with status -4:
    '/soft/interpreters/python/3.6/intel/2019.3.075/bin/python3.6' '-s' 'setup.py' '--no-user-cfg' 'install' '--prefix=/lus/theta-fs0/software/datascience/spack/opt/spack/cray-cnl6-mic_knl/gcc-8.3.0/py-torch-1.3.1-hbkhwn36w556jas6nexjb3zkh3id2twq' '--single-version-externally-managed' '--root=/'
See build log for details:
  /tmp/cadams/spack-stage/spack-stage-py-torch-1.3.1-hbkhwn36w556jas6nexjb3zkh3id2twq/spack-build-out.txt
```

There is no extra information in the file specified.

Installing on the compute nodes ought to satisfy the build requirement, however I think py-torch pulls from sub repositories and we don't have access to networking on compute nodes:

```
==> Warning: Fetching from mirror without a checksum!
  This package is normally checked out from a version control system, but it has been archived on a spack mirror.  This means we cannot know a checksum for the tarball in advance. Be sure that your connection to this mirror is secure!
==> Error: ProcessError: Command exited with status 1:
    '/soft/interpreters/python/3.6/intel/2019.3.075/bin/python3.6' '-s' 'setup.py' '--no-user-cfg' 'install' '--prefix=/lus/theta-fs0/software/datascience/spack/opt/spack/cray-cnl6-mic_knl/gcc-8.3.0/py-torch-1.3.1-hbkhwn36w556jas6nexjb3zkh3id2twq' '--single-version-externally-managed' '--root=/'

2 errors found in build log:
     92     Cloning into 'psimd'...
     93     fatal: unable to access 'https://github.com/Maratyszcza/psimd.git/': Failed to connect to github.com port 443: Connection timed out
     94     Cloning into 'psimd'...
     95     fatal: unable to access 'https://github.com/Maratyszcza/psimd.git/': Failed to connect to github.com port 443: Connection timed out
     96     -- Had to git clone more than once:
     97               3 times.
  >> 98     CMake Error at /tmp/cadams/spack-stage/spack-stage-py-torch-1.3.1-hbkhwn36w556jas6nexjb3zkh3id2twq/spack-src/build/confu-deps/psimd-download/psimd-prefix/tmp/psimd-gitclone.cmake:66 (message):
     99       Failed to clone repository: 'https://github.com/Maratyszcza/psimd.git'
     100
     101
     102    ninja: build stopped: subcommand failed.
  >> 103    CMake Error at third_party/FP16/CMakeLists.txt:94 (ADD_SUBDIRECTORY):
     104      ADD_SUBDIRECTORY given source
     105      "/tmp/cadams/spack-stage/spack-stage-py-torch-1.3.1-hbkhwn36w556jas6nexjb3zkh3id2twq/spack-src/build/confu-srcs/psimd"
     106      which is not an existing directory.
     107
     108
     109    -- Found system Eigen at /lus/theta-fs0/software/datascience/spack/opt/spack/cray-cnl6-mic_knl/gcc-8.3.0/eigen-3.3.7-rnf3w44mxhjijj7ok2yaypcttpa3wy7z/include/eigen3

See build log for details:
  /tmp/cadams/spack-stage/spack-stage-py-torch-1.3.1-hbkhwn36w556jas6nexjb3zkh3id2twq/spack-build-out.txt
```

I tried to fetch all of the packages needed for the build prior to running the build script, however it doesn't seem to have the psimd submodule when it goes to install.  Any ideas how to fetch this so it doesn't need to compile?


Discussion:
When you try to install on the login nodes, are you setting the `target`? What does `spack spec py-torch` look like? I don't have a ton of experience with cross-compilation, but this should be supported.

As for the compute node installation, yes, the `py-torch` package currently requires internet access to install. I was talking to someone at SC who was telling me how they manage to install things like PyTorch and TensorFlow on air-gapped networks but I can't remember who it was. This is definitely something we would like to support, so if anyone knows how to build PyTorch without internet access, please comment on this issue.
I'm using the cray compiler wrappers which automatically include the -march=knl flags for compilation on the compute nodes:
```cadams@thetalogin5 : ~
$ spack find
==> 14 installed packages
-- cray-cnl6-mic_knl / gcc@8.3.0 --------------------------------
cmake@3.16.2          intel-mkl-dnn@1.1.1  protobuf@3.10.1    py-pybind11@2.4.3     python@3.6.8
eigen@3.3.7           libyaml@0.2.2        py-cython@0.29.14  py-pyyaml@5.1.2       zlib@1.2.11
intel-mkl@2020.0.166  ninja@1.9.0          py-numpy@1.18.1    py-setuptools@41.4.0

cadams@thetalogin5 : ~
$ spack compiler info gcc@8.3.0
gcc@8.3.0:
	paths:
		cc = cc
		cxx = CC
		f77 = ftn
		fc = ftn
	modules  = ['PrgEnv-gnu', 'gcc/8.3.0']
	operating system  = cnl6
```

I was expecting the `space fetch` command to recursively chase down the git submodules, since it is trying to do that at build time.

Is it possible to pull the archive myself, get the submodules, tar it, and tell spack about it as a local cache to use?

> I was expecting the `spack fetch` command to recursively chase down the git submodules, since it is trying to do that at build time.

It does, if you have internet access:
```console
$ spack -d fetch py-torch
...
==> [2020-01-15-14:52:19.529809] Cloning git repository: https://github.com/pytorch/pytorch.git at tag v1.3.1
==> [2020-01-15-14:52:19.531112] '/usr/bin/git' '--version'
==> [2020-01-15-14:52:19.564839] '/usr/bin/git' '--version'
==> [2020-01-15-14:52:19.593728] '/usr/bin/git' '--version'
==> [2020-01-15-14:52:19.624314] '/usr/bin/git' 'clone' '--branch' 'v1.3.1' '--single-branch' '--depth' '1' 'https://github.com/pytorch/pytorch.git'
Cloning into 'pytorch'...
remote: Enumerating objects: 6348, done.
remote: Counting objects: 100% (6348/6348), done.
remote: Compressing objects: 100% (5746/5746), done.
remote: Total 6348 (delta 855), reused 2246 (delta 451), pack-reused 0
Receiving objects: 100% (6348/6348), 9.75 MiB | 5.77 MiB/s, done.
Resolving deltas: 100% (855/855), done.
Checking out files: 100% (5986/5986), done.
==> [2020-01-15-14:52:26.707810] '/usr/bin/git' '--version'
==> [2020-01-15-14:52:26.738241] '/usr/bin/git' 'submodule' 'update' '--init' '--recursive'
Submodule 'android/libs/fbjni' (https://github.com/IvanKobzarev/fbjni.git) registered for path 'android/libs/fbjni'
Submodule 'third_party/NNPACK_deps/FP16' (https://github.com/Maratyszcza/FP16.git) registered for path 'third_party/FP16'
Submodule 'third_party/NNPACK_deps/FXdiv' (https://github.com/Maratyszcza/FXdiv.git) registered for path 'third_party/FXdiv'
Submodule 'third_party/NNPACK' (https://github.com/Maratyszcza/NNPACK.git) registered for path 'third_party/NNPACK'
Submodule 'third_party/QNNPACK' (https://github.com/pytorch/QNNPACK) registered for path 'third_party/QNNPACK'
Submodule 'third_party/benchmark' (https://github.com/google/benchmark.git) registered for path 'third_party/benchmark'
Submodule 'third-party/cpuinfo' (https://github.com/pytorch/cpuinfo.git) registered for path 'third_party/cpuinfo'
Submodule 'third_party/cub' (https://github.com/NVlabs/cub.git) registered for path 'third_party/cub'
Submodule 'third_party/eigen' (https://github.com/eigenteam/eigen-git-mirror.git) registered for path 'third_party/eigen'
Submodule 'third_party/fbgemm' (https://github.com/pytorch/fbgemm) registered for path 'third_party/fbgemm'
Submodule 'third_party/foxi' (https://github.com/houseroad/foxi.git) registered for path 'third_party/foxi'
Submodule 'third_party/gemmlowp/gemmlowp' (https://github.com/google/gemmlowp.git) registered for path 'third_party/gemmlowp/gemmlowp'
Submodule 'third_party/gloo' (https://github.com/facebookincubator/gloo) registered for path 'third_party/gloo'
Submodule 'third_party/googletest' (https://github.com/google/googletest.git) registered for path 'third_party/googletest'
Submodule 'third_party/ideep' (https://github.com/intel/ideep) registered for path 'third_party/ideep'
Submodule 'third_party/ios-cmake' (https://github.com/Yangqing/ios-cmake.git) registered for path 'third_party/ios-cmake'
Submodule 'third_party/nccl/nccl' (https://github.com/NVIDIA/nccl) registered for path 'third_party/nccl/nccl'
Submodule 'third_party/neon2sse' (https://github.com/intel/ARM_NEON_2_x86_SSE.git) registered for path 'third_party/neon2sse'
Submodule 'third_party/onnx' (https://github.com/onnx/onnx.git) registered for path 'third_party/onnx'
Submodule 'third_party/onnx-tensorrt' (https://github.com/onnx/onnx-tensorrt) registered for path 'third_party/onnx-tensorrt'
Submodule 'third_party/protobuf' (https://github.com/protocolbuffers/protobuf.git) registered for path 'third_party/protobuf'
Submodule 'third_party/NNPACK_deps/psimd' (https://github.com/Maratyszcza/psimd.git) registered for path 'third_party/psimd'
Submodule 'third_party/NNPACK_deps/pthreadpool' (https://github.com/Maratyszcza/pthreadpool.git) registered for path 'third_party/pthreadpool'
Submodule 'third_party/pybind11' (https://github.com/pybind/pybind11.git) registered for path 'third_party/pybind11'
Submodule 'third_party/python-enum' (https://github.com/PeachPy/enum34.git) registered for path 'third_party/python-enum'
Submodule 'third_party/python-peachpy' (https://github.com/Maratyszcza/PeachPy.git) registered for path 'third_party/python-peachpy'
Submodule 'third_party/python-six' (https://github.com/benjaminp/six.git) registered for path 'third_party/python-six'
Submodule 'third_party/sleef' (https://github.com/shibatch/sleef) registered for path 'third_party/sleef'
Submodule 'third_party/tbb' (https://github.com/01org/tbb) registered for path 'third_party/tbb'
Submodule 'third_party/zstd' (https://github.com/facebook/zstd.git) registered for path 'third_party/zstd'
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/android/libs/fbjni'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/FP16'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/FXdiv'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/NNPACK'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/QNNPACK'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/benchmark'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/cpuinfo'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/cub'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/eigen'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/fbgemm'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/foxi'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/gemmlowp/gemmlowp'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/gloo'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/googletest'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/ideep'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/ios-cmake'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/nccl/nccl'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/neon2sse'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/onnx'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/onnx-tensorrt'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/protobuf'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/psimd'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/pthreadpool'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/pybind11'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/python-enum'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/python-peachpy'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/python-six'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/sleef'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/tbb'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/zstd'...
Submodule path 'android/libs/fbjni': checked out 'dc916917e1500527f83bc24b1767a123d6549ca0'
Submodule path 'third_party/FP16': checked out 'febbb1c163726b5db24bed55cc9dc42529068997'
Submodule path 'third_party/FXdiv': checked out 'b742d1143724d646cd0f914646f1240eacf5bd73'
Submodule path 'third_party/NNPACK': checked out 'c039579abe21f5756e0f0e45e8e767adccc11852'
Submodule path 'third_party/QNNPACK': checked out '7d2a4e9931a82adc3814275b6219a03e24e36b4c'
Submodule path 'third_party/benchmark': checked out '505be96ab23056580a3a2315abba048f4428b04e'
Submodule path 'third_party/cpuinfo': checked out '89fe1695edf9ee14c22f815f24bac45577a4f135'
Submodule path 'third_party/cub': checked out '285aeebaa34b0e8a7670867a2e66c1a52d998d6a'
Submodule path 'third_party/eigen': checked out 'd41dc4dd74acce21fb210e7625d5d135751fa9e5'
Submodule path 'third_party/fbgemm': checked out '7dfeddb5ba976f47471275b2468909dfd9b577e1'
Submodule 'third_party/asmjit' (https://github.com/asmjit/asmjit.git) registered for path 'third_party/fbgemm/third_party/asmjit'
Submodule 'third_party/cpuinfo' (https://github.com/pytorch/cpuinfo) registered for path 'third_party/fbgemm/third_party/cpuinfo'
Submodule 'third_party/googletest' (https://github.com/google/googletest) registered for path 'third_party/fbgemm/third_party/googletest'
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/fbgemm/third_party/asmjit'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/fbgemm/third_party/cpuinfo'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/fbgemm/third_party/googletest'...
Submodule path 'third_party/fbgemm/third_party/asmjit': checked out '4da474ac9aa2689e88d5e40a2f37628f302d7e3c'
Submodule path 'third_party/fbgemm/third_party/cpuinfo': checked out 'd5e37adf1406cf899d7d9ec1d317c47506ccb970'
Submodule path 'third_party/fbgemm/third_party/googletest': checked out '0fc5466dbb9e623029b1ada539717d10bd45e99e'
Submodule path 'third_party/foxi': checked out '8f74bc4df3a4cfc69b1a3eadf62aa29d9961c72d'
Submodule path 'third_party/gemmlowp/gemmlowp': checked out '3fb5c176c17c765a3492cd2f0321b0dab712f350'
Submodule path 'third_party/gloo': checked out 'ca528e32fea9ca8f2b16053cff17160290fc84ce'
Submodule path 'third_party/googletest': checked out '2fe3bd994b3189899d93f1d5a881e725e046fdc2'
Submodule path 'third_party/ideep': checked out '78eafa5d231924e3d525d4dc46de880015257618'
Submodule 'mkl-dnn' (https://github.com/intel/mkl-dnn.git) registered for path 'third_party/ideep/mkl-dnn'
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/ideep/mkl-dnn'...
Submodule path 'third_party/ideep/mkl-dnn': checked out '0125f28c61c1f822fd48570b4c1066f96fcb9b2e'
Submodule path 'third_party/ios-cmake': checked out '8abaed637d56f1337d6e1d2c4026e25c1eade724'
Submodule path 'third_party/nccl/nccl': checked out '7c72dee660e4d055b81721dd6b03e4e1c0a983cf'
Submodule path 'third_party/neon2sse': checked out '97a126f08ce318023be604d03f88bf0820a9464a'
Submodule path 'third_party/onnx': checked out '034921bd574cc84906b7996c07873454b7dd4135'
Submodule 'third_party/benchmark' (https://github.com/google/benchmark.git) registered for path 'third_party/onnx/third_party/benchmark'
Submodule 'third_party/pybind11' (https://github.com/pybind/pybind11.git) registered for path 'third_party/onnx/third_party/pybind11'
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/onnx/third_party/benchmark'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/onnx/third_party/pybind11'...
Submodule path 'third_party/onnx/third_party/benchmark': checked out 'e776aa0275e293707b6a0901e0e8d8a8a3679508'
Submodule path 'third_party/onnx/third_party/pybind11': checked out '09f082940113661256310e3f4811aa7261a9fa05'
Submodule 'tools/clang' (https://github.com/wjakob/clang-cindex-python3) registered for path 'third_party/onnx/third_party/pybind11/tools/clang'
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/onnx/third_party/pybind11/tools/clang'...
Submodule path 'third_party/onnx/third_party/pybind11/tools/clang': checked out '6a00cbc4a9b8e68b71caf7f774b3f9c753ae84d5'
Submodule path 'third_party/onnx-tensorrt': checked out 'cb3d8066f20e6bca306454934d09d6abd826264a'
Submodule 'third_party/onnx' (https://github.com/onnx/onnx.git) registered for path 'third_party/onnx-tensorrt/third_party/onnx'
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/onnx-tensorrt/third_party/onnx'...
Submodule path 'third_party/onnx-tensorrt/third_party/onnx': checked out '765f5ee823a67a866f4bd28a9860e81f3c811ce8'
Submodule 'third_party/benchmark' (https://github.com/google/benchmark.git) registered for path 'third_party/onnx-tensorrt/third_party/onnx/third_party/benchmark'
Submodule 'third_party/pybind11' (https://github.com/pybind/pybind11.git) registered for path 'third_party/onnx-tensorrt/third_party/onnx/third_party/pybind11'
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/onnx-tensorrt/third_party/onnx/third_party/benchmark'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/onnx-tensorrt/third_party/onnx/third_party/pybind11'...
Submodule path 'third_party/onnx-tensorrt/third_party/onnx/third_party/benchmark': checked out 'e776aa0275e293707b6a0901e0e8d8a8a3679508'
Submodule path 'third_party/onnx-tensorrt/third_party/onnx/third_party/pybind11': checked out 'a1041190c8b8ff0cd9e2f0752248ad5e3789ea0c'
Submodule 'tools/clang' (https://github.com/wjakob/clang-cindex-python3) registered for path 'third_party/onnx-tensorrt/third_party/onnx/third_party/pybind11/tools/clang'
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/onnx-tensorrt/third_party/onnx/third_party/pybind11/tools/clang'...
Submodule path 'third_party/onnx-tensorrt/third_party/onnx/third_party/pybind11/tools/clang': checked out '6a00cbc4a9b8e68b71caf7f774b3f9c753ae84d5'
Submodule path 'third_party/protobuf': checked out '48cb18e5c419ddd23d9badcfe4e9df7bde1979b2'
Submodule 'third_party/benchmark' (https://github.com/google/benchmark.git) registered for path 'third_party/protobuf/third_party/benchmark'
Submodule 'third_party/googletest' (https://github.com/google/googletest.git) registered for path 'third_party/protobuf/third_party/googletest'
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/protobuf/third_party/benchmark'...
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/protobuf/third_party/googletest'...
Submodule path 'third_party/protobuf/third_party/benchmark': checked out '5b7683f49e1e9223cf9927b24f6fd3d6bd82e3f8'
Submodule path 'third_party/protobuf/third_party/googletest': checked out 'c3bb0ee2a63279a803aaad956b9b26d74bf9e6e2'
Submodule path 'third_party/psimd': checked out '90a938f30ba414ada2f4b00674ee9631d7d85e19'
Submodule path 'third_party/pthreadpool': checked out '13da0b4c21d17f94150713366420baaf1b5a46f4'
Submodule path 'third_party/pybind11': checked out '25abf7efba0b2990f5a6dfb0a31bc65c0f2f4d17'
Submodule 'tools/clang' (https://github.com/wjakob/clang-cindex-python3) registered for path 'third_party/pybind11/tools/clang'
Cloning into '/private/var/folders/21/hwq39zyj4g36x6zjfyl5l8080000gn/T/Adam/spack-stage/spack-stage-py-torch-1.3.1-wixzcw44go7lzjjt4pdg5uw3quh3icpi/spack-src/third_party/pybind11/tools/clang'...
Submodule path 'third_party/pybind11/tools/clang': checked out '6a00cbc4a9b8e68b71caf7f774b3f9c753ae84d5'
Submodule path 'third_party/python-enum': checked out '4cfedc426c4e2fc52e3f5c2b4297e15ed8d6b8c7'
Submodule path 'third_party/python-peachpy': checked out '07d8fde8ac45d7705129475c0f94ed8925b93473'
Submodule path 'third_party/python-six': checked out '15e31431af97e5e64b80af0a3f598d382bcdd49a'
Submodule path 'third_party/sleef': checked out '7f523de651585fe25cade462efccca647dcc8d02'
Submodule path 'third_party/tbb': checked out 'a51a90bc609bb73db8ea13841b5cf7aa4344d4a9'
Submodule path 'third_party/zstd': checked out 'aec56a52fbab207fc639a1937d1e708a282edca8'
==> [2020-01-15-14:54:37.242804] No checksum needed when fetching with git
==> [2020-01-15-14:54:37.246000] '/Users/Adam/.spack/darwin/.spack-env/view/bin/tar' '--exclude=.git' '-czf' '/Users/Adam/spack/var/spack/cache/_source-cache/git//pytorch/pytorch.git/v1.3.1.tar.gz' 'pytorch'
$ spack -d fetch py-torch
...
==> [2020-01-15-14:55:43.962949] Using cached archive: /Users/Adam/spack/var/spack/cache/_source-cache/git//pytorch/pytorch.git/v1.3.1.tar.gz
==> [2020-01-15-14:55:43.963100] Warning: Fetching from mirror without a checksum!
  This package is normally checked out from a version control system, but it has been archived on a spack mirror.  This means we cannot know a checksum for the tarball in advance. Be sure that your connection to this mirror is secure!
```

I would try running `spack fetch py-torch` from the login nodes, then try `spack install py-torch` on the compute nodes. If that doesn't work, it's likely because we currently exclude the `.git` subdirectory when we create the tarball. I'm not sure why we do that historically, but users have been complaining about that for a long time. Let me see if I can write a PR to fix that.

EDIT: See #14344 for a description of the problem and what line may need to be modified if you can't get it working.
Sorry, I hope you weren't waiting on my report for this issue.  `space fetch py-torch` on the login nodes, followed by `spack install py-torch` on the compute nodes doesn't solve this issue.
This seems like a general problem when you want to `spack install` packages that use Git repos, and have the sources pulled from a local source cache:

I created an issue for the more general problem here: https://github.com/spack/spack/issues/16813

@coreyjadams 

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/py-torch/package.py b/var/spack/repos/builtin/packages/py-torch/package.py
--- a/var/spack/repos/builtin/packages/py-torch/package.py
+++ b/var/spack/repos/builtin/packages/py-torch/package.py
@@ -3,8 +3,10 @@
 #
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
 
-from spack import *
 import os
+import sys
+
+from spack import *
 
 
 class PyTorch(PythonPackage, CudaPackage):
@@ -21,6 +23,7 @@ class PyTorch(PythonPackage, CudaPackage):
     import_modules = ['torch', 'torch.autograd', 'torch.nn', 'torch.utils']
 
     version('master', branch='master', submodules=True)
+    version('1.9.0', tag='v1.9.0', submodules=True)
     version('1.8.1', tag='v1.8.1', submodules=True)
     version('1.8.0', tag='v1.8.0', submodules=True)
     version('1.7.1', tag='v1.7.1', submodules=True)
@@ -29,7 +32,7 @@ class PyTorch(PythonPackage, CudaPackage):
     version('1.5.1', tag='v1.5.1', submodules=True)
     version('1.5.0', tag='v1.5.0', submodules=True)
     version('1.4.1', tag='v1.4.1', submodules=True)
-    version('1.4.0', tag='v1.4.0', submodules=True,
+    version('1.4.0', tag='v1.4.0', submodules=True, deprecated=True,
             submodules_delete=['third_party/fbgemm'])
     version('1.3.1', tag='v1.3.1', submodules=True)
     version('1.3.0', tag='v1.3.0', submodules=True)
@@ -37,142 +40,180 @@ class PyTorch(PythonPackage, CudaPackage):
     version('1.1.0', tag='v1.1.0', submodules=True)
     version('1.0.1', tag='v1.0.1', submodules=True)
     version('1.0.0', tag='v1.0.0', submodules=True)
-    version('0.4.1', tag='v0.4.1', submodules=True,
+    version('0.4.1', tag='v0.4.1', submodules=True, deprecated=True,
             submodules_delete=['third_party/nervanagpu'])
-    version('0.4.0', tag='v0.4.0', submodules=True)
-    version('0.3.1', tag='v0.3.1', submodules=True)
-
-    variant('cuda', default=True, description='Build with CUDA')
-    variant('cudnn', default=True, description='Enables the cuDNN build')
-    variant('rocm', default=False, description='Build with ROCm build')
-    variant('magma', default=False, description='Enables the MAGMA build')
-    variant('fbgemm', default=False, description='Enables the FBGEMM build')
-    variant('test', default=False, description='Enables the test build')
-    variant('miopen', default=False, description='Enables the MIOpen build')
-    variant('mkldnn', default=True, description='Enables use of MKLDNN')
-    variant('nnpack', default=False, description='Enables NNPACK build')
-    variant('qnnpack', default=False, description='Enables QNNPACK build (quantized 8-bit operators)')
-    variant('xnnpack', default=False, description='Enables XNNPACK build')
-    variant('distributed', default=False, description='Enables distributed (c10d, gloo, mpi, etc.) build')
-    variant('nccl', default=True, description='Use Spack-installed NCCL')
-    variant('caffe2', default=False, description='Enables Caffe2 operators build')
-    variant('gloo', default=False, description='Enables features related to distributed support')
-    variant('opencv', default=False, description='Enables use of OpenCV for additional operators')
-    variant('openmp', default=True, description='Enables use of OpenMP for parallelization')
-    variant('ffmpeg', default=False, description='Enables use of ffmpeg for additional operators')
-    variant('leveldb', default=False, description='Enables use of LevelDB for storage')
-    variant('lmdb', default=False, description='Enables use of LMDB for storage')
-    variant('binary', default=False, description='Enables the additional binaries/ build')
-    variant('redis', default=False, description='Use Redis for distributed workflows')
-    variant('zstd', default=False, description='Enables use of ZSTD')
-    variant('tbb', default=False, description='Enables TBB support')
-
+    version('0.4.0', tag='v0.4.0', submodules=True, deprecated=True)
+    version('0.3.1', tag='v0.3.1', submodules=True, deprecated=True)
+
+    is_darwin = sys.platform == 'darwin'
+
+    # All options are defined in CMakeLists.txt.
+    # Some are listed in setup.py, but not all.
+    variant('caffe2', default=True, description='Build Caffe2')
+    variant('cuda', default=not is_darwin, description='Use CUDA')
+    variant('rocm', default=False, description='Use ROCm')
+    variant('cudnn', default=not is_darwin, description='Use cuDNN')
+    variant('fbgemm', default=True, description='Use FBGEMM (quantized 8-bit server operators)')
+    variant('kineto', default=True, description='Use Kineto profiling library')
+    variant('magma', default=not is_darwin, description='Use MAGMA')
+    variant('metal', default=is_darwin, description='Use Metal for Caffe2 iOS build')
+    variant('nccl', default=not is_darwin, description='Use NCCL')
+    variant('nnpack', default=True, description='Use NNPACK')
+    variant('numa', default=not is_darwin, description='Use NUMA')
+    variant('numpy', default=True, description='Use NumPy')
+    variant('openmp', default=True, description='Use OpenMP for parallel code')
+    variant('qnnpack', default=True, description='Use QNNPACK (quantized 8-bit operators)')
+    variant('valgrind', default=not is_darwin, description='Use Valgrind')
+    variant('xnnpack', default=True, description='Use XNNPACK')
+    variant('mkldnn', default=True, description='Use MKLDNN')
+    variant('distributed', default=not is_darwin, description='Use distributed')
+    variant('mpi', default=not is_darwin, description='Use MPI for Caffe2')
+    variant('gloo', default=not is_darwin, description='Use Gloo')
+    variant('tensorpipe', default=not is_darwin, description='Use TensorPipe')
+    variant('onnx_ml', default=True, description='Enable traditional ONNX ML API')
+
+    conflicts('+cuda', when='+rocm')
     conflicts('+cudnn', when='~cuda')
-    conflicts('+magma', when='~cuda')
-    conflicts('+fbgemm', when='@:0.4')
-    conflicts('+miopen', when='@:0.4')
-    conflicts('+mkldnn', when='@:0.3')
-    conflicts('+qnnpack', when='@:0.4')
-    conflicts('+xnnpack', when='@:1.4')
-    conflicts('+nccl', when='~cuda')
-    conflicts('+opencv', when='@:0.4')
-    conflicts('+ffmpeg', when='@:0.4')
-    conflicts('+leveldb', when='@:0.4')
-    conflicts('+lmdb', when='@:0.4')
-    conflicts('+binary', when='@:0.4')
-    conflicts('+redis', when='@:1.0')
-    conflicts('+zstd', when='@:1.0')
-    conflicts('+tbb', when='@:1.1')
-    # https://github.com/pytorch/pytorch/issues/35149
-    conflicts('+fbgemm', when='@1.4.0')
+    conflicts('+nccl', when='~cuda~rocm')
+    conflicts('+nccl', when='platform=darwin')
+    conflicts('+numa', when='platform=darwin', msg='Only available on Linux')
+    conflicts('+valgrind', when='platform=darwin', msg='Only available on Linux')
+    conflicts('+mpi', when='~distributed')
+    conflicts('+gloo', when='~distributed')
+    conflicts('+tensorpipe', when='~distributed')
+    conflicts('+kineto', when='@:1.7.999')
+    conflicts('+valgrind', when='@:1.7.999')
+    conflicts('~caffe2', when='@0.4.0:1.6.999')  # no way to disable caffe2?
+    conflicts('+caffe2', when='@:0.3.1')  # caffe2 did not yet exist?
+    conflicts('+tensorpipe', when='@:1.5.999')
+    conflicts('+xnnpack', when='@:1.4.999')
+    conflicts('~onnx_ml', when='@:1.4.999')  # no way to disable ONNX?
+    conflicts('+rocm', when='@:0.4.999')
+    conflicts('+cudnn', when='@:0.4.999')
+    conflicts('+fbgemm', when='@:0.4.999,1.4.0')
+    conflicts('+qnnpack', when='@:0.4.999')
+    conflicts('+mkldnn', when='@:0.4.999')
 
     conflicts('cuda_arch=none', when='+cuda',
               msg='Must specify CUDA compute capabilities of your GPU, see '
               'https://developer.nvidia.com/cuda-gpus')
-    conflicts('+rocm', when='+cuda')
 
     # Required dependencies
     depends_on('cmake@3.5:', type='build')
-    # Use Ninja generator to speed up build times
-    # Automatically used if found
-    depends_on('ninja@1.5:', type='build')
+    # Use Ninja generator to speed up build times, automatically used if found
+    depends_on('ninja@1.5:', when='@1.1.0:', type='build')
+    # See python_min_version in setup.py
     depends_on('python@3.6.2:', when='@1.7.1:', type=('build', 'link', 'run'))
-    depends_on('python@3.6.1:', when='@1.6:', type=('build', 'link', 'run'))
-    depends_on('python@3.5:', when='@1.5:', type=('build', 'link', 'run'))
-    depends_on('python@2.7:2.8,3.5:', type=('build', 'link', 'run'))
+    depends_on('python@3.6.1:', when='@1.6.0:1.7.0', type=('build', 'link', 'run'))
+    depends_on('python@3.5:', when='@1.5.0:1.5.999', type=('build', 'link', 'run'))
+    depends_on('python@2.7:2.8,3.5:', when='@1.4.0:1.4.999', type=('build', 'link', 'run'))
+    depends_on('python@2.7:2.8,3.5:3.7.999', when='@:1.3.999', type=('build', 'link', 'run'))
     depends_on('py-setuptools', type=('build', 'run'))
-    depends_on('py-numpy', type=('build', 'run'))
     depends_on('py-future', when='@1.5:', type=('build', 'run'))
     depends_on('py-future', when='@1.1: ^python@:2', type=('build', 'run'))
     depends_on('py-pyyaml', type=('build', 'run'))
     depends_on('py-typing', when='@0.4: ^python@:3.4', type=('build', 'run'))
     depends_on('py-typing-extensions', when='@1.7:', type=('build', 'run'))
-    depends_on('py-pybind11', when='@0.4:', type=('build', 'link', 'run'))
+    depends_on('py-pybind11@master', when='@master', type=('build', 'link', 'run'))
+    depends_on('py-pybind11@2.6.2', when='@1.8.0:1.9.999', type=('build', 'link', 'run'))
+    depends_on('py-pybind11@2.3.0', when='@1.1.0:1.7.999', type=('build', 'link', 'run'))
+    depends_on('py-pybind11@2.2.4', when='@1.0.0:1.0.999', type=('build', 'link', 'run'))
+    depends_on('py-pybind11@2.2.2', when='@0.4.0:0.4.999', type=('build', 'link', 'run'))
     depends_on('py-dataclasses', when='@1.7: ^python@3.6.0:3.6.999', type=('build', 'run'))
     depends_on('py-tqdm', type='run')
+    depends_on('py-protobuf', when='@0.4:', type=('build', 'run'))
+    depends_on('protobuf', when='@0.4:')
     depends_on('blas')
     depends_on('lapack')
-    depends_on('protobuf', when='@0.4:')
-    depends_on('py-protobuf', when='@0.4:', type=('build', 'run'))
     depends_on('eigen', when='@0.4:')
-    # TODO: replace all third_party packages with Spack packages
+    # https://github.com/pytorch/pytorch/issues/60329
+    # depends_on('cpuinfo@master', when='@master')
+    # depends_on('cpuinfo@2020-12-17', when='@1.8.0:1.9.999')
+    # depends_on('cpuinfo@2020-06-11', when='@1.6.0:1.7.999')
+    depends_on('sleef@master', when='@master')
+    depends_on('sleef@3.5.1_2020-12-22', when='@1.8.0:1.9.999')
+    # https://github.com/pytorch/pytorch/issues/60334
+    # depends_on('sleef@3.4.0_2019-07-30', when='@1.6.0:1.7.999')
+    depends_on('fp16@master', when='@master')
+    depends_on('fp16@2020-05-14', when='@1.6.0:1.9.999')
+    depends_on('pthreadpool@master', when='@master')
+    depends_on('pthreadpool@2021-04-13', when='@1.9.0:1.9.999')
+    depends_on('pthreadpool@2020-10-05', when='@1.8.0:1.8.999')
+    depends_on('pthreadpool@2020-06-15', when='@1.6.0:1.7.999')
+    depends_on('psimd@master', when='@master')
+    depends_on('psimd@2020-05-17', when='@1.6.0:1.9.999')
+    depends_on('fxdiv@master', when='@master')
+    depends_on('fxdiv@2020-04-17', when='@1.6.0:1.9.999')
+    depends_on('benchmark', when='@1.6:')
 
     # Optional dependencies
     depends_on('cuda@7.5:', when='+cuda', type=('build', 'link', 'run'))
     depends_on('cuda@9:', when='@1.1:+cuda', type=('build', 'link', 'run'))
-    depends_on('cudnn@6:', when='+cudnn')
-    depends_on('cudnn@7:', when='@1.1:+cudnn')
+    depends_on('cudnn@6.0:7.999', when='@:1.0.999+cudnn')
+    depends_on('cudnn@7.0:7.999', when='@1.1.0:1.5.999+cudnn')
+    depends_on('cudnn@7.0:', when='@1.6.0:+cudnn')
     depends_on('magma', when='+magma')
-    # TODO: add dependency: https://github.com/pytorch/FBGEMM
-    # depends_on('fbgemm', when='+fbgemm')
-    # TODO: add dependency: https://github.com/ROCmSoftwarePlatform/MIOpen
-    # depends_on('miopen', when='+miopen')
-    # TODO: See if there is a way to use an external mkldnn installation.
-    # Currently, only older versions of py-torch use an external mkldnn
-    # library.
-    depends_on('onednn', when='@0.4:0.4.1+mkldnn')
-    # TODO: add dependency: https://github.com/Maratyszcza/NNPACK
-    # depends_on('nnpack', when='+nnpack')
-    depends_on('qnnpack', when='+qnnpack')
-    # TODO: add dependency: https://github.com/google/XNNPACK
-    # depends_on('xnnpack', when='+xnnpack')
-    depends_on('mpi', when='+distributed')
     depends_on('nccl', when='+nccl')
-    depends_on('gloo', when='+gloo')
-    depends_on('opencv', when='+opencv')
+    depends_on('numactl', when='+numa')
+    depends_on('py-numpy', when='+numpy', type=('build', 'run'))
     depends_on('llvm-openmp', when='%apple-clang +openmp')
-    depends_on('ffmpeg', when='+ffmpeg')
-    depends_on('leveldb', when='+leveldb')
-    depends_on('lmdb', when='+lmdb')
-    depends_on('redis', when='+redis')
-    depends_on('zstd', when='+zstd')
-    depends_on('tbb', when='+tbb')
+    depends_on('valgrind', when='+valgrind')
+    # https://github.com/pytorch/pytorch/issues/60332
+    # depends_on('xnnpack@master', when='@master+xnnpack')
+    # depends_on('xnnpack@2021-02-22', when='@1.8.0:1.9.999+xnnpack')
+    # depends_on('xnnpack@2020-03-23', when='@1.6.0:1.7.999+xnnpack')
+    depends_on('mpi', when='+mpi')
+    # https://github.com/pytorch/pytorch/issues/60270
+    # depends_on('gloo@master', when='@master+gloo')
+    # depends_on('gloo@2021-05-04', when='@1.9.0:1.9.999+gloo')
+    # depends_on('gloo@2020-09-18', when='@1.7.0:1.8.999+gloo')
+    # depends_on('gloo@2020-03-17', when='@1.6.0:1.6.999+gloo')
+    # https://github.com/pytorch/pytorch/issues/60331
+    # depends_on('onnx@master', when='@master+onnx_ml')
+    # depends_on('onnx@1.8.0_2020-11-03', when='@1.8.0:1.9.999+onnx_ml')
+    # depends_on('onnx@1.7.0_2020-05-31', when='@1.6.0:1.7.999+onnx_ml')
+    depends_on('mkl', when='+mkldnn')
 
     # Test dependencies
     depends_on('py-hypothesis', type='test')
     depends_on('py-six', type='test')
     depends_on('py-psutil', type='test')
 
+    # Fix BLAS being overridden by MKL
+    # https://github.com/pytorch/pytorch/issues/60328
+    patch('https://patch-diff.githubusercontent.com/raw/pytorch/pytorch/pull/59220.patch',
+          sha256='e37afffe45cf7594c22050109942370e49983ad772d12ebccf508377dc9dcfc9',
+          when='@1.2.0:')
+
     # Fixes build on older systems with glibc <2.12
     patch('https://patch-diff.githubusercontent.com/raw/pytorch/pytorch/pull/55063.patch',
           sha256='e17eaa42f5d7c18bf0d7c37d7b0910127a01ad53fdce3e226a92893356a70395',
-          when='@1.1.0:')
+          when='@1.1.0:1.8.1')
 
+    # Fixes CMake configuration error when XNNPACK is disabled
     # https://github.com/pytorch/pytorch/pull/35607
     # https://github.com/pytorch/pytorch/pull/37865
-    # Fixes CMake configuration error when XNNPACK is disabled
     patch('xnnpack.patch', when='@1.5.0:1.5.999')
 
-    # Fixes Build error for when ROCm is enable for pytorch-1.5 release
+    # Fixes build error when ROCm is enabled for pytorch-1.5 release
     patch('rocm.patch', when='@1.5.0:1.5.999+rocm')
 
-    # https://github.com/pytorch/pytorch/pull/37086
+    # Fixes fatal error: sleef.h: No such file or directory
+    # https://github.com/pytorch/pytorch/pull/35359
+    # https://github.com/pytorch/pytorch/issues/26555
+    patch('sleef.patch', when='@1.0.0:1.5.999')
+
     # Fixes compilation with Clang 9.0.0 and Apple Clang 11.0.3
+    # https://github.com/pytorch/pytorch/pull/37086
     patch('https://github.com/pytorch/pytorch/commit/e921cd222a8fbeabf5a3e74e83e0d8dfb01aa8b5.patch',
           sha256='17561b16cd2db22f10c0fe1fdcb428aecb0ac3964ba022a41343a6bb8cba7049',
           when='@1.1:1.5')
 
-    # Fix for 'FindOpenMP.cmake'
+    # Removes duplicate definition of getCusparseErrorString
+    # https://github.com/pytorch/pytorch/issues/32083
+    patch('cusparseGetErrorString.patch', when='@0.4.1:1.0.999^cuda@10.1.243:')
+
+    # Fixes 'FindOpenMP.cmake'
     # to detect openmp settings used by Fujitsu compiler.
     patch('detect_omp_of_fujitsu_compiler.patch', when='%fj')
 
@@ -182,16 +223,12 @@ class PyTorch(PythonPackage, CudaPackage):
 
     @property
     def libs(self):
-        root = join_path(
-            self.prefix, self.spec['python'].package.site_packages_dir,
-            'torch', 'lib')
+        root = join_path(site_packages_dir, 'torch', 'lib')
         return find_libraries('libtorch', root)
 
     @property
     def headers(self):
-        root = join_path(
-            self.prefix, self.spec['python'].package.site_packages_dir,
-            'torch', 'include')
+        root = join_path(site_packages_dir, 'torch', 'include')
         headers = find_all_headers(root)
         headers.directories = [root]
         return headers
@@ -204,6 +241,16 @@ def patch(self):
                     'caffe2/CMakeLists.txt')
 
     def setup_build_environment(self, env):
+        """Set environment variables used to control the build.
+
+        PyTorch's ``setup.py`` is a thin wrapper around ``cmake``.
+        In ``tools/setup_helpers/cmake.py``, you can see that all
+        environment variables that start with ``BUILD_``, ``USE_``,
+        or ``CMAKE_``, plus a few more explicitly specified variable
+        names, are passed directly to the ``cmake`` call. Therefore,
+        most flags defined in ``CMakeLists.txt`` can be specified as
+        environment variables.
+        """
         def enable_or_disable(variant, keyword='USE', var=None, newer=False):
             """Set environment variable to enable or disable support for a
             particular variant.
@@ -236,84 +283,129 @@ def enable_or_disable(variant, keyword='USE', var=None, newer=False):
         # Spack logs have trouble handling colored output
         env.set('COLORIZE_OUTPUT', 'OFF')
 
-        # Don't use vendored third-party libraries
-        env.set('BUILD_CUSTOM_PROTOBUF', 'OFF')
-        env.set('USE_PYTORCH_QNNPACK', 'OFF')
-        env.set('USE_SYSTEM_EIGEN_INSTALL', 'ON')
-        env.set('pybind11_DIR', self.spec['py-pybind11'].prefix)
-        env.set('pybind11_INCLUDE_DIR',
-                self.spec['py-pybind11'].prefix.include)
+        if self.spec.satisfies('@1.7:'):
+            enable_or_disable('caffe2', keyword='BUILD')
 
         enable_or_disable('cuda')
         if '+cuda' in self.spec:
-            env.set('CUDA_HOME', self.spec['cuda'].prefix)
+            # cmake/public/cuda.cmake
+            # cmake/Modules_CUDA_fix/upstream/FindCUDA.cmake
+            env.unset('CUDA_ROOT')
             torch_cuda_arch = ';'.join('{0:.1f}'.format(float(i) / 10.0) for i
                                        in
                                        self.spec.variants['cuda_arch'].value)
             env.set('TORCH_CUDA_ARCH_LIST', torch_cuda_arch)
 
+        enable_or_disable('rocm')
+
         enable_or_disable('cudnn')
         if '+cudnn' in self.spec:
-            env.set('CUDNN_LIB_DIR', self.spec['cudnn'].libs.directories[0])
+            # cmake/Modules_CUDA_fix/FindCUDNN.cmake
             env.set('CUDNN_INCLUDE_DIR', self.spec['cudnn'].prefix.include)
             env.set('CUDNN_LIBRARY', self.spec['cudnn'].libs[0])
 
         enable_or_disable('fbgemm')
-        enable_or_disable('test', keyword='BUILD')
-        enable_or_disable('rocm')
-        if '+rocm' in self.spec:
-            env.set('USE_MKLDNN', 0)
-        if '+miopen' in self.spec:
-            env.set('MIOPEN_LIB_DIR', self.spec['miopen'].libs.directories[0])
-            env.set('MIOPEN_INCLUDE_DIR', self.spec['miopen'].prefix.include)
-            env.set('MIOPEN_LIBRARY', self.spec['miopen'].libs[0])
-
-        enable_or_disable('mkldnn')
-        if '@0.4:0.4.1+mkldnn' in self.spec:
-            env.set('MKLDNN_HOME', self.spec['onednn'].prefix)
-
-        enable_or_disable('nnpack')
-        enable_or_disable('qnnpack')
-        enable_or_disable('xnnpack')
-        enable_or_disable('distributed')
+        if self.spec.satisfies('@1.8:'):
+            enable_or_disable('kineto')
+        enable_or_disable('magma')
+        enable_or_disable('metal')
 
         enable_or_disable('nccl')
-        enable_or_disable('nccl', var='SYSTEM_NCCL')
         if '+nccl' in self.spec:
-            env.set('NCCL_ROOT', self.spec['nccl'].prefix)
             env.set('NCCL_LIB_DIR', self.spec['nccl'].libs.directories[0])
             env.set('NCCL_INCLUDE_DIR', self.spec['nccl'].prefix.include)
 
-        enable_or_disable('caffe2', keyword='BUILD', var='CAFFE2_OPS')
-        enable_or_disable('gloo', newer=True)
-        enable_or_disable('opencv', newer=True)
+        # cmake/External/nnpack.cmake
+        enable_or_disable('nnpack')
+
+        enable_or_disable('numa')
+        if '+numa' in self.spec:
+            # cmake/Modules/FindNuma.cmake
+            env.set('NUMA_ROOT_DIR', self.spec['numactl'].prefix)
+
+        # cmake/Modules/FindNumPy.cmake
+        enable_or_disable('numpy')
+        # cmake/Modules/FindOpenMP.cmake
         enable_or_disable('openmp', newer=True)
-        enable_or_disable('ffmpeg', newer=True)
-        enable_or_disable('leveldb', newer=True)
-        enable_or_disable('lmdb', newer=True)
-        enable_or_disable('binary', keyword='BUILD', newer=True)
+        enable_or_disable('qnnpack')
+        if self.spec.satisfies('@1.3:'):
+            enable_or_disable('qnnpack', var='PYTORCH_QNNPACK')
+        if self.spec.satisfies('@1.8:'):
+            enable_or_disable('valgrind')
+        if self.spec.satisfies('@1.5:'):
+            enable_or_disable('xnnpack')
+        enable_or_disable('mkldnn')
+        enable_or_disable('distributed')
+        enable_or_disable('mpi')
+        # cmake/Modules/FindGloo.cmake
+        enable_or_disable('gloo', newer=True)
+        if self.spec.satisfies('@1.6:'):
+            enable_or_disable('tensorpipe')
+
+        if '+onnx_ml' in self.spec:
+            env.set('ONNX_ML', 'ON')
+        else:
+            env.set('ONNX_ML', 'OFF')
 
         if not self.spec.satisfies('@master'):
             env.set('PYTORCH_BUILD_VERSION', self.version)
             env.set('PYTORCH_BUILD_NUMBER', 0)
 
         # BLAS to be used by Caffe2
-        if '^mkl' in self.spec:
-            env.set('BLAS', 'MKL')
-        elif '^atlas' in self.spec:
+        # Options defined in cmake/Dependencies.cmake and cmake/Modules/FindBLAS.cmake
+        if self.spec['blas'].name == 'atlas':
             env.set('BLAS', 'ATLAS')
-        elif '^openblas' in self.spec:
+            env.set('WITH_BLAS', 'atlas')
+        elif self.spec['blas'].name in ['blis', 'amdblis']:
+            env.set('BLAS', 'BLIS')
+            env.set('WITH_BLAS', 'blis')
+        elif self.spec['blas'].name == 'eigen':
+            env.set('BLAS', 'Eigen')
+        elif self.spec['lapack'].name in ['libflame', 'amdlibflame']:
+            env.set('BLAS', 'FLAME')
+            env.set('WITH_BLAS', 'FLAME')
+        elif self.spec['blas'].name in [
+                'intel-mkl', 'intel-parallel-studio', 'intel-oneapi-mkl']:
+            env.set('BLAS', 'MKL')
+            env.set('WITH_BLAS', 'mkl')
+        elif self.spec['blas'].name == 'openblas':
             env.set('BLAS', 'OpenBLAS')
-        elif '^veclibfort' in self.spec:
+            env.set('WITH_BLAS', 'open')
+        elif self.spec['blas'].name == 'veclibfort':
             env.set('BLAS', 'vecLib')
-        elif '^libflame' in self.spec:
-            env.set('BLAS', 'FLAME')
-        elif '^eigen' in self.spec:
-            env.set('BLAS', 'Eigen')
+            env.set('WITH_BLAS', 'veclib')
+        else:
+            env.set('BLAS', 'Generic')
+            env.set('WITH_BLAS', 'generic')
 
-        enable_or_disable('redis', newer=True)
-        enable_or_disable('zstd', newer=True)
-        enable_or_disable('tbb', newer=True)
+        # Don't use vendored third-party libraries when possible
+        env.set('BUILD_CUSTOM_PROTOBUF', 'OFF')
+        env.set('USE_SYSTEM_NCCL', 'ON')
+        env.set('USE_SYSTEM_EIGEN_INSTALL', 'ON')
+        if self.spec.satisfies('@0.4:'):
+            env.set('pybind11_DIR', self.spec['py-pybind11'].prefix)
+            env.set('pybind11_INCLUDE_DIR',
+                    self.spec['py-pybind11'].prefix.include)
+        if self.spec.satisfies('@1.10:'):
+            env.set('USE_SYSTEM_PYBIND11', 'ON')
+        # https://github.com/pytorch/pytorch/issues/60334
+        if self.spec.satisfies('@1.8:'):
+            env.set('USE_SYSTEM_SLEEF', 'ON')
+        if self.spec.satisfies('@1.6:'):
+            # env.set('USE_SYSTEM_LIBS', 'ON')
+            # https://github.com/pytorch/pytorch/issues/60329
+            # env.set('USE_SYSTEM_CPUINFO', 'ON')
+            # https://github.com/pytorch/pytorch/issues/60270
+            # env.set('USE_SYSTEM_GLOO', 'ON')
+            env.set('USE_SYSTEM_FP16', 'ON')
+            env.set('USE_SYSTEM_PTHREADPOOL', 'ON')
+            env.set('USE_SYSTEM_PSIMD', 'ON')
+            env.set('USE_SYSTEM_FXDIV', 'ON')
+            env.set('USE_SYSTEM_BENCHMARK', 'ON')
+            # https://github.com/pytorch/pytorch/issues/60331
+            # env.set('USE_SYSTEM_ONNX', 'ON')
+            # https://github.com/pytorch/pytorch/issues/60332
+            # env.set('USE_SYSTEM_XNNPACK', 'ON')
 
     @run_before('install')
     def build_amd(self):


Test patch: