I’m not sure what the official way is, but here is what has consistently worked for me for a long time by now:
I have set up two directories with symlinks I add to my path. In ~/pytorch/compiler I have
g++ -> /usr/bin/g++-5
gcc -> /usr/bin/gcc-5
x86_64-linux-gnu-g++ -> /usr/bin/x86_64-linux-gnu-g++-5
x86_64-linux-gnu-gcc -> /usr/bin/x86_64-linux-gnu-gcc-5

and because I like ccache (I use the Debian/unstable ccache seems to do OK) I also have ~/pytorch/compilers-with-ccache
g++ -> /usr/bin/ccache
g++-5 -> /usr/bin/ccache
gcc -> /usr/bin/ccache
gcc-5 -> /usr/bin/ccache
x86_64-linux-gnu-g++ -> /usr/bin/ccache
x86_64-linux-gnu-g++-5 -> /usr/bin/ccache
x86_64-linux-gnu-gcc -> /usr/bin/ccache
x86_64-linux-gnu-gcc-5 -> /usr/bin/ccache

Then I compile PyTorch with
PATH=~/pytorch/compilers-with-ccache/:~/pytorch/compilers/:$PATH python3 setup.py bdist_wheel

to get a whl in the dist directory.
Finally, I install with sudo pip3 -U --no-deps dist/something.whl because my system Python 3 is with pip3.
You might have to clean (python3 setup.py clean) before rerunning setup.py.
Best regards
Thomas