diff --git a/.ci/scripts/utils.sh b/.ci/scripts/utils.sh index ed9f6f21a5b..677578ce3a4 100644 --- a/.ci/scripts/utils.sh +++ b/.ci/scripts/utils.sh @@ -60,12 +60,46 @@ install_pytorch_and_domains() { # Fetch the target commit pushd pytorch || return git checkout "${TORCH_VERSION}" - git submodule update --init --recursive - export USE_DISTRIBUTED=1 - # Then build and install PyTorch - python setup.py bdist_wheel - pip install "$(echo dist/*.whl)" + local system_name=$(uname) + if [[ "${system_name}" == "Darwin" ]]; then + local platform=$(python -c 'import sysconfig; import platform; v=platform.mac_ver()[0].split(".")[0]; platform=sysconfig.get_platform().split("-"); platform[1]=f"{v}_0"; print("_".join(platform))') + fi + local python_version=$(python -c 'import platform; v=platform.python_version_tuple(); print(f"{v[0]}{v[1]}")') + local torch_release=$(cat version.txt) + local torch_short_hash=${TORCH_VERSION:0:7} + local torch_wheel_path="cached_artifacts/pytorch/executorch/pytorch_wheels/${system_name}/${python_version}" + local torch_wheel_name="torch-${torch_release}%2Bgit${torch_short_hash}-cp${python_version}-cp${python_version}-${platform:-}.whl" + + local cached_torch_wheel="https://gha-artifacts.s3.us-east-1.amazonaws.com/${torch_wheel_path}/${torch_wheel_name}" + # Cache PyTorch wheel is only needed on MacOS, Linux CI already has this as part + # of the Docker image + local torch_wheel_not_found=0 + if [[ "${system_name}" == "Darwin" ]]; then + pip install "${cached_torch_wheel}" || torch_wheel_not_found=1 + else + torch_wheel_not_found=1 + fi + + # Found no such wheel, we will build it from source then + if [[ "${torch_wheel_not_found}" == "1" ]]; then + echo "No cached wheel found, continue with building PyTorch at ${TORCH_VERSION}" + + git submodule update --init --recursive + USE_DISTRIBUTED=1 python setup.py bdist_wheel + pip install "$(echo dist/*.whl)" + + # Only AWS runners have access to S3 + if command -v aws && [[ -z "${GITHUB_RUNNER:-}" ]]; then + for wheel_path in dist/*.whl; do + local wheel_name=$(basename "${wheel_path}") + echo "Caching ${wheel_name}" + aws s3 cp "${wheel_path}" "s3://gha-artifacts/${torch_wheel_path}/${wheel_name}" + done + fi + else + echo "Use cached wheel at ${cached_torch_wheel}" + fi # Grab the pinned audio and vision commits from PyTorch TORCHAUDIO_VERSION=$(cat .github/ci_commit_pins/audio.txt) diff --git a/.github/workflows/_unittest.yml b/.github/workflows/_unittest.yml index 6b08b6d1259..eb6c9c24257 100644 --- a/.github/workflows/_unittest.yml +++ b/.github/workflows/_unittest.yml @@ -49,4 +49,6 @@ jobs: ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} script: | set -eux + # This is needed to get the prebuilt PyTorch wheel from S3 + ${CONDA_RUN} --no-capture-output pip install awscli==1.37.21 .ci/scripts/unittest-macos.sh --build-tool "${{ inputs.build-tool }}" --build-mode "${{ inputs.build-mode }}" --editable "${{ inputs.editable }}" diff --git a/.github/workflows/trunk.yml b/.github/workflows/trunk.yml index 097a272d0fe..ecae932b74f 100644 --- a/.github/workflows/trunk.yml +++ b/.github/workflows/trunk.yml @@ -228,7 +228,7 @@ jobs: name: test-coreml-delegate uses: pytorch/test-infra/.github/workflows/macos_job.yml@main with: - runner: macos-13-xlarge + runner: macos-latest-xlarge python-version: '3.11' submodules: 'true' ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}