CPU Unit Test C++ CI workflow (meta-pytorch/torchrec)
The CPU Unit Test C++ CI workflow from meta-pytorch/torchrec, explained and optimized by Latchkey.
CI health: C - fair
Run this on Latchkey for self-healing, caching, and up to 58% lower cost.
Grade your own workflow free or run it on Latchkey →What it does
This is the CPU Unit Test C++ CI workflow from the meta-pytorch/torchrec repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-3-Clause license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: CPU Unit Test C++ CI
on:
push:
branches:
# only run tests on main branch & nightly; release should be triggered manually
- nightly
- main
tags:
# Release candidate tags look like: v1.11.0-rc1
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
paths-ignore:
- "docs/*"
- "third_party/*"
- .gitignore
- "*.md"
pull_request:
paths-ignore:
- "docs/*"
- "third_party/*"
- .gitignore
- "*.md"
jobs:
build_test:
strategy:
fail-fast: false
matrix:
include:
- os: linux.2xlarge
python-version: 3.9
python-tag: "py39"
- os: linux.2xlarge
python-version: '3.10'
python-tag: "py310"
- os: linux.2xlarge
python-version: '3.11'
python-tag: "py311"
- os: linux.2xlarge
python-version: '3.12'
python-tag: "py312"
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
permissions:
id-token: write
contents: read
with:
runner: ${{ matrix.os }}
timeout: 15
script: |
ldd --version
conda create -y --name build_binary python=${{ matrix.python-version }}
conda info
python --version
echo "Starting C++ Tests"
conda install -n build_binary -y gxx_linux-64
conda run -n build_binary \
x86_64-conda-linux-gnu-g++ --version
conda install -n build_binary -c anaconda redis -y
conda run -n build_binary redis-server --daemonize yes
mkdir cpp-build
cd cpp-build
conda run -n build_binary cmake \
-DBUILD_TEST=ON \
-DBUILD_REDIS_IO=ON \
-DCMAKE_PREFIX_PATH=/opt/conda/envs/build_binary/lib/python${{ matrix.python-version }}/site-packages/torch/share/cmake ..
conda run -n build_binary make -j
conda run -n build_binary ctest -V .
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions name: CPU Unit Test C++ CI on: push: branches: # only run tests on main branch & nightly; release should be triggered manually - nightly - main tags: # Release candidate tags look like: v1.11.0-rc1 - v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+ paths-ignore: - "docs/*" - "third_party/*" - .gitignore - "*.md" pull_request: paths-ignore: - "docs/*" - "third_party/*" - .gitignore - "*.md" concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: build_test: timeout-minutes: 30 strategy: fail-fast: false matrix: include: - os: linux.2xlarge python-version: 3.9 python-tag: "py39" - os: linux.2xlarge python-version: '3.10' python-tag: "py310" - os: linux.2xlarge python-version: '3.11' python-tag: "py311" - os: linux.2xlarge python-version: '3.12' python-tag: "py312" uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main permissions: id-token: write contents: read with: runner: ${{ matrix.os }} timeout: 15 script: | ldd --version conda create -y --name build_binary python=${{ matrix.python-version }} conda info python --version echo "Starting C++ Tests" conda install -n build_binary -y gxx_linux-64 conda run -n build_binary \ x86_64-conda-linux-gnu-g++ --version conda install -n build_binary -c anaconda redis -y conda run -n build_binary redis-server --daemonize yes mkdir cpp-build cd cpp-build conda run -n build_binary cmake \ -DBUILD_TEST=ON \ -DBUILD_REDIS_IO=ON \ -DCMAKE_PREFIX_PATH=/opt/conda/envs/build_binary/lib/python${{ matrix.python-version }}/site-packages/torch/share/cmake .. conda run -n build_binary make -j conda run -n build_binary ctest -V .
What changed
- Cancel superseded runs when a branch or PR gets a newer push.
- Add a job timeout so a hung step cannot burn hours of runner time.
1 third-party action is referenced by a movable tag. Pin it to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.