Basic Installation
The basic installation procedure of PyTorch includes obtaining the source code and sub-repository dependency code, setting environment variables, and compiling and installing PyTorch. Replace the example paths provided in the following procedure with the actual ones.
- Configure a git network proxy.
git config --global http.sslVerify false git config --global https.sslverify false git config --global http.proxy "http://Username:Password@Proxy_IP_address:Proxy_port"
- Obtain the PyTorch source code.
git clone -b v2.1.2 https://github.com/pytorch/pytorch.git --depth 1
- Go to the /path/to/pytorch directory.
cd /path/to/pytorch
- Obtain the sub-repository dependency code.
git submodule sync git submodule update --init --recursive
- Set environment variables.
export USE_CUDA=0 export USE_ROCM=0 export USE_FBGEMM=0 export USE_GLOO=0
USE_CUDA: CUDA is a technology dedicated to NVIDIA GPUs. Set this parameter to 0 in CPU scenarios, meaning that this optional is disabled.
USE_ROCM: ROCM is a technology dedicated to AMD GPUs. Set this parameter to 0 in CPU scenarios, meaning that this optional is disabled.
USE_FBGEMM: Matrix operation acceleration library, which applies only to x86. Set this parameter to 0 in Arm scenarios, meaning that this optional is disabled.
USE_GLOO: Communication library between multiple GPUs and multiple nodes. Set this parameter to 0 in CPU scenarios, meaning that this optional is disabled.
- Install the Python dependency.
pip install -r requirements.txt
- Compile and install PyTorch.
python3 setup.py install
- Verify the installation.
pip list | grep torch

- When obtaining the PyTorch source code, an error may be reported stating "unexpected disconnect while reading sideband packet." Rectify this fault by following instructions in Error "unexpected disconnect while reading sideband packet" Reported When Obtaining the PyTorch Source Code?.
- When obtaining the sub-repository dependency code, an error may be reported stating "unexpected disconnect while reading sideband packet fatal." Rectify this fault by following instructions in Error "unexpected disconnect while reading sideband packet fatal" Reported When Obtaining the Sub-repository Dependency.
- When compiling PyTorch, an error may be reported indicating that the CMakeLists.txt, Makefile, setup.py, LICENSE, LICENSE.md, and LICENSE.txt are not found in the /path/to/pytorch/third_party/ios-cmake directory. Rectify this fault by following instructions in No Files Found When Running PyTorch Compilation and Installation Commands.