Skip to content

Instantly share code, notes, and snippets.

@peterbell10
Last active August 18, 2020 13:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterbell10/64da921e4e2b24d65c73066055e2e92b to your computer and use it in GitHub Desktop.
Save peterbell10/64da921e4e2b24d65c73066055e2e92b to your computer and use it in GitHub Desktop.
Building pytorch using conda
#!/bin/bash
# Activate the build environment
eval "$(conda shell.bash hook)"
conda activate pytorch-dev
cd ~/git/pytorch
# Enable ccache
export CCACHE_COMPRESS=true
export CMAKE_C_COMPILER_LAUNCHER=ccache
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
export CMAKE_CUDA_COMPILER_LAUNCHER=ccache
# Configure the pytorch build
export CMAKE_PREFIX_PATH=$CONDA_PREFIX
export USE_CUDA=1
export USE_XNNPACK=1
export USE_DISTRIBUTED=0
export USE_NCCL=0
export MAX_JOBS=24
export CUDA_HOME=/usr/local/cuda-10.2.89
export DEBUG=1
# Cleanup any old torch installs
pip uninstall torch -y
# Build pytorch and install to the curren environment (pytorch-dev)
python setup.py install
name: pytorch-dev
channels:
- conda-forge
- pytorch
dependencies:
- python=3.8
- numpy
- ninja
- pyyaml
- mkl
- mkl-include
- setuptools
- cmake
- cffi
- typing
- pytest
- magma-cuda102
- pytest
- hypothesis
- ccache
- flake8

Setting up a development environment to build and test pytorch

  1. Install miniconda into your home directory:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x ./Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh

Then follow the setup prompts. You may need to restart your terminal after installing to update your environment variables.

  1. Setup conda environment and clone pytorch:
conda env create -f pytorch-dev.yaml
git clone https://github.com/pytorch/pytorch
git -C pytorch submodule update --init --recursive
  1. Build using the included script:
./build.sh

After this finishes, pytorch will be installed in the conda environment pytorch-dev which can be enabled with

conda activate pytorch-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment