-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a CI workflow for tests that requires pytorch CUDA. (#7140)
- Loading branch information
1 parent
8471826
commit 6fadbf5
Showing
6 changed files
with
232 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: build-torch-with-cuda | ||
on: | ||
workflow_call: | ||
inputs: | ||
dev-image: | ||
required: true | ||
type: string | ||
description: Base image for builds | ||
torch-commit: | ||
required: true | ||
type: string | ||
description: torch-commit | ||
runner: | ||
required: false | ||
type: string | ||
description: Runner type for the test | ||
default: linux.12xlarge | ||
jobs: | ||
build: | ||
runs-on: ${{ inputs.runner }} | ||
container: | ||
image: ${{ inputs.dev-image }} | ||
options: "--gpus all --shm-size 16g" | ||
env: | ||
_GLIBCXX_USE_CXX11_ABI: 0 | ||
steps: | ||
# See https://github.com/actions/checkout/issues/1014#issuecomment-1906802802 | ||
- name: Clean up workspace | ||
run: | | ||
ls -la | ||
rm -rvf ${GITHUB_WORKSPACE}/* | ||
- name: Setup CUDA environment | ||
shell: bash | ||
run: | | ||
echo "PATH=$PATH:/usr/local/cuda-12.1/bin" >> $GITHUB_ENV | ||
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-12.1/lib64" >> $GITHUB_ENV | ||
- name: Check GPU | ||
run: nvidia-smi | ||
- name: Checkout PyTorch Repo | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: pytorch/pytorch | ||
path: pytorch | ||
ref: ${{ inputs.torch-commit }} | ||
submodules: recursive | ||
- name: Build | ||
shell: bash | ||
run: | | ||
cd pytorch | ||
USE_CUDA=1 python setup.py bdist_wheel | ||
- name: Upload wheel | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: torch-with-cuda | ||
path: pytorch/dist/*.whl |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: get-torch-commit | ||
on: | ||
workflow_call: | ||
outputs: | ||
torch_commit: | ||
description: "torch commit to be used" | ||
value: ${{ jobs.get-commit.outputs.torch_commit }} | ||
|
||
jobs: | ||
get-commit: | ||
runs-on: ubuntu-20.04 | ||
outputs: | ||
torch_commit: ${{ steps.get_torch_commit.outputs.torch_commit }} | ||
steps: | ||
# See https://github.com/actions/checkout/issues/1014#issuecomment-1906802802 | ||
- name: Clean up workspace | ||
run: | | ||
ls -la | ||
rm -rvf ${GITHUB_WORKSPACE}/* | ||
- name: Checkout PyTorch Repo | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: pytorch/pytorch | ||
path: pytorch | ||
submodules: recursive | ||
- id: get_torch_commit | ||
name: Get torch commit | ||
run: | | ||
cd pytorch | ||
torch_commit=$(git rev-parse HEAD) | ||
echo "torch_commit=$torch_commit" >> "$GITHUB_OUTPUT" | ||
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
name: xla-test-requiring-torch-cuda | ||
on: | ||
workflow_call: | ||
inputs: | ||
dev-image: | ||
required: true | ||
type: string | ||
description: Base image for builds | ||
runner: | ||
required: false | ||
type: string | ||
description: Runner type for the test | ||
default: linux.12xlarge | ||
collect-coverage: | ||
required: false | ||
type: boolean | ||
description: Set to true to collect coverage information | ||
default: false | ||
timeout-minutes: | ||
required: false | ||
type: number | ||
default: 30 | ||
description: | | ||
Set the maximum (in minutes) how long the workflow should take to finish | ||
timeout-minutes: | ||
jobs: | ||
test: | ||
runs-on: ${{ inputs.runner }} | ||
container: | ||
image: ${{ inputs.dev-image }} | ||
options: "--gpus all --shm-size 16g" | ||
timeout-minutes: ${{ inputs.timeout-minutes }} | ||
env: | ||
USE_COVERAGE: ${{ inputs.collect-coverage && '1' || '0' }} | ||
BAZEL_JOBS: 16 | ||
BAZEL_REMOTE_CACHE: 1 | ||
steps: | ||
# See https://github.com/actions/checkout/issues/1014#issuecomment-1906802802 | ||
# TODO: need to find a way to reuse these steps. | ||
- name: Clean up workspace | ||
run: | | ||
ls -la | ||
rm -rvf ${GITHUB_WORKSPACE}/* | ||
- name: Fetch torch/torch_xla/torchvision wheels | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: torch-xla-wheels | ||
path: /tmp/wheels/ | ||
- name: Remove torch wheel built with CUDA disabled | ||
shell: bash | ||
run: | | ||
rm -rf /tmp/wheels/torch-* | ||
- name: Fetch the torch wheel built with CUDA enabled | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: torch-with-cuda | ||
path: /tmp/wheels/ | ||
- name: Fetch CUDA plugin | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: cuda-plugin | ||
path: /tmp/wheels/ | ||
- name: Setup CUDA environment | ||
shell: bash | ||
run: | | ||
echo "XLA_REGISTER_INSTALLED_PLUGINS=1" >> $GITHUB_ENV | ||
echo "PATH=$PATH:/usr/local/cuda-12.1/bin" >> $GITHUB_ENV | ||
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-12.1/lib64" >> $GITHUB_ENV | ||
- name: Check GPU | ||
run: nvidia-smi | ||
- name: Install wheels | ||
shell: bash | ||
run: | | ||
pip install /tmp/wheels/*.whl | ||
# TODO: Add these in setup.py | ||
pip install fsspec | ||
pip install rich | ||
echo "Import check..." | ||
python -c "import torch, torch_xla, torchvision" | ||
echo "Import check done." | ||
echo "Check if CUDA is available for PyTorch..." | ||
python -c "import torch; assert torch.cuda.is_available()" | ||
echo "CUDA is available for PyTorch." | ||
- name: Record PyTorch commit | ||
run: | | ||
# Don't just pipe output in shell because imports may do extra logging | ||
python -c " | ||
import torch_xla.version | ||
with open('$GITHUB_ENV', 'a') as f: | ||
f.write(f'PYTORCH_COMMIT={torch_xla.version.__torch_gitrev__}\n') | ||
" | ||
- name: Checkout PyTorch Repo | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: pytorch/pytorch | ||
path: pytorch | ||
ref: ${{ env.PYTORCH_COMMIT }} | ||
- name: Checkout PyTorch/XLA Repo | ||
uses: actions/checkout@v4 | ||
with: | ||
path: pytorch/xla | ||
- name: Test | ||
shell: bash | ||
run: | | ||
set -xue | ||
PJRT_DEVICE=CUDA python pytorch/xla/test/test_operations.py -v | ||
PJRT_DEVICE=CUDA python pytorch/xla/test/dynamo/test_dynamo.py -v |
This file contains 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
This file contains 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