Skip to content

Commit 6b2dee3

Browse files
authored
Merge pull request #602 from michaelfeil/add-cache
Caching huggingface models in GH actions
2 parents 644bb37 + b0fc189 commit 6b2dee3

File tree

1 file changed

+80
-18
lines changed

1 file changed

+80
-18
lines changed

.github/workflows/test.yaml

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,76 @@ env:
2222

2323

2424
jobs:
25-
testing-job:
25+
initial-job: # Run initial job to create model cache
26+
defaults:
27+
run:
28+
working-directory: ${{ inputs.working-directory }}
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
os: [ubuntu-latest, windows-latest] # macos-latest
33+
python-version:
34+
- "3.12"
35+
coverage_tests: ["unit_test", "end_to_end"]
36+
37+
runs-on: ${{ matrix.os }}
38+
name: Py${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.coverage_tests }}
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
- name: Free Disk Space
43+
uses: "./.github/actions/disk_cleanup"
44+
if: runner.os == 'Linux'
45+
with:
46+
tool-cache: false
47+
android: true
48+
dotnet: true
49+
haskell: true
50+
large-packages: false
51+
docker-images: false
52+
swap-storage: false
53+
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
54+
uses: "./.github/actions/poetry_setup"
55+
with:
56+
python-version: ${{ matrix.python-version }}
57+
poetry-version: ${{ env.POETRY_VERSION }}
58+
working-directory: ${{ inputs.working-directory }}
59+
cache-key: ${{ inputs.working-directory }}-test-${{ matrix.coverage_tests }}
60+
61+
- name: Install dependencies from local
62+
# only if source is local
63+
shell: bash
64+
run: poetry install ${{ inputs.extra_poetry }}
65+
66+
- name: Cache HuggingFace models
67+
id: cache-models
68+
uses: actions/cache@v4
69+
with:
70+
path: |
71+
~/.cache/huggingface/hub
72+
key: hf-models-${{ inputs.working-directory }}-test-${{ matrix.coverage_tests }}
73+
74+
75+
- name: Run Pytest Coverage
76+
if: ${{ inputs.working-directory == 'libs/infinity_emb' }}
77+
run: |
78+
poetry run coverage run -m --source ./infinity_emb pytest tests/${{ matrix.coverage_tests }}
79+
poetry run coverage xml
80+
81+
- name: Run Pytest Coverage w/o infinity
82+
if: ${{ inputs.working-directory != 'libs/infinity_emb' }}
83+
run:
84+
make coverage
85+
86+
- name: Upload coverage Report to Codecov for python 3.11
87+
if: ${{ matrix.python-version == '3.11' && inputs.upload_coverage == true && matrix.os == 'ubuntu-latest'}}
88+
uses: codecov/codecov-action@v4
89+
env:
90+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
91+
92+
93+
testing-job: # Run the other jobs to use cache from initial job
94+
needs: initial-job
2695
defaults:
2796
run:
2897
working-directory: ${{ inputs.working-directory }}
@@ -34,24 +103,7 @@ jobs:
34103
- "3.9"
35104
- "3.10"
36105
- "3.11"
37-
- "3.12"
38106
coverage_tests: ["unit_test", "end_to_end"]
39-
exclude:
40-
# Exclude unit tests on macOS due to compatibility issues
41-
- python-version: "3.9"
42-
os: macos-latest
43-
coverage_tests: "unit_test"
44-
- python-version: "3.10"
45-
os: macos-latest
46-
coverage_tests: "unit_test"
47-
- python-version: "3.11"
48-
os: macos-latest
49-
coverage_tests: "unit_test"
50-
- python-version: "3.12"
51-
os: macos-latest
52-
coverage_tests: "unit_test"
53-
# continue-on-error: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11' }}
54-
55107

56108
runs-on: ${{ matrix.os }}
57109
name: Py${{ matrix.python-version }}-${{ matrix.os }}-${{ matrix.coverage_tests }}
@@ -82,6 +134,14 @@ jobs:
82134
shell: bash
83135
run: poetry install ${{ inputs.extra_poetry }}
84136

137+
- name: Cached HuggingFace models
138+
id: cache-models
139+
uses: actions/cache@v4
140+
with:
141+
path: |
142+
~/.cache/huggingface/hub
143+
key: hf-models-${{ inputs.working-directory }}-test-${{ matrix.coverage_tests }}
144+
85145
- name: Run Pytest Coverage
86146
if: ${{ inputs.working-directory == 'libs/infinity_emb' }}
87147
run: |
@@ -98,3 +158,5 @@ jobs:
98158
uses: codecov/codecov-action@v4
99159
env:
100160
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
161+
162+

0 commit comments

Comments
 (0)