Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
57ad254
enable caching of model weights for prototype CI
pmeier Oct 28, 2021
54e88ca
syntax
pmeier Oct 28, 2021
603f615
syntax
pmeier Oct 28, 2021
35a7a46
make cache dir dynamic
pmeier Oct 28, 2021
df386b9
increase verbosity
pmeier Oct 28, 2021
96b7411
fix
pmeier Oct 28, 2021
adf0c24
use larget CI machine
pmeier Oct 28, 2021
0fc0bdd
revert debug output
pmeier Oct 28, 2021
b9335aa
[DEBUG] test env var usage in save_cache
pmeier Oct 28, 2021
7bebe1a
retry
pmeier Oct 28, 2021
a134e03
use checksum for caching
pmeier Oct 28, 2021
c6bdeea
remove env vars because expansion is not working
pmeier Oct 28, 2021
f443f2a
syntax
pmeier Oct 28, 2021
d497f21
cleanup
pmeier Oct 28, 2021
4a9f1c1
base caching on model-urls
pmeier Oct 28, 2021
bd4c84d
relax regex
pmeier Oct 28, 2021
b5bf51a
cleanup skips
pmeier Oct 28, 2021
b030fdd
Merge branch 'main' into cache-model-weights
pmeier Oct 28, 2021
fe4537b
cleanup
pmeier Oct 28, 2021
0e76cf9
fix skipping logic
pmeier Oct 28, 2021
7c652b7
improve step name
pmeier Oct 28, 2021
a1086b7
benchmark without caching
pmeier Oct 28, 2021
9d2bb9c
benchmark with external download
pmeier Oct 29, 2021
0a7d1f6
debug
pmeier Oct 29, 2021
a6f0eb1
fix manual download location
pmeier Oct 29, 2021
cfe4a71
debug again
pmeier Oct 29, 2021
df2097a
download weights in the background
pmeier Nov 26, 2021
ff3d39b
Merge branch 'main' into cache-model-weights
pmeier Nov 26, 2021
789446e
try parallel download
pmeier Nov 26, 2021
3d1eac3
add missing import
pmeier Nov 26, 2021
ef21703
use correct decoractor
pmeier Nov 26, 2021
037aeb1
up resource_class
pmeier Nov 26, 2021
70b09b0
fix wording
pmeier Nov 26, 2021
a45f56d
enable stdout passthrough to see download during test
pmeier Nov 26, 2021
a9eb425
remove linebreak
pmeier Nov 26, 2021
0c81611
move checkout up
pmeier Nov 26, 2021
8b1ebaf
cleanup
pmeier Nov 26, 2021
133933e
debug failing test
pmeier Nov 26, 2021
60b2716
temp fix
pmeier Nov 26, 2021
0a247d4
fix
pmeier Nov 26, 2021
7ed8fe3
cleanup
pmeier Nov 26, 2021
a2f9758
fix regex
pmeier Nov 26, 2021
fe3e128
Merge branch 'main' into cache-model-weights
pmeier Nov 26, 2021
31f26a6
remove explicit install of numpy
pmeier Nov 26, 2021
4f3ddb1
Merge branch 'main' into cache-model-weights
pmeier Nov 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .circleci/config.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion .circleci/config.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,23 @@ jobs:
prototype_test:
docker:
- image: circleci/python:3.7
resource_class: xlarge
steps:
- run:
name: Install torch
command: pip install --user --progress-bar=off --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
command: |
pip install --user --progress-bar=off --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
- run:
name: Install prototype dependencies
command: pip install --user --progress-bar=off git+https://github.com/pytorch/data.git
- checkout
- run:
name: Download model weights
background: true
command: |
sudo apt update -qy && sudo apt install -qy parallel wget
python scripts/collect_model_urls.py torchvision/prototype/models \
| parallel -j0 wget --no-verbose -P ~/.cache/torch/hub/checkpoints {}
- run:
name: Install torchvision
command: pip install --user --progress-bar off --no-build-isolation .
Expand All @@ -279,6 +288,8 @@ jobs:
command: pip install --user --progress-bar=off pytest pytest-mock scipy iopath
- run:
name: Run tests
environment:
PYTORCH_TEST_WITH_PROTOTYPE: 1
command: pytest --junitxml=test-results/junit.xml -v --durations 20 test/test_prototype_*.py
- store_test_results:
path: test-results
Expand Down
22 changes: 22 additions & 0 deletions scripts/collect_model_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pathlib
import re
import sys

MODEL_URL_PATTERN = re.compile(r"https://download[.]pytorch[.]org/models/.*?[.]pth")


def main(root):
model_urls = set()
for path in pathlib.Path(root).glob("**/*"):
if path.name.startswith("_") or not path.suffix == ".py":
continue

with open(path, "r") as file:
for line in file:
model_urls.update(MODEL_URL_PATTERN.findall(line))

print("\n".join(sorted(model_urls)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach is a bit hacky, though admittedly you can't do much else prior compiling torchvision. If TorchVision was compiled, we could rely on the upcoming registration mechanism to get all available models and weights and then fetch their URLs. Since this is not possible for speed reasons, we might be forced to do something like that. The good thing is even if this fails, we will download the weights properly one-by-one later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing how fast the download is, we could also do it in the foreground after the installation. Still much faster than downloading sequentially during the tests. Both variants are fine by me. You pick.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13 seconds sounds pretty good to me. It's your call. I don't mind either way.



if __name__ == "__main__":
main(sys.argv[1])
21 changes: 18 additions & 3 deletions test/common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@
import random
import shutil
import tempfile
from distutils.util import strtobool

import numpy as np
import pytest
import torch
from PIL import Image
from torchvision import io

import __main__ # noqa: 401


IN_CIRCLE_CI = os.getenv("CIRCLECI", False) == "true"
IN_RE_WORKER = os.environ.get("INSIDE_RE_WORKER") is not None
IN_FBCODE = os.environ.get("IN_FBCODE_TORCHVISION") == "1"
def get_bool_env_var(name, *, exist_ok=False, default=False):
value = os.getenv(name)
if value is None:
return default
if exist_ok:
return True
return bool(strtobool(value))


IN_CIRCLE_CI = get_bool_env_var("CIRCLECI")
IN_RE_WORKER = get_bool_env_var("INSIDE_RE_WORKER", exist_ok=True)
IN_FBCODE = get_bool_env_var("IN_FBCODE_TORCHVISION")
CUDA_NOT_AVAILABLE_MSG = "CUDA device not available"
CIRCLECI_GPU_NO_CUDA_MSG = "We're in a CircleCI GPU machine, and this test doesn't need cuda."

Expand Down Expand Up @@ -202,3 +213,7 @@ def _test_fn_on_batch(batch_tensors, fn, scripted_fn_atol=1e-8, **fn_kwargs):
# scriptable function test
s_transformed_batch = scripted_fn(batch_tensors, **fn_kwargs)
torch.testing.assert_close(transformed_batch, s_transformed_batch, rtol=1e-5, atol=scripted_fn_atol)


def run_on_env_var(name, *, skip_reason=None, exist_ok=False, default=False):
return pytest.mark.skipif(not get_bool_env_var(name, exist_ok=exist_ok, default=default), reason=skip_reason)
20 changes: 12 additions & 8 deletions test/test_prototype_models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import importlib
import os

import pytest
import test_models as TM
import torch
from common_utils import cpu_and_gpu
from common_utils import cpu_and_gpu, run_on_env_var
from torchvision.prototype import models

run_if_test_with_prototype = run_on_env_var(
"PYTORCH_TEST_WITH_PROTOTYPE",
skip_reason="Prototype tests are disabled by default. Set PYTORCH_TEST_WITH_PROTOTYPE=1 to run them.",
)


def _get_original_model(model_fn):
original_module_name = model_fn.__module__.replace(".prototype", "")
Expand Down Expand Up @@ -48,34 +52,34 @@ def test_get_weight(model_fn, name, weight):

@pytest.mark.parametrize("model_fn", TM.get_models_from_module(models))
@pytest.mark.parametrize("dev", cpu_and_gpu())
@pytest.mark.skipif(os.getenv("PYTORCH_TEST_WITH_PROTOTYPE", "0") == "0", reason="Prototype code tests are disabled")
@run_if_test_with_prototype
def test_classification_model(model_fn, dev):
TM.test_classification_model(model_fn, dev)


@pytest.mark.parametrize("model_fn", TM.get_models_from_module(models.detection))
@pytest.mark.parametrize("dev", cpu_and_gpu())
@pytest.mark.skipif(os.getenv("PYTORCH_TEST_WITH_PROTOTYPE", "0") == "0", reason="Prototype code tests are disabled")
@run_if_test_with_prototype
def test_detection_model(model_fn, dev):
TM.test_detection_model(model_fn, dev)


@pytest.mark.parametrize("model_fn", TM.get_models_from_module(models.quantization))
@pytest.mark.skipif(os.getenv("PYTORCH_TEST_WITH_PROTOTYPE", "0") == "0", reason="Prototype code tests are disabled")
@run_if_test_with_prototype
def test_quantized_classification_model(model_fn):
TM.test_quantized_classification_model(model_fn)


@pytest.mark.parametrize("model_fn", TM.get_models_from_module(models.segmentation))
@pytest.mark.parametrize("dev", cpu_and_gpu())
@pytest.mark.skipif(os.getenv("PYTORCH_TEST_WITH_PROTOTYPE", "0") == "0", reason="Prototype code tests are disabled")
@run_if_test_with_prototype
def test_segmentation_model(model_fn, dev):
TM.test_segmentation_model(model_fn, dev)


@pytest.mark.parametrize("model_fn", TM.get_models_from_module(models.video))
@pytest.mark.parametrize("dev", cpu_and_gpu())
@pytest.mark.skipif(os.getenv("PYTORCH_TEST_WITH_PROTOTYPE", "0") == "0", reason="Prototype code tests are disabled")
@run_if_test_with_prototype
def test_video_model(model_fn, dev):
TM.test_video_model(model_fn, dev)

Expand All @@ -89,7 +93,7 @@ def test_video_model(model_fn, dev):
+ get_models_with_module_names(models.video),
)
@pytest.mark.parametrize("dev", cpu_and_gpu())
@pytest.mark.skipif(os.getenv("PYTORCH_TEST_WITH_PROTOTYPE", "0") == "0", reason="Prototype code tests are disabled")
@run_if_test_with_prototype
def test_old_vs_new_factory(model_fn, module_name, dev):
defaults = {
"models": {
Expand Down