From 4e691dd7b9d782d6408b919f48bfbbf3758df52e Mon Sep 17 00:00:00 2001 From: Yifei Teng Date: Wed, 25 Sep 2024 11:28:35 -0700 Subject: [PATCH] [developer] Add a script to automate building torch_xla (#7876) --- CONTRIBUTING.md | 5 +++++ scripts/build_developer.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 scripts/build_developer.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 05d60c2f84e..33c59a57cc9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -73,6 +73,11 @@ We recommend you to use our prebuilt Docker image to start your development work # Output: xla:0 ``` +**Subsequent builds**: after setting up the source checkouts and building them +for the first time, you may find the need to build everything again after e.g. +`git pull`. You can run `scripts/build_developer.sh` which will build PyTorch, +TorchVision, and PyTorch/XLA according to the above. + ### Manually build in Docker container * Setup Development Docker Image diff --git a/scripts/build_developer.sh b/scripts/build_developer.sh new file mode 100755 index 00000000000..2590860424e --- /dev/null +++ b/scripts/build_developer.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e # Fail on any error. +set -x # Display commands being run. + +# Change to pytorch directory. +cd "$(dirname "$(readlink -f "$0")")" +cd ../../ + +python3 setup.py bdist_wheel +python3 setup.py install +cd .. + +# Optionally install torchvision. +if [ -d "vision" ]; then + cd vision + python3 setup.py develop +fi + +cd .. +cd pytorch/xla +python3 setup.py develop + +# libtpu is needed to talk to the TPUs. If TPUs are not present, +# installing this wouldn't hurt either. +pip install torch_xla[tpu] -f https://storage.googleapis.com/libtpu-releases/index.html + +# Test that the library is installed correctly. +python3 -c 'import torch_xla as xla; print(xla.device())' +