From 22a9b580030ecf9e6491c620a51c27efa3fb4cf9 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Thu, 9 Feb 2023 09:54:58 +0000 Subject: [PATCH 1/3] Test some flaky detection models on float64 instead of float32 --- test/test_models.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/test_models.py b/test/test_models.py index 5826cc77164..a1dd2d30091 100644 --- a/test/test_models.py +++ b/test/test_models.py @@ -278,6 +278,11 @@ def _check_input_backprop(model, inputs): # tests under test_quantized_classification_model will be skipped for the following models. quantized_flaky_models = ("inception_v3", "resnet50") +# The tests for the following detection models are flaky. +# We run those tests on float64 to avoid floating point errors. +# FIXME: we shouldn't have to do that :'/ +detection_flaky_models = ("keypointrcnn_resnet50_fpn", "maskrcnn_resnet50_fpn", "maskrcnn_resnet50_fpn_v2") + # The following contains configuration parameters for all models which are used by # the _test_*_model methods. @@ -777,13 +782,17 @@ def test_detection_model(model_fn, dev): "input_shape": (3, 300, 300), } model_name = model_fn.__name__ + if model_name in detection_flaky_models: + dtype = torch.float64 + else: + dtype = torch.get_default_dtype() kwargs = {**defaults, **_model_params.get(model_name, {})} input_shape = kwargs.pop("input_shape") real_image = kwargs.pop("real_image", False) model = model_fn(**kwargs) - model.eval().to(device=dev) - x = _get_image(input_shape=input_shape, real_image=real_image, device=dev) + model.eval().to(device=dev, dtype=dtype) + x = _get_image(input_shape=input_shape, real_image=real_image, device=dev).to(dtype) model_input = [x] with torch.no_grad(), freeze_rng_state(): out = model(model_input) From ef647df3529ad27459c48633d9b002f050f7c77a Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Thu, 9 Feb 2023 11:37:12 +0000 Subject: [PATCH 2/3] put dtype in _get_image --- test/test_models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_models.py b/test/test_models.py index a1dd2d30091..4b893a94c4f 100644 --- a/test/test_models.py +++ b/test/test_models.py @@ -29,7 +29,7 @@ def list_model_fns(module): return [get_model_builder(name) for name in list_models(module)] -def _get_image(input_shape, real_image, device): +def _get_image(input_shape, real_image, device, dtype=None): """This routine loads a real or random image based on `real_image` argument. Currently, the real image is utilized for the following list of models: - `retinanet_resnet50_fpn`, @@ -63,7 +63,7 @@ def _get_image(input_shape, real_image, device): return image.to(device=device) # RNG always on CPU, to ensure x in cuda tests is bitwise identical to x in cpu tests - return torch.rand(input_shape).to(device=device) + return torch.rand(input_shape).to(device=device, dtype=dtype) @pytest.fixture @@ -792,7 +792,7 @@ def test_detection_model(model_fn, dev): model = model_fn(**kwargs) model.eval().to(device=dev, dtype=dtype) - x = _get_image(input_shape=input_shape, real_image=real_image, device=dev).to(dtype) + x = _get_image(input_shape=input_shape, real_image=real_image, device=dev, dtype=dtype) model_input = [x] with torch.no_grad(), freeze_rng_state(): out = model(model_input) From 6258ac0b4bb8c7a2dfac40e3d5e2bde3430e1943 Mon Sep 17 00:00:00 2001 From: Nicolas Hug Date: Thu, 9 Feb 2023 12:15:14 +0000 Subject: [PATCH 3/3] Fix --- test/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_models.py b/test/test_models.py index 4b893a94c4f..abffe91aaeb 100644 --- a/test/test_models.py +++ b/test/test_models.py @@ -60,7 +60,7 @@ def _get_image(input_shape, real_image, device, dtype=None): convert_tensor = transforms.ToTensor() image = convert_tensor(img) assert tuple(image.size()) == input_shape - return image.to(device=device) + return image.to(device=device, dtype=dtype) # RNG always on CPU, to ensure x in cuda tests is bitwise identical to x in cpu tests return torch.rand(input_shape).to(device=device, dtype=dtype)