Installing PyTorch from source error with hash.h

Hi, when I tried to install PyTorch from source, I have the following errors and I guess it might be related to the pytorch/torch/csrc/utils/hash.h file.

pytorch/torch/csrc/utils/hash.h:56:111: error: expected '(' before ')' token
 auto dispatch_hash(const T& o) -> decltype((typename std::enable_if<std::is_enum<T>::value, std::size_t>::type){}) {
                                                                                                               ^
pytorch/torch/csrc/utils/hash.h:56:112: error: expected ')' before '{' token
 auto dispatch_hash(const T& o) -> decltype((typename std::enable_if<std::is_enum<T>::value, std::size_t>::type){}) {
                                                                                                                ^
pytorch/torch/csrc/utils/hash.h:56:35: error: expected type-specifier before 'decltype'
 auto dispatch_hash(const T& o) -> decltype((typename std::enable_if<std::is_enum<T>::value, std::size_t>::type){}) {
                                   ^
pytorch/torch/csrc/utils/hash.h:56:35: error: expected initializer before 'decltype'
/afs/cs.pitt.edu/usr0/mzhang/tmp/pytorch/torch/csrc/utils/hash.h:56:114: error: expected unqualified-id before ')' token
 auto dispatch_hash(const T& o) -> decltype((typename std::enable_if<std::is_enum<T>::value, std::size_t>::type){}) {
                                                                                                                  ^
pytorch/torch/csrc/utils/hash.h:71:41: error: no matching function for call to 'dispatch_hash(const at::ScalarType&)'
     return _hash_detail::dispatch_hash(o);
                                         ^
pytorch/torch/csrc/utils/hash.h:51:60: error: invalid use of incomplete type 'struct std::hash<at::ScalarType>'
 auto dispatch_hash(const T& o) -> decltype(std::hash<T>()(o), std::size_t()) {
                                                            ^
/usr/include/c++/4.8.2/bits/functional_hash.h:58:12: error: declaration of 'struct std::hash<at::ScalarType>'
     struct hash;
            ^

My system configuration:

  • Cent OS Linux release 7.2.1511
  • gcc (GCC) 4.8.5 20150623
  • CUDA 9.0, Cuda compilation tools, release 9.0, V9.0.176
  • CuDNN: 7004
  • Python 3.6.3 :: Anaconda, Inc.
  • PyTorch master branch, commit b97dfc8

Thanks in advance for your help!

I think this is an instance of this issue: https://github.com/pytorch/pytorch/pull/3756 . It should have been fixed by this commit, try pulling from master and rebuilding.

1 Like

The commit you mentioned seems fixing another compiler tool, but I do see someone commit a fix for this problem like 7 minutes ago 23ca19a. I’ll pull the master and retry compilation.

Thanks again!