'How to build pytorch source?

When I use pytorch, it showed that my the cuda version pytorch used and cuda version of system are inconsistent, so I need rebuild pytorch from source.

# install dependency
pip install astunparse numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses

# Download pytorch source
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
# if you are updating an existing checkout
git submodule sync
git submodule update --init --recursive --jobs 0

# Build
#if you want to use pytorch with cuda ,please `USE_CUDA=1`
python setup.py install

#torchvision install with source
# Download
git clone --recursive --branch v0.11.1 https://github.com/pytorch/vision.git

cd vision
python setup.py install


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source