π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
test(feature): give TestLAFAffNetShapeEstimator::test_toy a half-precision tolerance (#4220)
Dmytro Mishkin23735c3309bf
diff --git a/testing/half_precision_xfails/cpu_bfloat16.txt b/testing/half_precision_xfails/cpu_bfloat16.txtindex db5a9a9bc..34a3b27a8 100644--- a/testing/half_precision_xfails/cpu_bfloat16.txt+++ b/testing/half_precision_xfails/cpu_bfloat16.txt@@ -116,7 +116,6 @@ call builtins.AssertionError tests/contrib/test_hist_match.py::TestHistMatch::tecall builtins.AssertionError tests/core/test_helpers.py::TestSvdCast::test_smoke[cpu-bfloat16]call builtins.AssertionError tests/enhance/test_jpeg.py::TestDiffJPEG::test_cardinality[cpu-bfloat16]call builtins.AssertionError tests/enhance/test_zca.py::TestZCA::test_dim_args[cpu-bfloat16-1]-call builtins.AssertionError tests/feature/test_affine_shape_estimator.py::TestLAFAffNetShapeEstimator::test_toy[cpu-bfloat16]call builtins.AssertionError tests/feature/test_aliked.py::TestALIKED::test_descriptor_normalized[cpu-bfloat16]call builtins.NotImplementedError tests/feature/test_hynet.py::TestHyNet::test_jit[cpu-bfloat16]call builtins.AssertionError tests/feature/test_responces_local_features.py::TestBlobDoGSingle::test_blobs_batch[cpu-bfloat16]diff --git a/testing/half_precision_xfails/cpu_float16.txt b/testing/half_precision_xfails/cpu_float16.txtindex 706c9dcb1..91ea6ac13 100644--- a/testing/half_precision_xfails/cpu_float16.txt+++ b/testing/half_precision_xfails/cpu_float16.txt@@ -226,7 +226,6 @@ call builtins.AssertionError tests/augmentation/test_random_generator_3d.py::Tescall builtins.AssertionError tests/color/test_hls.py::TestRgbToHls::test_jit[cpu-float16]call builtins.AssertionError tests/color/test_hls.py::TestRgbToHls::test_module[cpu-float16]call builtins.AssertionError tests/color/test_rgb.py::TestRgb255Normals::test_back_and_forth[cpu-float16]-call builtins.AssertionError tests/feature/test_affine_shape_estimator.py::TestLAFAffNetShapeEstimator::test_toy[cpu-float16]call builtins.AssertionError tests/feature/test_aliked.py::TestALIKED::test_descriptor_normalized[cpu-float16]call builtins.NotImplementedError tests/feature/test_hynet.py::TestHyNet::test_jit[cpu-float16]call builtins.AssertionError tests/feature/test_responces_local_features.py::TestBlobDoGSingle::test_blobs_batch[cpu-float16]diff --git a/tests/feature/test_affine_shape_estimator.py b/tests/feature/test_affine_shape_estimator.pyindex 3d44fc419..fdaecd83a 100644--- a/tests/feature/test_affine_shape_estimator.py+++ b/tests/feature/test_affine_shape_estimator.py@@ -345,8 +345,17 @@ class TestLAFAffNetShapeEstimator(BaseTester):laf = torch.tensor([[[[20.0, 0.0, 16.0], [0.0, 20.0, 16.0]]]], device=device, dtype=dtype)new_laf = aff(laf, inp)expected = torch.tensor([[[[33.2073, 0.0, 16.0], [-1.3766, 12.0456, 16.0]]]], device=device, dtype=dtype)- atol = 5e-3 if (device.type == "cuda" and dtype == torch.float32) else 1e-4- self.assert_close(new_laf, expected, atol=atol, rtol=1e-4)+ if dtype in (torch.float16, torch.bfloat16):+ # AffNet's convolutions carry reduced-precision noise proportional to the LAF's own scale+ # (~33 px), not to each entry's magnitude, so the small a21 entry (-1.38) cannot be held to a+ # relative bound: it misses by 0.024 (float16) and 0.031 (bfloat16), bitwise identical on+ # torch 2.9.1 and 2.14.0. The 1e-1 bound is ~3 float16 ULP at that scale, so it is set by the+ # dtype rather than by the observed miss and does not need re-tuning per platform. It still+ # discriminates: a genuine shape regression moves these entries by O(1).+ self.assert_close(new_laf, expected, atol=1e-1, rtol=1e-3 if dtype == torch.float16 else 7.8e-3)+ else:+ atol = 5e-3 if (device.type == "cuda" and dtype == torch.float32) else 1e-4+ self.assert_close(new_laf, expected, atol=atol, rtol=1e-4)@pytest.mark.slowdef test_gradcheck(self, device):