Skip to content

Commit a69a684

Browse files
NicolasHugfacebook-github-bot
authored andcommitted
[fbsync] port special tests from CircleCI to GHA (#7396)
Reviewed By: vmoens Differential Revision: D44416639 fbshipit-source-id: a1a088a1a8e04a38889652c1316ab00bb3f8f2ea
1 parent 6b06087 commit a69a684

File tree

5 files changed

+129
-14
lines changed

5 files changed

+129
-14
lines changed

.github/unittest.sh renamed to .github/scripts/setup-env.sh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,3 @@ echo '::endgroup::'
9595
echo '::group::Collect PyTorch environment information'
9696
python -m torch.utils.collect_env
9797
echo '::endgroup::'
98-
99-
echo '::group::Install testing utilities'
100-
pip install --progress-bar=off pytest pytest-mock pytest-cov
101-
echo '::endgroup::'
102-
103-
echo '::group::Run tests'
104-
pytest --durations=25
105-
echo '::endgroup::'

.github/scripts/unittest.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
./.github/scripts/setup-env.sh
6+
7+
# Prepare conda
8+
CONDA_PATH=$(which conda)
9+
eval "$(${CONDA_PATH} shell.bash hook)"
10+
conda activate ci
11+
12+
echo '::group::Install testing utilities'
13+
pip install --progress-bar=off pytest pytest-mock pytest-cov
14+
echo '::endgroup::'
15+
16+
echo '::group::Run unittests'
17+
pytest --durations=25
18+
echo '::endgroup::'

.github/workflows/test-linux.yml

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Unit-tests on Linux
1+
name: Tests on Linux
22

33
on:
44
pull_request:
@@ -10,7 +10,7 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13-
tests:
13+
unittests:
1414
strategy:
1515
matrix:
1616
python-version:
@@ -34,8 +34,70 @@ jobs:
3434
gpu-arch-version: ${{ matrix.gpu-arch-version }}
3535
timeout: 120
3636
script: |
37+
set -euo pipefail
38+
3739
export PYTHON_VERSION=${{ matrix.python-version }}
3840
export GPU_ARCH_TYPE=${{ matrix.gpu-arch-type }}
3941
export GPU_ARCH_VERSION=${{ matrix.gpu-arch-version }}
4042
41-
./.github/unittest.sh
43+
./.github/scripts/unittest.sh
44+
45+
onnx:
46+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
47+
with:
48+
repository: pytorch/vision
49+
script: |
50+
set -euo pipefail
51+
52+
export PYTHON_VERSION=3.8
53+
export GPU_ARCH_TYPE=cpu
54+
55+
./.github/scripts/setup-env.sh
56+
57+
# Prepare conda
58+
CONDA_PATH=$(which conda)
59+
eval "$(${CONDA_PATH} shell.bash hook)"
60+
conda activate ci
61+
62+
echo '::group::Install ONNX'
63+
pip install --progress-bar=off onnx onnxruntime
64+
echo '::endgroup::'
65+
66+
echo '::group::Install testing utilities'
67+
pip install --progress-bar=off pytest
68+
echo '::endgroup::'
69+
70+
echo '::group::Run ONNX tests'
71+
pytest --durations=25 -v test/test_onnx.py
72+
echo '::endgroup::'
73+
74+
unittests-extended:
75+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
76+
with:
77+
repository: pytorch/vision
78+
script: |
79+
set -euo pipefail
80+
81+
export PYTHON_VERSION=3.8
82+
export GPU_ARCH_TYPE=cpu
83+
84+
./.github/scripts/setup-env.sh
85+
86+
# Prepare conda
87+
CONDA_PATH=$(which conda)
88+
eval "$(${CONDA_PATH} shell.bash hook)"
89+
conda activate ci
90+
91+
echo '::group::Pre-download model weights'
92+
pip install --progress-bar=off aiohttp aiofiles tqdm
93+
python scripts/download_model_urls.py
94+
echo '::endgroup::'
95+
96+
echo '::group::Install testing utilities'
97+
pip install --progress-bar=off pytest
98+
echo '::endgroup::'
99+
100+
echo '::group::Run extended unittests'
101+
export PYTORCH_TEST_WITH_EXTENDED=1
102+
pytest --durations=25 -v test/test_extended_*.py
103+
echo '::endgroup::'

.github/workflows/test-macos.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Unit-tests on macOS
1+
name: Tests on macOS
22

33
on:
44
pull_request:
@@ -10,7 +10,7 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13-
tests:
13+
unittests:
1414
strategy:
1515
matrix:
1616
python-version:
@@ -31,7 +31,9 @@ jobs:
3131
timeout: 240
3232
runner: ${{ matrix.runner }}
3333
script: |
34+
set -euo pipefail
35+
3436
export PYTHON_VERSION=${{ matrix.python-version }}
3537
export GPU_ARCH_TYPE=cpu
3638
37-
./.github/unittest.sh
39+
./.github/scripts/unittest.sh

scripts/download_model_urls.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import asyncio
2+
import sys
3+
from pathlib import Path
4+
from time import perf_counter
5+
from urllib.parse import urlsplit
6+
7+
import aiofiles
8+
import aiohttp
9+
from torchvision import models
10+
from tqdm.asyncio import tqdm
11+
12+
13+
async def main(download_root):
14+
download_root.mkdir(parents=True, exist_ok=True)
15+
urls = {weight.url for name in models.list_models() for weight in iter(models.get_model_weights(name))}
16+
17+
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=None)) as session:
18+
await tqdm.gather(*[download(download_root, session, url) for url in urls])
19+
20+
21+
async def download(download_root, session, url):
22+
response = await session.get(url, params=dict(source="ci"))
23+
24+
assert response.ok
25+
26+
file_name = Path(urlsplit(url).path).name
27+
async with aiofiles.open(download_root / file_name, "wb") as f:
28+
async for data in response.content.iter_any():
29+
await f.write(data)
30+
31+
32+
if __name__ == "__main__":
33+
download_root = (
34+
(Path(sys.argv[1]) if len(sys.argv) > 1 else Path("~/.cache/torch/hub/checkpoints")).expanduser().resolve()
35+
)
36+
print(f"Downloading model weights to {download_root}")
37+
start = perf_counter()
38+
asyncio.get_event_loop().run_until_complete(main(download_root))
39+
stop = perf_counter()
40+
minutes, seconds = divmod(stop - start, 60)
41+
print(f"Download took {minutes:2.0f}m {seconds:2.0f}s")

0 commit comments

Comments
 (0)