Skip to content

Commit 71c397e

Browse files
committed
Cleanup, fix call, add TestRoiAlign, add json file
1 parent 0eb13d2 commit 71c397e

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

pytest.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@ addopts =
1111
testpaths =
1212
test
1313
xfail_strict = True
14-
markers =
15-
opcheck_only_one: only opcheck one parametrization

test/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def pytest_configure(config):
1919
config.addinivalue_line("markers", "needs_cuda: mark for tests that rely on a CUDA device")
2020
config.addinivalue_line("markers", "needs_mps: mark for tests that rely on a MPS device")
2121
config.addinivalue_line("markers", "dont_collect: mark for tests that should not be collected")
22+
config.addinivalue_line("markers", "opcheck_only_one: only opcheck one parametrization")
2223

2324

2425
def pytest_collection_modifyitems(items):

test/test_ops.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from functools import lru_cache
55
from itertools import product
66
from typing import Callable, List, Tuple
7-
import unittest
87

98
import numpy as np
109
import pytest
@@ -21,6 +20,14 @@
2120
from torchvision.models.feature_extraction import get_graph_node_names
2221

2322

23+
OPTESTS = [
24+
"test_schema",
25+
"test_autograd_registration",
26+
"test_faketensor",
27+
"test_aot_dispatch_dynamic",
28+
]
29+
30+
2431
# Context manager for setting deterministic flag and automatically
2532
# resetting it to its original value
2633
class DeterministicGuard:
@@ -464,9 +471,10 @@ def test_boxes_shape(self):
464471

465472
@pytest.mark.parametrize("aligned", (True, False))
466473
@pytest.mark.parametrize("device", cpu_and_cuda_and_mps())
467-
@pytest.mark.parametrize("x_dtype", (torch.float16, torch.float32, torch.float64), ids=str)
474+
@pytest.mark.parametrize("x_dtype", (torch.float16, torch.float32, torch.float64)) # , ids=str)
468475
@pytest.mark.parametrize("contiguous", (True, False))
469476
@pytest.mark.parametrize("deterministic", (True, False))
477+
@pytest.mark.opcheck_only_one()
470478
def test_forward(self, device, contiguous, deterministic, aligned, x_dtype, rois_dtype=None):
471479
if deterministic and device == "cpu":
472480
pytest.skip("cpu is always deterministic, don't retest")
@@ -484,6 +492,7 @@ def test_forward(self, device, contiguous, deterministic, aligned, x_dtype, rois
484492
@pytest.mark.parametrize("deterministic", (True, False))
485493
@pytest.mark.parametrize("x_dtype", (torch.float, torch.half))
486494
@pytest.mark.parametrize("rois_dtype", (torch.float, torch.half))
495+
@pytest.mark.opcheck_only_one()
487496
def test_autocast(self, aligned, deterministic, x_dtype, rois_dtype):
488497
with torch.cuda.amp.autocast():
489498
self.test_forward(
@@ -499,6 +508,7 @@ def test_autocast(self, aligned, deterministic, x_dtype, rois_dtype):
499508
@pytest.mark.parametrize("device", cpu_and_cuda_and_mps())
500509
@pytest.mark.parametrize("contiguous", (True, False))
501510
@pytest.mark.parametrize("deterministic", (True, False))
511+
@pytest.mark.opcheck_only_one()
502512
def test_backward(self, seed, device, contiguous, deterministic):
503513
if deterministic and device == "cpu":
504514
pytest.skip("cpu is always deterministic, don't retest")
@@ -513,6 +523,7 @@ def _make_rois(self, img_size, num_imgs, dtype, num_rois=1000):
513523
@pytest.mark.parametrize("aligned", (True, False))
514524
@pytest.mark.parametrize("scale, zero_point", ((1, 0), (2, 10), (0.1, 50)))
515525
@pytest.mark.parametrize("qdtype", (torch.qint8, torch.quint8, torch.qint32))
526+
@pytest.mark.opcheck_only_one()
516527
def test_qroialign(self, aligned, scale, zero_point, qdtype):
517528
"""Make sure quantized version of RoIAlign is close to float version"""
518529
pool_size = 5
@@ -582,6 +593,15 @@ def test_jit_boxes_list(self):
582593
self._helper_jit_boxes_list(model)
583594

584595

596+
optests.generate_opcheck_tests(
597+
testcase=TestRoIAlign,
598+
namespaces=["torchvision"],
599+
failures_dict_path="test/optests_failures_dict.json",
600+
additional_decorators=[],
601+
test_utils=OPTESTS,
602+
)
603+
604+
585605
class TestPSRoIAlign(RoIOpTester):
586606
mps_backward_atol = 5e-2
587607

@@ -837,20 +857,13 @@ def test_batched_nms_implementations(self, seed):
837857
empty = torch.empty((0,), dtype=torch.int64)
838858
torch.testing.assert_close(empty, ops.batched_nms(empty, None, None, None))
839859

840-
data_dependent_torchvision_test_checks = [
841-
"test_schema",
842-
"test_autograd_registration",
843-
"test_faketensor",
844-
"test_aot_dispatch_dynamic",
845-
]
846860

847861
optests.generate_opcheck_tests(
848-
TestNMS,
849-
["torchvision"],
850-
{},
851-
"test/test_ops.py",
852-
[],
853-
data_dependent_torchvision_test_checks,
862+
testcase=TestNMS,
863+
namespaces=["torchvision"],
864+
failures_dict_path="test/optests_failures_dict.json",
865+
additional_decorators=[],
866+
test_utils=OPTESTS,
854867
)
855868

856869

0 commit comments

Comments
 (0)