How to build pytorch from source using numpy
I am trying to build pytorch v1.4.0 from source because I need it for another module.
I have succeeded in building pytorch from source but when I try to run the intended python script I get this error:
RuntimeError: PyTorch was compiled without NumPy support

So I looked up what I did wrong and it turns out I needed to install numpy before i build pytorch from source, so thats what I did.
I used the command:
pip3 install numpy==1.19.4

When installing pytorch the console gives me a lot of information, including the build settings. The build settings looked like this:
--   Compile definitions   : ONNX_ML=1;ONNX_NAMESPACE=onnx_torch;HAVE_MMAP=1;_FILE_OFFSET_BITS=64;HAVE_SHM_OPEN=1;HAVE_SHM_UNLINK=1;HAVE_MALLOC_USABLE_SIZE=1
--   CMAKE_PREFIX_PATH     : /home/elvygcp/venv/lib/python3.6/site-packages;/usr/local/cuda
--   CMAKE_INSTALL_PREFIX  : /home/elvygcp/venv/pytorch-1.4.0/torch
-- 
--   TORCH_VERSION         : 1.4.0
--   CAFFE2_VERSION        : 1.4.0
--   BUILD_CAFFE2_MOBILE   : ON
--   USE_STATIC_DISPATCH   : OFF
--   BUILD_BINARY          : OFF
--   BUILD_CUSTOM_PROTOBUF : ON
--     Link local protobuf : ON
--   BUILD_DOCS            : OFF
--   BUILD_PYTHON          : True
--     Python version      : 3.6.9
--     Python executable   : /home/elvygcp/venv/bin/python3
--     Pythonlibs version  : 3.6.9
--     Python library      : /usr/lib/libpython3.6m.so.1.0
--     Python includes     : /usr/include/python3.6m
--     Python site-packages: lib/python3.6/site-packages
--   BUILD_CAFFE2_OPS      : ON
--   BUILD_SHARED_LIBS     : ON
--   BUILD_TEST            : True
--   BUILD_JNI             : OFF
--   INTERN_BUILD_MOBILE   : 
--   USE_ASAN              : OFF
--   USE_CUDA              : ON
--     CUDA static link    : OFF
--     USE_CUDNN           : OFF
--     CUDA version        : 10.2
--     CUDA root directory : /usr/local/cuda
--     CUDA library        : /usr/local/cuda/lib64/stubs/libcuda.so
--     cudart library      : /usr/local/cuda/lib64/libcudart.so
--     cublas library      : /usr/lib/x86_64-linux-gnu/libcublas.so
--     cufft library       : /usr/local/cuda/lib64/libcufft.so
--     curand library      : /usr/local/cuda/lib64/libcurand.so
--     nvrtc               : /usr/local/cuda/lib64/libnvrtc.so
--     CUDA include path   : /usr/local/cuda/include
--     NVCC executable     : /usr/local/cuda/bin/nvcc
--     CUDA host compiler  : /usr/bin/cc
--     USE_TENSORRT        : OFF
--   USE_ROCM              : OFF
--   USE_EIGEN_FOR_BLAS    : ON
--   USE_FBGEMM            : ON
--   USE_FFMPEG            : OFF
--   USE_GFLAGS            : OFF
--   USE_GLOG              : OFF
--   USE_LEVELDB           : OFF
--   USE_LITE_PROTO        : OFF
--   USE_LMDB              : OFF
--   USE_METAL             : OFF
--   USE_MKL               : OFF
--   USE_MKLDNN            : ON
--   USE_MKLDNN_CBLAS      : OFF
--   USE_NCCL              : ON
--     USE_SYSTEM_NCCL     : OFF
--   USE_NNPACK            : ON
--   USE_NUMPY             : OFF
--   USE_OBSERVERS         : ON
--   USE_OPENCL            : OFF
--   USE_OPENCV            : OFF
--   USE_OPENMP            : ON
--   USE_TBB               : OFF
--   USE_PROF              : OFF
--   USE_QNNPACK           : ON
--   USE_REDIS             : OFF
--   USE_ROCKSDB           : OFF
--   USE_ZMQ               : OFF
--   USE_DISTRIBUTED       : ON
--     USE_MPI             : OFF
--     USE_GLOO            : ON
--   BUILD_NAMEDTENSOR   : OFF

There are 2 things I do not understand:

The line: USE_CUDNN           : OFF, which I think is strange since i followed the pytorch build instructions from their github page which mentions I need CuDNN to build pytorch from source, and CuDNN is installed on my system.

The line: USE_NUMPY             : OFF, I dont know why but pytorch does not recognize numpy.


My system:
OS: Ubuntu 18.04 LTS
Cuda version: 10.2
CuDNN version: 8
python venv in Google Cloud Compute Engine VM

How I build pytorch 1.4.0 from source:
git clone --branch v1.4.0 https://github.com/pytorch/pytorch.git pytorch-1.4.0
cd pytorch-1.4.0/
git submodule update --init --recursive
sudo apt install cmake -y
sudo apt-get update
cd ../
sudo apt install python3-venv -y
python3 -m venv venv/
cd venv
source bin/activate
cd pytorch-1.4.0/
pip install pyyaml
python3 setup.py install
cd ../
git clone --branch v0.5.0 https://github.com/pytorch/vision.git torchvision-0.5.0
cd torchvision-0.5.0/
python3 setup.py install
cd ../


If anyone could tell how I make pytorch recognize and build with numpy I'd be very grateful.
If I need to supply more information I'd be happy to.

Okay so I don't exactly know what the solution was since I did two things:

I installed a lower version of numpy since my torch version is also a bit older.
I cleared all the pytorch install cache with the command: sudo USE_ROCM=1 USE_LMDB=1 USE_OPENCV=1 MAX_JOBS=15 python3 setup.py clean

Downgrading numpy might have been unnecessary, since I can't remember if I cleared all the pytorch installation cache after installing numpy and trying again.
Now my installation log contains USE_NUMPY             : ON.
Dont know if this fixed all my problems, building pytorch takes forever so I'll just have to wait and see, but at least it fixed this one :)
