Skip to content

Commit 036321a

Browse files
jazpurTTsshonTT
authored andcommitted
Create job to build torch-xla wheel and publish to tt-pypi
1 parent d36ded2 commit 036321a

File tree

3 files changed

+172
-0
lines changed

3 files changed

+172
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.10.12
40+
pyenv global 3.10.12
41+
ln -sf $HOME/.pyenv/versions/3.10.12/bin/python3.10 /usr/local/bin/python3.10
42+
43+
# Install essential packages for Python 3.10
44+
python3.10 -m pip install --upgrade pip
45+
python3.10 -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.10 setup.py bdist_wheel
54+
python3.10 setup.py develop
55+
56+
# Build PyTorch/XLA
57+
cd xla/
58+
python3.10 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
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: publish-wheel
2+
on:
3+
workflow_call:
4+
inputs:
5+
artifact_name:
6+
required: true
7+
type: string
8+
description: 'Name of the artifact containing the wheel'
9+
10+
jobs:
11+
12+
publish-wheels:
13+
name: "Publish wheels to internal PyPI"
14+
runs-on: ubuntu-latest
15+
permissions:
16+
id-token: write
17+
steps:
18+
- name: Validate inputs
19+
run: |
20+
if [ -z "${{ inputs.artifact_name }}" ]; then
21+
echo "ERROR: artifact_name input is empty or not provided!"
22+
exit 1
23+
fi
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: '3.10'
29+
30+
- name: Configure AWS Credentials
31+
uses: aws-actions/configure-aws-credentials@v4
32+
with:
33+
role-to-assume: ${{ secrets.PYPI_ROLE }}
34+
aws-region: ${{ secrets.PYPI_REGION }}
35+
36+
- name: Install s3pypi
37+
run: |
38+
pip install s3pypi
39+
40+
- name: Download wheel artifacts
41+
uses: actions/download-artifact@v4
42+
with:
43+
name: ${{ inputs.artifact_name }}
44+
path: ./dist
45+
46+
- name: Publish wheels to internal PyPI
47+
run: |
48+
wheel_count=$(find ./dist -type f -name "torch_xla*.whl" | wc -l)
49+
if [ "$wheel_count" -ne 1 ]; then
50+
echo "ERROR: Expected exactly 1 wheel file, but found $wheel_count!"
51+
exit 1
52+
fi
53+
54+
wheel_file=$(find ./dist -type f -name "torch_xla*.whl" -exec realpath {} \;)
55+
wheel_basename=$(basename "$wheel_file")
56+
echo "Wheel file found, publishing $wheel_basename to PyPi server"
57+
58+
s3pypi upload "$wheel_file" --bucket ${{ secrets.PYPI_BUCKET }} --put-root-index --force
59+
if [ $? -ne 0 ]; then
60+
echo "ERROR: Failed to upload $wheel_basename to S3 PyPI"
61+
exit 1
62+
fi
63+
echo "Successfully uploaded $wheel_basename"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build and Publish PyTorch/XLA
2+
on:
3+
push:
4+
branches:
5+
- master
6+
workflow_dispatch:
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'workflow_dispatch' }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
check_code_changes:
14+
name: Check Code Changes
15+
uses: ./.github/workflows/_check_code_changes.yml
16+
with:
17+
event_name: ${{ github.event_name }}
18+
base_sha: ${{ github.event.before }}
19+
head_sha: ${{ github.sha }}
20+
21+
build-torch-xla:
22+
name: "Build PyTorch/XLA for Python 3.10"
23+
if: needs.check_code_changes.outputs.has_code_changes == 'true'
24+
uses: ./.github/workflows/_build_torch_xla_3.10.yml
25+
needs: check_code_changes
26+
27+
publish-torch-xla:
28+
name: "Publish PyTorch/XLA"
29+
uses: ./.github/workflows/_publish_torch_xla.yml
30+
needs: build-torch-xla
31+
secrets: inherit
32+
with:
33+
artifact_name: ${{ needs.build-torch-xla.outputs.artifact_name }}

0 commit comments

Comments
 (0)