Skip to content
Latchkey

cpu_tests workflow (gordicaleksa/Open-NLLB)

The cpu_tests workflow from gordicaleksa/Open-NLLB, explained and optimized by Latchkey.

C

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 →
Source: gordicaleksa/Open-NLLB.github/workflows/cpu_tests.ymlLicense MITView source

What it does

This is the cpu_tests workflow from the gordicaleksa/Open-NLLB repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: cpu_tests

on: [push, pull_request]

jobs:
  unittest:

    strategy:
      fail-fast: false
      max-parallel: 12
      matrix:
        platform: [ubuntu-latest, macos-latest]
        python-version: [3.8, 3.9]

    runs-on: ${{ matrix.platform }}

    steps:
    - name: Checkout branch 🛎️
      uses: actions/checkout@v2

    - name: Setup Conda Environment
      uses: conda-incubator/setup-miniconda@v2
      with:
        activate-environment: fairseq
        python-version: ${{ matrix.python-version }}
        auto-update-conda: true
        use-only-tar-bz2: true

    - name: Cache Conda Environment
      uses: actions/cache@v2
      env:
        # Increase this value to reset cache if nothing has changed but you still
        # want to invalidate the cache
        CACHE_NUMBER: 0
      with:
        path: |
          /usr/share/miniconda/envs/
          /usr/local/miniconda/envs/
        key: fairseq-cpu-${{ matrix.platform }}-python${{ matrix.python-version }}-${{ env.CACHE_NUMBER }}-${{ hashFiles('**/.github/workflows/cpu_tests.yml') }}-${{ hashFiles('**/setup.py') }}


    - name: Install Dependencies
      shell: bash -l {0}
      run: |
        conda activate fairseq
        git submodule update --init --recursive
        pip install torch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 statsmodels==0.12.2 more_itertools submitit boto3 editdistance iopath ipdb ipython pyarrow pytest sacremoses sentencepiece subword-nmt transformers sklearn scipy fairscale Jinja2==2.11.3

    - name: Install Repository
      shell: bash -l {0}
      run: |
        conda activate fairseq
        python setup.py clean --all
        pip install --editable .
        python setup.py build_ext --inplace


    - name: Run CPU tests
      shell: bash -l {0}
      run: |
        conda activate fairseq
        cd tests
        pytest --continue-on-collection-errors -v .

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: cpu_tests
 
on: [push, pull_request]
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  unittest:
    timeout-minutes: 30
 
    strategy:
      fail-fast: false
      max-parallel: 12
      matrix:
        platform: [ubuntu-latest, macos-latest]
        python-version: [3.8, 3.9]
 
    runs-on: ${{ matrix.platform }}
 
    steps:
    - name: Checkout branch 🛎️
      uses: actions/checkout@v2
 
    - name: Setup Conda Environment
      uses: conda-incubator/setup-miniconda@v2
      with:
        activate-environment: fairseq
        python-version: ${{ matrix.python-version }}
        auto-update-conda: true
        use-only-tar-bz2: true
 
    - name: Cache Conda Environment
      uses: actions/cache@v2
      env:
        # Increase this value to reset cache if nothing has changed but you still
        # want to invalidate the cache
        CACHE_NUMBER: 0
      with:
        path: |
          /usr/share/miniconda/envs/
          /usr/local/miniconda/envs/
        key: fairseq-cpu-${{ matrix.platform }}-python${{ matrix.python-version }}-${{ env.CACHE_NUMBER }}-${{ hashFiles('**/.github/workflows/cpu_tests.yml') }}-${{ hashFiles('**/setup.py') }}
 
 
    - name: Install Dependencies
      shell: bash -l {0}
      run: |
        conda activate fairseq
        git submodule update --init --recursive
        pip install torch==1.10.1 torchvision==0.11.2 torchaudio==0.10.1 statsmodels==0.12.2 more_itertools submitit boto3 editdistance iopath ipdb ipython pyarrow pytest sacremoses sentencepiece subword-nmt transformers sklearn scipy fairscale Jinja2==2.11.3
 
    - name: Install Repository
      shell: bash -l {0}
      run: |
        conda activate fairseq
        python setup.py clean --all
        pip install --editable .
        python setup.py build_ext --inplace
 
 
    - name: Run CPU tests
      shell: bash -l {0}
      run: |
        conda activate fairseq
        cd tests
        pytest --continue-on-collection-errors -v .
 

What changed

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.

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 1 job (4 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow