FYI, here is my build script 29 for PyTorch v0.1.11.r317.gde984558 (May 23, CuDNN 5.1)
I didn’t update to CuDNN v6 yet, but it should be pretty easy to adapt. ENV variables to watch for:
  CC=gcc-5 \
  CXX=g++-5 \
  WITH_CUDA=1 \
  CUDA_HOME=/opt/cuda \
  WITH_CUDNN=1 \
  CUDNN_LIB_DIR=/opt/cuda/lib64 \
  CUDNN_INCLUDE_DIR=/opt/cuda/include \

CC and CXX must be GCC-5 for CUDA-8 and can be GCC-6 for CUDA-9 (I don’t think GCC-7 will work for any of those).
Don’t forget the WITH_CUDA and WITH_CUDNN