generated from allenai/python-package-template
-
Notifications
You must be signed in to change notification settings - Fork 46
347 lines (299 loc) · 11.3 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
name: Main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
on:
pull_request:
branches:
- "*"
push:
branches:
- main
tags:
- "v*.*.*"
env:
CACHE_PREFIX: v5 # Change this to invalidate existing cache.
PYTHON_PATH: ./
DEFAULT_PYTHON: 3.9
WANDB_API_KEY: ${{ secrets.WANDB_API_KEY }}
BEAKER_TOKEN: ${{ secrets.BEAKER_TOKEN }}
BEAKER_WORKSPACE: ai2/tango-testing
BEAKER_DEFAULT_CLUSTER: ai2/allennlp-cirrascale
BEAKER_IMAGE: petew/tango-testing
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
checks:
name: python ${{ matrix.python }} - ${{ matrix.task.name }}
runs-on: [ubuntu-latest]
timeout-minutes: 30
permissions:
contents: "read"
id-token: "write"
strategy:
fail-fast: false
matrix:
python: ["3.9"]
task:
- name: Lint
extras: dev,all
requires_torch: true
run: |
ruff check .
- name: Type check
extras: dev,all
requires_torch: true
run: |
mypy --check-untyped-defs .
- name: Build
extras: dev,all
requires_torch: true
run: |
tango --version
python -m build
- name: Style
extras: dev
requires_torch: false
run: |
isort --check .
black --check .
- name: Docs
extras: dev,all
requires_torch: true
run: |
cd docs && make html SPHINXOPTS="-W --keep-going"
- name: Test
extras: dev
requires_torch: false
run: |
pytest -v --durations=10 --color=yes --doctest-modules --ignore=tests/integrations --ignore=tango/integrations tests/ tango/
- name: Datasets integration
extras: dev,datasets
requires_torch: false
run: |
pytest -v --color=yes --doctest-modules tango/integrations/datasets tests/integrations/datasets
- name: PyTorch integration
extras: dev,torch
requires_torch: true
run: |
pytest -v --color=yes --doctest-modules tango/integrations/torch tests/integrations/torch
- name: Transformers integration
extras: dev,flax,transformers
requires_torch: true
run: |
pytest -v --color=yes --doctest-modules tango/integrations/transformers tests/integrations/transformers
- name: FairScale integration
extras: dev,fairscale
requires_torch: true
run: |
pytest -v --color=yes --doctest-modules tango/integrations/fairscale tests/integrations/fairscale
- name: W&B integration
extras: dev,torch,flax,wandb
requires_torch: true
run: |
pytest -v --color=yes --doctest-modules tango/integrations/wandb tests/integrations/wandb
- name: Beaker integration
extras: dev,beaker
requires_torch: false
run: |
pytest -v --color=yes --doctest-modules tango/integrations/beaker tests/integrations/beaker
- name: Flax integration
extras: dev,flax,transformers
requires_torch: false
run: |
pytest -v --color=yes --doctest-modules tango/integrations/flax tests/integrations/flax
- name: GS integration
extras: dev,gs
requires_torch: false
run: |
pytest -v --color=yes --doctest-modules tango/integrations/gs tests/integrations/gs
- name: Example - train_lm
extras: dev,all
requires_torch: true
run: |
cd examples/train_lm
pytest -v --color=yes test.py
include:
# Run the core tests on other Python versions as well.
- task:
name: Test
extras: dev
requires_torch: false
run: |
pytest -v --durations=10 --color=yes --doctest-modules --ignore=tests/integrations --ignore=tango/integrations tests/ tango/
python: "3.8"
- task:
name: Test
extras: dev
requires_torch: false
run: |
pytest -v --durations=10 --color=yes --doctest-modules --ignore=tests/integrations --ignore=tango/integrations tests/ tango/
python: "3.10"
steps:
- uses: "actions/checkout@v3"
- name: Checkout
if: github.event_name != 'pull_request'
uses: actions/checkout@v3
# For pull requests we need to checkout the HEAD commit instead of the merge
# commit since some tests depend on having an existing commit.
- name: Checkout (pull request)
if: github.event_name == 'pull_request'
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install prerequisites
run: |
pip install --upgrade pip setuptools wheel virtualenv
- name: Set build variables
shell: bash
run: |
set -e
# Get the exact Python version to use in the cache key.
echo "PYTHON_VERSION=$(python --version)" >> $GITHUB_ENV
echo "RUNNER_ARCH=$(uname -m)" >> $GITHUB_ENV
# Use week number in cache key so we can refresh the cache weekly.
echo "WEEK_NUMBER=$(date +%V)" >> $GITHUB_ENV
echo "EXTRAS_HASH=$(python scripts/hash_extras.py ${{ matrix.task.extras }})" >> $GITHUB_ENV
- uses: actions/cache@v3
id: virtualenv-cache
with:
path: .venv
key: ${{ env.CACHE_PREFIX }}-${{ env.WEEK_NUMBER }}-${{ runner.os }}-${{ env.RUNNER_ARCH }}-${{ env.PYTHON_VERSION }}-${{ env.EXTRAS_HASH }}-${{ hashFiles('pyproject.toml') }}
- name: Setup virtual environment (no cache hit)
if: steps.virtualenv-cache.outputs.cache-hit != 'true'
run: |
test -d .venv || virtualenv -p $(which python) --copies --reset-app-data .venv
# Reference: https://github.com/marketplace/actions/authenticate-to-google-cloud#setup
- name: Authenticate to Google Cloud
if: matrix.task.name == 'GS integration'
uses: "google-github-actions/auth@v1"
with:
workload_identity_provider: "projects/10554368204/locations/global/workloadIdentityPools/tango-ci-pool/providers/tango-ci-provider"
service_account: "[email protected]"
- name: Pre-install torch
if: steps.virtualenv-cache.outputs.cache-hit != 'true' && (contains(matrix.task.extras, 'torch') || contains(matrix.task.extras, 'all') || matrix.task.requires_torch)
run: |
. .venv/bin/activate
pip install torch==2.0.0 --extra-index-url https://download.pytorch.org/whl/cpu
- name: Pre-install flax
if: steps.virtualenv-cache.outputs.cache-hit != 'true' && (contains(matrix.task.extras, 'flax') || contains(matrix.task.extras, 'all'))
run: |
. .venv/bin/activate
pip install flax==0.6.1 jax==0.4.1 jaxlib==0.4.1 tensorflow-cpu==2.9.1 optax==0.1.3
- name: Install editable (no cache hit)
if: steps.virtualenv-cache.outputs.cache-hit != 'true'
run: |
. .venv/bin/activate
pip install -e .[${{ matrix.task.extras }}]
- name: Install editable (cache hit)
if: steps.virtualenv-cache.outputs.cache-hit == 'true'
run: |
. .venv/bin/activate
pip install --no-deps -e .[${{ matrix.task.extras }}]
- name: Show environment info
run: |
. .venv/bin/activate
echo "========= Python location ==========="
which python
echo "========= Python version ============"
python --version
echo "========= Python packages ==========="
pip freeze
echo "========= Tango installation ========"
tango info
- name: ${{ matrix.task.name }}
run: |
. .venv/bin/activate
${{ matrix.task.run }}
- name: Upload package distribution files
if: matrix.task.name == 'Build' && matrix.python == env.DEFAULT_PYTHON
uses: actions/upload-artifact@v3
with:
name: package
path: dist
- name: Upload docs build
if: matrix.task.name == 'Docs' && matrix.python == env.DEFAULT_PYTHON
uses: actions/upload-artifact@v3
with:
name: docs
path: docs/build
- name: Clean up
if: always()
run: |
. .venv/bin/activate
pip uninstall -y ai2-tango
gpu_tests:
name: GPU Tests
runs-on: ubuntu-latest
steps:
- name: Determine current commit SHA (pull request)
if: github.event_name == 'pull_request'
run: |
echo "COMMIT_SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
- name: Determine current commit SHA (push)
if: github.event_name != 'pull_request'
run: |
echo "COMMIT_SHA=$GITHUB_SHA" >> $GITHUB_ENV
- name: GPU Tests
uses: allenai/[email protected]
with:
spec: |
version: v2
description: GPU Tests
tasks:
- name: tests
image:
beaker: ${{ env.BEAKER_IMAGE }}
context:
cluster: ${{ env.BEAKER_DEFAULT_CLUSTER }}
resources:
gpuCount: 2
envVars:
- name: COMMIT_SHA
value: ${{ env.COMMIT_SHA }}
command: ["/entrypoint.sh", "pytest", "-v", "-m", "gpu", "tests/"]
result:
path: /unused
token: ${{ secrets.BEAKER_TOKEN }}
workspace: ${{ env.BEAKER_WORKSPACE }}
clusters: ai2/general-cirrascale,ai2/allennlp-cirrascale,ai2/aristo-cirrascale,ai2/mosaic-cirrascale,ai2/s2-cirrascale
release:
name: Release
runs-on: ubuntu-latest
needs: [gpu_tests, checks]
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Install requirements
run: |
pip install -e .[dev]
- name: Prepare environment
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Download package distribution files
uses: actions/download-artifact@v3
with:
name: package
path: dist
- name: Generate release notes
run: |
python scripts/release_notes.py > ${{ github.workspace }}-RELEASE_NOTES.md
- name: Publish package to PyPI
run: |
twine upload -u __token__ -p ${{ secrets.PYPI_PASSWORD }} dist/*
- name: Publish GitHub release
uses: softprops/action-gh-release@v1
with:
body_path: ${{ github.workspace }}-RELEASE_NOTES.md
prerelease: ${{ contains(env.TAG, 'rc') }}
files: |
dist/*