Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

test(geometry): Restore CUDA Affine coverage (#5530)

A Aswanth Raj622ae4767b67
diff --git a/testing/half_precision_xfails/cpu_bfloat16.txt b/testing/half_precision_xfails/cpu_bfloat16.txt
index 1e6f72dee..eb46d8d69 100644
--- a/testing/half_precision_xfails/cpu_bfloat16.txt
+++ b/testing/half_precision_xfails/cpu_bfloat16.txt
@@ -352,7 +352,6 @@ call builtins.AssertionError tests/geometry/test_quaternion.py::TestQuaternion::
call builtins.AssertionError tests/geometry/test_quaternion.py::TestQuaternionAverage::test_single_quaternion_returns_itself[cpu-bfloat16]
call builtins.NotImplementedError tests/geometry/test_ransac.py::TestRANSACEssential::test_forward_enforces_essential_constraint[cpu-bfloat16]
call builtins.NotImplementedError tests/geometry/test_ransac.py::TestRANSACEssential::test_polish_enforces_essential_constraint[cpu-bfloat16]
-call builtins.AssertionError tests/geometry/transform/test_affine.py::TestAffine2d::test_affine_rotate_translate[cpu-bfloat16]
call builtins.AssertionError tests/geometry/transform/test_affine.py::TestRescale::test_downscale_values[cpu-bfloat16]
call builtins.AssertionError tests/geometry/transform/test_affine.py::TestRescale::test_downscale_values_AA[cpu-bfloat16]
call builtins.AssertionError tests/geometry/transform/test_affine.py::TestRotate::test_angle90[cpu-bfloat16]
diff --git a/testing/half_precision_xfails/cpu_float16.txt b/testing/half_precision_xfails/cpu_float16.txt
index 70feac699..5b8115354 100644
--- a/testing/half_precision_xfails/cpu_float16.txt
+++ b/testing/half_precision_xfails/cpu_float16.txt
@@ -235,7 +235,6 @@ call builtins.AssertionError tests/geometry/test_quaternion.py::TestQuaternion::
call builtins.AssertionError tests/geometry/test_quaternion.py::TestQuaternion::test_to_axis_angle[cpu-float16-None]
call builtins.NotImplementedError tests/geometry/test_ransac.py::TestRANSACEssential::test_forward_enforces_essential_constraint[cpu-float16]
call builtins.NotImplementedError tests/geometry/test_ransac.py::TestRANSACEssential::test_polish_enforces_essential_constraint[cpu-float16]
-call builtins.AssertionError tests/geometry/transform/test_affine.py::TestAffine2d::test_affine_rotate_translate[cpu-float16]
call builtins.AssertionError tests/geometry/transform/test_affine.py::TestRotate::test_angle90[cpu-float16]
call builtins.AssertionError tests/geometry/transform/test_affine.py::TestRotate::test_angle90_batch2[cpu-float16]
call builtins.AssertionError tests/geometry/transform/test_affine.py::TestRotate::test_angle90_batch2_broadcast[cpu-float16]
diff --git a/tests/geometry/transform/test_affine.py b/tests/geometry/transform/test_affine.py
index 6c5dad7a0..221b472fc 100644
--- a/tests/geometry/transform/test_affine.py
+++ b/tests/geometry/transform/test_affine.py
@@ -720,9 +720,6 @@ class TestAffine2d(BaseTester):
kornia.geometry.transform.Affine(angle, translation)
def test_affine_rotate(self, device, dtype):
- # TODO: Remove when #666 is implemented
- if device.type == "cuda":
- pytest.skip("Currently breaks in CUDA.See https://github.com/kornia/kornia/issues/666")
torch.manual_seed(0)
angle = torch.rand(1, device=device, dtype=dtype) * 90.0
input = torch.rand(1, 2, 3, 4, device=device, dtype=dtype)
@@ -733,9 +730,6 @@ class TestAffine2d(BaseTester):
self.assert_close(actual, expected, atol=1e-4, rtol=1e-4)
def test_affine_translate(self, device, dtype):
- # TODO: Remove when #666 is implemented
- if device.type == "cuda":
- pytest.skip("Currently breaks in CUDA.See https://github.com/kornia/kornia/issues/666")
torch.manual_seed(0)
translation = torch.rand(1, 2, device=device, dtype=dtype) * 2.0
input = torch.rand(1, 2, 3, 4, device=device, dtype=dtype)
@@ -746,9 +740,6 @@ class TestAffine2d(BaseTester):
self.assert_close(actual, expected, atol=1e-4, rtol=1e-4)
def test_affine_scale(self, device, dtype):
- # TODO: Remove when #666 is implemented
- if device.type == "cuda":
- pytest.skip("Currently breaks in CUDA.See https://github.com/kornia/kornia/issues/666")
torch.manual_seed(0)
_scale_factor = torch.rand(1, device=device, dtype=dtype) * 2.0
scale_factor = torch.stack([_scale_factor, _scale_factor], dim=1)
@@ -774,9 +765,6 @@ class TestAffine2d(BaseTester):
self.assert_close(actual, expected, atol=1e-4, rtol=1e-4)
def test_affine_rotate_translate(self, device, dtype):
- # TODO: Remove when #666 is implemented
- if device.type == "cuda":
- pytest.skip("Currently breaks in CUDA.See https://github.com/kornia/kornia/issues/666")
batch_size = 2
input = torch.tensor(
@@ -798,7 +786,10 @@ class TestAffine2d(BaseTester):
device=device, dtype=dtype
)
actual = transform(input)
- self.assert_close(actual, expected, atol=1e-4, rtol=1e-4)
+ # The half dtypes round the 180-degree rotation and the bilinear weights: the output is off by up to 3.9e-3
+ # in float16 and 2.3e-2 in bfloat16 on CPU and CUDA, against 1.0 for a dropped translation.
+ tol = {torch.float16: 1e-2, torch.bfloat16: 5e-2}.get(dtype, 1e-4)
+ self.assert_close(actual, expected, atol=tol, rtol=tol)
def test_compose_affine_matrix_3x3(self, device, dtype):
"""To get parameters: