Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

test(geometry): stop five tests from assuming CPU behaviour on CUDA (#6264)

Leonardo Vanni4f4c9d61ecdb
diff --git a/tests/geometry/subpix/test_spatial_softargmax.py b/tests/geometry/subpix/test_spatial_softargmax.py
index 7187e41b6..36ba6d6fb 100644
--- a/tests/geometry/subpix/test_spatial_softargmax.py
+++ b/tests/geometry/subpix/test_spatial_softargmax.py
@@ -847,7 +847,8 @@ class TestConvQuadInterp3dModule(BaseTester):
def test_gradcheck(self, device):
sample = torch.rand(1, 1, 3, 5, 5, device=device, dtype=torch.float64)
sample[0, 0, 1, 2, 2] += 20.0
- self.gradcheck(kornia.geometry.ConvQuadInterp3d(), (sample), atol=1e-3, rtol=1e-3)
+ # nondet_tol: CUDA's backward accumulates with atomics, so repeated backward passes differ by roundoff.
+ self.gradcheck(kornia.geometry.ConvQuadInterp3d(), (sample), atol=1e-3, rtol=1e-3, nondet_tol=1e-8)
def test_diag(self, device, dtype):
sample = torch.tensor(
@@ -1025,6 +1026,7 @@ class TestConvQuadInterp3d(BaseTester):
(sample,),
atol=1e-3,
rtol=1e-3,
+ nondet_tol=1e-8, # CUDA's backward accumulates with atomics, so repeated passes differ by roundoff
)
def test_dynamo(self, device, dtype, torch_optimizer):
diff --git a/tests/geometry/test_ransac.py b/tests/geometry/test_ransac.py
index d8e8e8a87..2b12fe9b8 100644
--- a/tests/geometry/test_ransac.py
+++ b/tests/geometry/test_ransac.py
@@ -3047,8 +3047,13 @@ class TestRANSACDegensac(BaseTester):
calls = []
original = ransac_module._plane_parallax_search
monkeypatch.setattr(ransac_module, "_plane_parallax_search", lambda *a: calls.append(1) or original(*a))
- # plane_fraction=0 puts every inlier at a random depth: no dominant plane.
- for seed in range(6):
+ # plane_fraction=0 puts every inlier at a random depth: no dominant plane. Which seeds draw an H-degenerate
+ # record setter depends on the device's generator and batch sizes, not only on the scene (#6263): CPU and CUDA
+ # fire on different seeds, and on some CUDA setups none of the first six does. So the first six seeds always
+ # run, further seeds run until a recovery has happened, and every seed that runs must keep the accuracy.
+ for seed in range(30):
+ if seed >= 6 and calls:
+ break
kp1, kp2, _, clean1, clean2 = create_dominant_plane_scene(1000, 0.6, 0.0, seed, device=device, dtype=dtype)
F, mask = RANSAC("fundamental", inl_th=1.0, seed=seed, degensac=True)(kp1, kp2)
F_plain, mask_plain = RANSAC("fundamental", inl_th=1.0, seed=seed, degensac=False)(kp1, kp2)
diff --git a/tests/geometry/transform/test_affine.py b/tests/geometry/transform/test_affine.py
index 36daa85ce..c6ff1d1ab 100644
--- a/tests/geometry/transform/test_affine.py
+++ b/tests/geometry/transform/test_affine.py
@@ -920,7 +920,8 @@ class TestScale(BaseTester):
def test_isotropic_scale_factor_gradcheck(self, device):
image = torch.arange(48, device=device, dtype=torch.float64).reshape(2, 1, 4, 6) / 48
scale_factor = torch.tensor([0.8, 1.3], device=device, dtype=torch.float64)
- self.gradcheck(kornia.geometry.transform.scale, (image, scale_factor))
+ # CUDA's grid_sample backward accumulates with atomics, so repeated backward passes differ by roundoff.
+ self.gradcheck(kornia.geometry.transform.scale, (image, scale_factor), nondet_tol=1e-8)
def test_gradcheck(self, device):
# test parameters