Step 1: Install the necessary dependencies
Install Xcode Command Line Tools by running the following command in your terminal:
xcode-select --install
Install Homebrew(arm64 version is indeed), a package manager for macOS, by following the instructions on the Homebrew website: **https://brew.sh/**
Use Homebrew to install additional dependencies required for building PyTorch:
brew install cmake pkg-config libomp llvm openblas gmp mpfr libmpc
Step 2: Create and activate a Conda environment
Install Anaconda or Miniconda, which will allow you to create isolated Python environments, by following the instructions on the official website: **https://www.anaconda.com/products/distribution** or **https://docs.conda.io/en/latest/miniconda.html**
Create a new Conda environment named "pytorch-build" with Python 3.8:
conda create -n pytorch-build python=3.10
Activate the newly created Conda environment:
conda activate pytorch-build
Step 3: Clone the PyTorch repository
Open a terminal and navigate to the directory where you want to clone the PyTorch repository.
Clone the PyTorch repository, including its submodules, by running the following command:
git clone --recursive <https://github.com/pytorch/pytorch>
Change to the newly created pytorch
directory:
cd pytorch
Step 4: Install Python dependencies from requirements.txt
Ensure you are still in the pytorch
directory.
Install the Python dependencies listed in the requirements.txt
file:
pip install -r requirements.txt
Step 5: Check out the PyTorch Nightly branch
In the pytorch
directory, run the following command to switch to the Nightly branch:
git checkout nightly
Step 6: Build and install PyTorch
Modify the CMakeLists.txt
file to disable the Werror
flag:
Open the CMakeLists.txt
file located in the root directory of the PyTorch repository using a text editor.
Look for the line that contains Werror
and comment it out by adding a #
at the beginning of the line. For example:
#append_cxx_flag_if_supported("-Werror=return-type" CMAKE_CXX_FLAGS)
#append_cxx_flag_if_supported("-Werror=non-virtual-dtor" CMAKE_CXX_FLAGS)
#append_cxx_flag_if_supported("-Werror=braced-scalar-init" CMAKE_CXX_FLAGS)
#append_cxx_flag_if_supported("-Werror=range-loop-construct" CMAKE_CXX_FLAGS)
#append_cxx_flag_if_supported("-Werror=bool-operation" CMAKE_CXX_FLAGS)
Save the changes and close the file.