Rate This Document
Findability
Accuracy
Completeness
Readability

Compiling PyTorch

  1. Obtain the PyTorch source code.
    1
    git 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:

    1
    git config --global http.sslBackend openssl
    
  2. Access the PyTorch source code.
    1
    cd pytorch
    
  3. Obtain the sub-repository dependency code.
    1
    2
    git submodule sync
    git submodule update --init --recursive
    
  4. Set environment variables.
    1
    2
    3
    4
    export USE_CUDA=1 
    export USE_ROCM=1 
    export USE_FBGEMM=0 
    export USE_GLOO=1
    
  5. Install the Python dependency.
    1
    pip3 install -r requirements.txt
    
  6. Compile and install PyTorch.
    1
    python3 setup.py bdist_wheel
    

    After the installation is complete, the torch*.whl file is generated in the dist directory.

  7. Verify the installation.
    1
    2
    pip3 install dist/torch*.whl
    pip list | grep torch
    

    Command output:

  8. Check whether GPUs are supported.
    1
    python3
    

    Run the following commands:

    1
    2
    import torch
    print(torch.cuda.is_available())
    

    If the output is True, GPUs are supported.