@@ -8,25 +8,25 @@ BUILD_LATEST=false
88FORCE_REINSTALL=false
99PYTORCH_CURRENT_COMMIT=" "
1010VENV=false
11+ CLEAN=true
1112for arg in " $@ " ; do
1213 case $arg in
1314 --source)
1415 BUILD_PYTORCH=true
15- shift
1616 ;;
1717 --latest)
1818 # Build from the latest pytorch commit in the main branch.
1919 BUILD_PYTORCH=true
2020 BUILD_LATEST=true
21- shift
2221 ;;
2322 --force-reinstall)
2423 FORCE_REINSTALL=true
25- shift
2624 ;;
2725 --venv)
2826 VENV=true
29- shift
27+ ;;
28+ -nc|--no-clean)
29+ CLEAN=false
3030 ;;
3131 --help)
3232 echo " Example usage: ./install-pytorch.sh [--source | --latest | --force-reinstall | --venv]"
@@ -134,24 +134,34 @@ if [ ! -d "$BASE" ]; then
134134 mkdir $BASE
135135fi
136136
137- echo " **** Cleaning $PYTORCH_PROJ before build ****"
138- rm -rf $PYTORCH_PROJ
139-
140- echo " **** Cloning $PYTORCH_PROJ ****"
141- cd $BASE
142- git clone --single-branch -b main --recurse-submodules https://github.com/pytorch/pytorch.git
143-
144- cd $PYTORCH_PROJ
137+ if [ " $CLEAN " = true ]; then
138+ [ " $BUILD_LATEST " = false ] || PYTORCH_PINNED_COMMIT=main
139+ if [ -d " $PYTORCH_PROJ " ] && cd " $PYTORCH_PROJ " && \
140+ git fetch --recurse-submodules && \
141+ git reset --hard $PYTORCH_PINNED_COMMIT && \
142+ git submodule update --init --recursive && \
143+ git clean -xffd; then
144+ echo " **** Cleaning $PYTORCH_PROJ before build ****"
145+ else
146+ cd $BASE
147+ rm -rf " $PYTORCH_PROJ "
148+ echo " **** Cloning PyTorch into $PYTORCH_PROJ ****"
149+ git clone --single-branch -b main --recurse-submodules https://github.com/pytorch/pytorch.git
150+ cd " $PYTORCH_PROJ "
151+
152+ if [ " $BUILD_LATEST " = false ]; then
153+ git checkout $PYTORCH_PINNED_COMMIT
154+ git submodule update --init --recursive
155+ git clean -xffd
156+ fi
157+ fi
145158
146- if [ " $BUILD_LATEST " = false ] ; then
147- git fetch --all
148- git checkout $PYTORCH_PINNED_COMMIT
149- git submodule update --recursive
159+ # Apply Triton specific patches to PyTorch.
160+ $SCRIPTS_DIR /patch-pytorch.sh
161+ else
162+ cd " $PYTORCH_PROJ "
150163fi
151164
152- # Apply Triton specific patches to PyTorch.
153- $SCRIPTS_DIR /patch-pytorch.sh
154-
155165echo " ****** Building $PYTORCH_PROJ ******"
156166pip install -r requirements.txt
157167pip install cmake ninja
0 commit comments