build-torch-xla #12
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' | |
xla_ref: | |
description: 'XLA reference to build (default: HEAD)' | |
required: false | |
type: string | |
default: 'HEAD' | |
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 | |
XLA_REF: ${{ inputs.xla_ref || github.event.pull_request.head.sha || github.ref }} | |
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: "Build Torch/XLA wheel" | |
shell: bash | |
id: build_wheels | |
timeout-minutes: 540 # 9 hours | |
run: | | |
echo "Building Torch/XLA with XLA ref: $XLA_REF" | |
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.11 | |
pyenv global 3.11 | |
ln -sf $(pyenv which python3.11) /usr/local/bin/python3.11 | |
# Install essential packages for Python 3.11 | |
python3.11 -m pip install --upgrade pip | |
python3.11 -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 | |
( | |
# Build PyTorch | |
# From https://docs.pytorch.org/FBGEMM/fbgemm/development/BuildInstructions.html, section "Build Issues with GCC 12+" | |
export CFLAGS+=" -Wno-error=maybe-uninitialized -Wno-error=uninitialized -Wno-error=restrict" | |
export CXXFLAGS+=" -Wno-error=maybe-uninitialized -Wno-error=uninitialized -Wno-error=restrict" | |
# copy pre-built wheels from cache | |
python3.11 setup.py bdist_wheel | |
python3.11 setup.py develop | |
) | |
# Build PyTorch/XLA | |
cd xla/ | |
git fetch --no-tags --depth=1 origin "${XLA_REF}" | |
git checkout --detach FETCH_HEAD | |
python3.11 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 |