Build and test PyTorch #200
This file contains hidden or 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
| # ******************************************************************************* | |
| # Copyright 2025 Arm Limited and affiliates. | |
| # SPDX-License-Identifier: Apache-2.0 | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| # ******************************************************************************* | |
| name: "Build and test PyTorch" | |
| #* To avoid duplicate jobs running when both push and PR is satisfied, we use this: | |
| #* https://github.com/orgs/community/discussions/26940#discussioncomment-5686753 | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - ".github/**" | |
| - "ML-Frameworks/pytorch-aarch64/**" | |
| - "ML-Frameworks/utils/**" | |
| # Exclusions (must come after the includes): | |
| - "!ML-Frameworks/pytorch-aarch64/CHANGELOG.md" | |
| - "!ML-Frameworks/pytorch-aarch64/README.md" | |
| - "!ML-Frameworks/pytorch-aarch64/welcome.txt" | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| paths: | |
| - ".github/**" | |
| - "ML-Frameworks/pytorch-aarch64/**" | |
| - "ML-Frameworks/utils/**" | |
| # Exclusions (must come after the includes): | |
| - "!ML-Frameworks/pytorch-aarch64/CHANGELOG.md" | |
| - "!ML-Frameworks/pytorch-aarch64/README.md" | |
| - "!ML-Frameworks/pytorch-aarch64/welcome.txt" | |
| schedule: | |
| #* minute (0-59) hour (0-23) day (1-31) month (1-12) day of the week (0 - 6) | |
| #* cron jobs run on the default (main) branch. | |
| #* set to run at 5am UCT | |
| - cron: "0 5 * * *" | |
| #* allow manual trigger of workflow when needed. | |
| workflow_dispatch: | |
| #* Stop stale workflows when pull requests are updated: https://stackoverflow.com/a/70972844 | |
| #* Does not apply to the main branch. | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | |
| # Declare default permissions as read only. | |
| permissions: read-all | |
| jobs: | |
| build-image: | |
| strategy: | |
| matrix: | |
| config: | |
| [ | |
| { name: c7g, label: ah-ubuntu_24_04-c7g_8x-100 }, | |
| { name: c8g, label: ah-ubuntu_24_04-c8g_8x } | |
| ] | |
| runs-on: ${{ matrix.config.label }} | |
| env: | |
| CCACHE_HOST_DIR: ${{ github.workspace }}/Tool-Solutions/ML-Frameworks/pytorch-aarch64/.ccache | |
| TORCH_BUILD_CONTAINER_ID_FILE: ${{ github.workspace }}/Tool-Solutions/ML-Frameworks/pytorch-aarch64/.torch_build_container_id | |
| steps: | |
| - name: Checkout Tool-Solutions | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| path: Tool-Solutions | |
| - name: Set up Docker | |
| uses: docker/setup-docker-action@v4 | |
| - name: Create unique cache key from the year and week (YYYY-WW) | |
| id: cache_suffix | |
| run: echo "week=$(date -u +%G-%V)" >> "$GITHUB_OUTPUT" | |
| # Restore cache if available. GitHub automatically evicts cache entries that have not been | |
| # accessed for over 7 days. We rotate the cache key weekly; if no cache exists for the | |
| # current week, a cache from a previous week (via the prefix restore key) will be restored | |
| # and then saved under the current week's key at the end of the job. This effectively limits | |
| # the cache to at most two weeks of cache data. | |
| - name: Restore ccache cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: ${{ env.CCACHE_HOST_DIR }} | |
| key: ccache-${{ matrix.config.name }}-${{ steps.cache_suffix.outputs.week }} | |
| restore-keys: | | |
| ccache-${{ matrix.config.name }}- | |
| - name: Build Tool-Solutions PyTorch | |
| working-directory: ${{ github.workspace }}/Tool-Solutions/ML-Frameworks/pytorch-aarch64 | |
| run: ${{ github.workspace }}/Tool-Solutions/ML-Frameworks/pytorch-aarch64/build.sh | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| CCACHE_HOST_DIR: ${{ env.CCACHE_HOST_DIR }} | |
| CCACHE_MAXSIZE: 2G | |
| - name: Print ccache disk usage | |
| run: du -sh "${{ env.CCACHE_HOST_DIR }}" || true | |
| - name: Report final ccache build stats | |
| run: docker exec "$(cat ${{ env.TORCH_BUILD_CONTAINER_ID_FILE }})" ccache -s || true | |
| - name: Save image as an artifact | |
| run: docker save toolsolutions-pytorch:latest -o toolsolutions-pytorch-image-${{ matrix.config.name }}.tar | |
| - name: Upload build artifact | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: toolsolutions-pytorch-image-${{ matrix.config.name }} | |
| path: toolsolutions-pytorch-image-${{ matrix.config.name }}.tar | |
| compression-level: 9 | |
| retention-days: 1 | |
| test: | |
| needs: build-image | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| config: | |
| [ | |
| { name: c7g, label: ah-ubuntu_24_04-c7g_8x-100 }, | |
| { name: c8g, label: ah-ubuntu_24_04-c8g_8x } | |
| ] | |
| onednn_fpmath_mode: [FP32, BF16] | |
| runs-on: ${{ matrix.config.label }} | |
| steps: | |
| - name: Download image artifact | |
| uses: actions/download-artifact@v5 | |
| with: | |
| name: toolsolutions-pytorch-image-${{ matrix.config.name }} | |
| path: . | |
| - name: Set up Docker | |
| uses: docker/setup-docker-action@v4 | |
| - name: Load Docker image | |
| run: docker load -i toolsolutions-pytorch-image-${{ matrix.config.name }}.tar | |
| - name: Run smoke tests | |
| run: | | |
| docker run --rm \ | |
| -e ONEDNN_DEFAULT_FPMATH_MODE=${{ matrix.onednn_fpmath_mode }} \ | |
| toolsolutions-pytorch:latest ./test-examples.sh | |
| - name: Run unit tests | |
| run: | | |
| docker run --rm \ | |
| -e ONEDNN_DEFAULT_FPMATH_MODE=${{ matrix.onednn_fpmath_mode }} \ | |
| toolsolutions-pytorch:latest ./run_unit_tests.sh |