Compiling PyTorch
- Obtain the PyTorch source code.
1git clone -b v2.4.0 https://github.com/pytorch/pytorch.git --depth 1
If a pull error occurs, try again or run the following command:
1git config --global http.sslBackend openssl
- Access the PyTorch source code.
1cd pytorch
- Obtain the sub-repository dependency code.
1 2
git submodule sync git submodule update --init --recursive
- Set environment variables.
1 2 3 4
export USE_CUDA=1 export USE_ROCM=1 export USE_FBGEMM=0 export USE_GLOO=1
- Install the Python dependency.
1pip3 install -r requirements.txt
- Compile and install PyTorch.
1python3 setup.py bdist_wheel
After the installation is complete, the torch*.whl file is generated in the dist directory.
- Verify the installation.
1 2
pip3 install dist/torch*.whl pip list | grep torch
Command output:

- Check whether GPUs are supported.
1python3
Run the following commands:
1 2
import torch print(torch.cuda.is_available())
If the output is True, GPUs are supported.
