Skip to content

Commit f8a5984

Browse files
committed
Setup GHA repository cache.
1 parent d291621 commit f8a5984

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

.github/workflows/_build_torch_xla.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
GCLOUD_SERVICE_KEY: ${{ secrets.gcloud-service-key }}
3636
BAZEL_REMOTE_CACHE: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }}
3737
BAZEL_JOBS: "" # Let bazel decide the parallelism based on the number of CPUs.
38+
BAZEL_REPOSITORY_CACHE_RELATIVE_DIR: ".cache/repository-cache"
3839
BUILD_CPP_TESTS: 1
3940
steps:
4041
# Need to check out local composite actions before using them
@@ -43,30 +44,46 @@ jobs:
4344
if: inputs.has_code_changes == 'true'
4445
uses: actions/checkout@v4
4546
with:
46-
sparse-checkout: |
47-
.github/workflows/setup
47+
sparse-checkout: .github/workflows/setup
4848
path: .actions
49+
4950
- name: Setup
5051
if: inputs.has_code_changes == 'true'
5152
uses: ./.actions/.github/workflows/setup
53+
54+
- name: "Cache: Bazel Repository Cache"
55+
uses: actions/cache@v4
56+
with:
57+
key: bazel-repository-cache-${{ hashFiles("WORKSPACE") }}
58+
path: ${{ env.BAZEL_REPOSITORY_CACHE_RELATIVE_DIR }}
59+
enableCrossOsArchive: true
60+
5261
- name: Build
5362
if: inputs.has_code_changes == 'true'
63+
env:
64+
# Actual environment variable that is read by our build_utils.py for setting
65+
# the repository cache. Since we will be changing directories, we need to
66+
# provide the absolute path.
67+
BAZEL_REPOSITORY_CACHE_DIR: "${{ github.workspace }}/${{ env.BAZEL_REPOSITORY_CACHE_RELATIVE_DIR }}"
5468
shell: bash
5569
run: |
5670
cd pytorch/xla/infra/ansible
5771
ansible-playbook playbook.yaml -vvv -e "stage=build arch=amd64 accelerator=tpu src_root=${GITHUB_WORKSPACE} bundle_libtpu=0 build_cpp_tests=1 git_versioned_xla_build=1 cache_suffix=-ci" --skip-tags=fetch_srcs,install_deps
72+
5873
- name: Upload wheel
5974
if: inputs.has_code_changes == 'true'
6075
uses: actions/upload-artifact@v4
6176
with:
6277
name: torch-xla-wheels
6378
path: /dist/*.whl
79+
6480
- name: Upload CPP test binaries
6581
if: inputs.has_code_changes == 'true'
6682
uses: actions/upload-artifact@v4
6783
with:
6884
name: cpp-test-bin
6985
path: /tmp/test/bin
86+
7087
- name: Report no code changes
7188
if: inputs.has_code_changes == 'false'
7289
run: |

build_util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def bazel_options_from_env() -> Iterable[str]:
3636
bazel_flags.append('--remote_default_exec_properties=cache-silo-key=%s' %
3737
cache_silo_name)
3838

39+
repository_cache_name = os.getenv('BAZEL_REPOSITORY_CACHE_DIR')
40+
if repository_cache_name:
41+
bazel_flags.append('--repository_cache=%s' % repository_cache_name)
42+
3943
bazel_jobs = os.getenv('BAZEL_JOBS', default='')
4044
if bazel_jobs:
4145
bazel_flags.append('--jobs=%s' % bazel_jobs)

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
# CXX_ABI=""
4444
# value for cxx_abi flag; if empty, it is inferred from `torch._C`.
4545
#
46+
# BAZEL_REPOSITORY_CACHE_DIR
47+
# path to the directory to be used as bazel repository cache
48+
#
4649
from setuptools import setup, find_packages, distutils, Extension, command
4750
from setuptools.command import develop, build_ext
4851
import posixpath

0 commit comments

Comments
 (0)