10
10
import torch
11
11
import torch .fx
12
12
import torch .nn .functional as F
13
+ import torch .testing ._internal .optests as optests
13
14
from common_utils import assert_equal , cpu_and_cuda , cpu_and_cuda_and_mps , needs_cuda , needs_mps
14
15
from PIL import Image
15
16
from torch import nn , Tensor
19
20
from torchvision .models .feature_extraction import get_graph_node_names
20
21
21
22
23
+ OPTESTS = [
24
+ "test_schema" ,
25
+ "test_autograd_registration" ,
26
+ "test_faketensor" ,
27
+ "test_aot_dispatch_dynamic" ,
28
+ ]
29
+
30
+
22
31
# Context manager for setting deterministic flag and automatically
23
32
# resetting it to its original value
24
33
class DeterministicGuard :
@@ -462,7 +471,7 @@ def test_boxes_shape(self):
462
471
463
472
@pytest .mark .parametrize ("aligned" , (True , False ))
464
473
@pytest .mark .parametrize ("device" , cpu_and_cuda_and_mps ())
465
- @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)
466
475
@pytest .mark .parametrize ("contiguous" , (True , False ))
467
476
@pytest .mark .parametrize ("deterministic" , (True , False ))
468
477
def test_forward (self , device , contiguous , deterministic , aligned , x_dtype , rois_dtype = None ):
@@ -712,6 +721,7 @@ def _create_tensors_with_iou(self, N, iou_thresh):
712
721
713
722
@pytest .mark .parametrize ("iou" , (0.2 , 0.5 , 0.8 ))
714
723
@pytest .mark .parametrize ("seed" , range (10 ))
724
+ @pytest .mark .opcheck_only_one ()
715
725
def test_nms_ref (self , iou , seed ):
716
726
torch .random .manual_seed (seed )
717
727
err_msg = "NMS incompatible between CPU and reference implementation for IoU={}"
@@ -732,6 +742,7 @@ def test_nms_input_errors(self):
732
742
733
743
@pytest .mark .parametrize ("iou" , (0.2 , 0.5 , 0.8 ))
734
744
@pytest .mark .parametrize ("scale, zero_point" , ((1 , 0 ), (2 , 50 ), (3 , 10 )))
745
+ @pytest .mark .opcheck_only_one ()
735
746
def test_qnms (self , iou , scale , zero_point ):
736
747
# Note: we compare qnms vs nms instead of qnms vs reference implementation.
737
748
# This is because with the int conversion, the trick used in _create_tensors_with_iou
@@ -759,6 +770,7 @@ def test_qnms(self, iou, scale, zero_point):
759
770
),
760
771
)
761
772
@pytest .mark .parametrize ("iou" , (0.2 , 0.5 , 0.8 ))
773
+ @pytest .mark .opcheck_only_one ()
762
774
def test_nms_gpu (self , iou , device , dtype = torch .float64 ):
763
775
dtype = torch .float32 if device == "mps" else dtype
764
776
tol = 1e-3 if dtype is torch .half else 1e-5
@@ -778,6 +790,7 @@ def test_nms_gpu(self, iou, device, dtype=torch.float64):
778
790
@needs_cuda
779
791
@pytest .mark .parametrize ("iou" , (0.2 , 0.5 , 0.8 ))
780
792
@pytest .mark .parametrize ("dtype" , (torch .float , torch .half ))
793
+ @pytest .mark .opcheck_only_one ()
781
794
def test_autocast (self , iou , dtype ):
782
795
with torch .cuda .amp .autocast ():
783
796
self .test_nms_gpu (iou = iou , dtype = dtype , device = "cuda" )
@@ -789,6 +802,7 @@ def test_autocast(self, iou, dtype):
789
802
pytest .param ("mps" , marks = pytest .mark .needs_mps ),
790
803
),
791
804
)
805
+ @pytest .mark .opcheck_only_one ()
792
806
def test_nms_float16 (self , device ):
793
807
boxes = torch .tensor (
794
808
[
@@ -805,6 +819,7 @@ def test_nms_float16(self, device):
805
819
assert_equal (keep32 , keep16 )
806
820
807
821
@pytest .mark .parametrize ("seed" , range (10 ))
822
+ @pytest .mark .opcheck_only_one ()
808
823
def test_batched_nms_implementations (self , seed ):
809
824
"""Make sure that both implementations of batched_nms yield identical results"""
810
825
torch .random .manual_seed (seed )
@@ -830,6 +845,15 @@ def test_batched_nms_implementations(self, seed):
830
845
torch .testing .assert_close (empty , ops .batched_nms (empty , None , None , None ))
831
846
832
847
848
+ optests .generate_opcheck_tests (
849
+ testcase = TestNMS ,
850
+ namespaces = ["torchvision" ],
851
+ failures_dict_path = os .path .join (os .path .dirname (__file__ ), "optests_failures_dict.json" ),
852
+ additional_decorators = [],
853
+ test_utils = OPTESTS ,
854
+ )
855
+
856
+
833
857
class TestDeformConv :
834
858
dtype = torch .float64
835
859
0 commit comments