@KunWangV try compiling with gcc 4.9 like this:
On ubuntu 16.04:
sudo apt install gcc-4.9 g++-4.9
export CC="gcc-4.9"
export CXX="g++-4.9"
# change to pytorch directory
python setup.py clean
python setup.py install