|
| 1 | +name: build-torch-xla |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + torch_version: |
| 6 | + description: 'Torch version to build (default: 2.7.0)' |
| 7 | + required: false |
| 8 | + type: string |
| 9 | + default: '2.7.0' |
| 10 | + outputs: |
| 11 | + artifact_name: |
| 12 | + description: 'Name of uploaded wheels artifact' |
| 13 | + value: ${{ jobs.build-wheels.outputs.artifact_name }} |
| 14 | + workflow_dispatch: |
| 15 | +jobs: |
| 16 | + build-wheels: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + env: |
| 19 | + ARTIFACT_NAME: install-artifact-torch-xla-release |
| 20 | + GIT_VERSIONED_XLA_BUILD: 1 |
| 21 | + container: |
| 22 | + image: us-central1-docker.pkg.dev/tpu-pytorch-releases/docker/development:tpu |
| 23 | + options: --user root |
| 24 | + outputs: |
| 25 | + artifact_name: ${{ steps.set_upload_name.outputs.artifact_name }} |
| 26 | + steps: |
| 27 | + - name: "Build Torch/XLA wheel" |
| 28 | + id: build_wheels |
| 29 | + run: | |
| 30 | + cmake --version |
| 31 | + apt-get update && apt-get install -y curl git build-essential |
| 32 | +
|
| 33 | + # Clean up any existing pyenv installation |
| 34 | + rm -rf $HOME/.pyenv |
| 35 | +
|
| 36 | + curl https://pyenv.run | bash |
| 37 | + export PATH="$HOME/.pyenv/bin:$PATH" |
| 38 | + eval "$(pyenv init -)" |
| 39 | + pyenv install 3.11 |
| 40 | + pyenv global 3.11 |
| 41 | + ln -sf $HOME/.pyenv/versions/3.11/bin/python3.11 /usr/local/bin/python3.11 |
| 42 | +
|
| 43 | + # Install essential packages for Python 3.11 |
| 44 | + python3.11 -m pip install --upgrade pip |
| 45 | + python3.11 -m pip install pyyaml setuptools wheel numpy typing_extensions requests |
| 46 | +
|
| 47 | + cd /tmp |
| 48 | + git clone --recursive --branch v${{ inputs.torch_version || '2.7.0' }} https://github.com/pytorch/pytorch.git |
| 49 | + cd pytorch/ |
| 50 | + git clone --recursive https://github.com/tenstorrent/pytorch-xla.git xla |
| 51 | +
|
| 52 | + # copy pre-built wheels from cache |
| 53 | + python3.11 setup.py bdist_wheel |
| 54 | + python3.11 setup.py develop |
| 55 | +
|
| 56 | + # Build PyTorch/XLA |
| 57 | + cd xla/ |
| 58 | + python3.11 setup.py bdist_wheel |
| 59 | +
|
| 60 | + # Collect wheels |
| 61 | + mkdir -p /dist |
| 62 | + cp dist/*.whl /dist/ |
| 63 | +
|
| 64 | + # Clean up any existing pyenv installation |
| 65 | + rm -rf $HOME/.pyenv |
| 66 | +
|
| 67 | + - name: "Upload Wheels Artifact" |
| 68 | + id: upload |
| 69 | + uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: ${{ env.ARTIFACT_NAME }} |
| 72 | + path: /dist/*.whl |
| 73 | + |
| 74 | + - name: Set artifact name output |
| 75 | + id: set_upload_name |
| 76 | + run: echo "artifact_name=${{ env.ARTIFACT_NAME }}" >> $GITHUB_OUTPUT |
0 commit comments