build-torch-xla #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build-torch-xla | |
on: | |
workflow_call: | |
inputs: | |
torch_version: | |
description: 'Torch version to build (default: 2.7.0)' | |
required: false | |
type: string | |
default: '2.7.0' | |
outputs: | |
artifact_name: | |
description: 'Name of uploaded wheels artifact' | |
value: ${{ jobs.build-wheels.outputs.artifact_name }} | |
workflow_dispatch: | |
jobs: | |
build-wheels: | |
runs-on: ubuntu-latest | |
env: | |
ARTIFACT_NAME: install-artifact-torch-xla-release | |
GIT_VERSIONED_XLA_BUILD: 1 | |
container: | |
image: us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/development:tpu | |
options: --user root | |
outputs: | |
artifact_name: ${{ steps.set_upload_name.outputs.artifact_name }} | |
steps: | |
- name: Free Disk Space (Ubuntu) | |
uses: jlumbroso/free-disk-space@main | |
with: | |
# this might remove tools that are actually needed, | |
# if set to "true" but frees about 6 GB | |
tool-cache: false | |
# all of these default to true, but feel free to set to | |
# "false" if necessary for your workflow | |
android: true | |
dotnet: true | |
haskell: true | |
large-packages: true | |
docker-images: true | |
swap-storage: true | |
- name: "Build Torch/XLA wheel" | |
id: build_wheels | |
run: | | |
cmake --version | |
apt-get update && apt-get install -y curl git build-essential | |
# Clean up any existing pyenv installation | |
rm -rf $HOME/.pyenv | |
curl https://pyenv.run | bash | |
export PATH="$HOME/.pyenv/bin:$PATH" | |
eval "$(pyenv init -)" | |
pyenv install 3.10.12 | |
pyenv global 3.10.12 | |
ln -sf $HOME/.pyenv/versions/3.10.12/bin/python3.10 /usr/local/bin/python3.10 | |
# Install essential packages for Python 3.10 | |
python3.10 -m pip install --upgrade pip | |
python3.10 -m pip install pyyaml setuptools wheel numpy typing_extensions requests | |
cd /tmp | |
git clone --recursive --branch v${{ inputs.torch_version || '2.7.0' }} https://github.com/pytorch/pytorch.git | |
cd pytorch/ | |
git clone --recursive https://github.com/tenstorrent/pytorch-xla.git xla | |
# copy pre-built wheels from cache | |
python3.10 setup.py bdist_wheel | |
python3.10 setup.py develop | |
# create debug whl | |
export DEBUG=1 | |
# Build PyTorch/XLA | |
cd xla/ | |
python3.10 setup.py bdist_wheel | |
# Collect wheels | |
mkdir -p /dist | |
cp dist/*.whl /dist/ | |
# Clean up any existing pyenv installation | |
rm -rf $HOME/.pyenv | |
- name: "Upload Wheels Artifact" | |
id: upload | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT_NAME }} | |
path: /dist/*.whl | |
- name: Set artifact name output | |
id: set_upload_name | |
run: echo "artifact_name=${{ env.ARTIFACT_NAME }}" >> $GITHUB_OUTPUT |