Skip to content

Commit 1e3e5eb

Browse files
[scripts/install-pytorch.sh] Do not delete pytorch on clean (intel#3256)
Instead of deletion and clonning the repo again, use git reset + clean. Also added the --no-clean option. It allows to proceed building after resolving an error. Closes intel#3257
1 parent 97caaf2 commit 1e3e5eb

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

scripts/install-pytorch.sh

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ BUILD_LATEST=false
88
FORCE_REINSTALL=false
99
PYTORCH_CURRENT_COMMIT=""
1010
VENV=false
11+
CLEAN=true
1112
for 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
135135
fi
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"
150163
fi
151164

152-
# Apply Triton specific patches to PyTorch.
153-
$SCRIPTS_DIR/patch-pytorch.sh
154-
155165
echo "****** Building $PYTORCH_PROJ ******"
156166
pip install -r requirements.txt
157167
pip install cmake ninja

0 commit comments

Comments
 (0)