Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

fix: resolve two CI failures in coverage workflow (#3639)

Dmytro Mishkinbf56558aed4f
diff --git a/tests/augmentation/test_augmentation.py b/tests/augmentation/test_augmentation.py
index 1173f908a..7ccf30de0 100644
--- a/tests/augmentation/test_augmentation.py
+++ b/tests/augmentation/test_augmentation.py
@@ -5302,3 +5302,24 @@ class TestRandomThinPlateSpline(CommonTests):
diffs = [(params["dst"][0] - params["dst"][j]).abs().sum().item() for j in range(1, 4)]
assert any(d > 0 for d in diffs)
+
+ @pytest.mark.slow
+ def _test_gradcheck_implementation(self, params):
+ # RandomThinPlateSpline generates fresh random control points on every forward call,
+ # which makes the standard gradcheck non-deterministic (numerical Jacobian sees a
+ # different warp each perturbation step). Fix the params from a single forward pass
+ # so that gradcheck only tests gradient flow through the deterministic warp path.
+ # fork_rng saves/restores CPU RNG state so this seed doesn't affect other tests.
+ # (generate_parameters uses rsample on CPU then .to(device), so CPU RNG governs both
+ # input_tensor and the TPS control-point sampling.)
+ aug = self._create_augmentation_from_params(**params, p=1.0)
+ with torch.random.fork_rng():
+ torch.manual_seed(0)
+ input_tensor = torch.rand((1, 3, 5, 5), device=self.device, dtype=self.dtype)
+ _ = aug(input_tensor)
+ fixed_params = aug._params
+
+ def forward_with_fixed_params(x: torch.Tensor) -> torch.Tensor:
+ return aug(x, params=fixed_params)
+
+ self.gradcheck(forward_with_fixed_params, (input_tensor,))
diff --git a/tests/losses/test_mutual_information.py b/tests/losses/test_mutual_information.py
index 5a07fa6bd..93cb01d18 100644
--- a/tests/losses/test_mutual_information.py
+++ b/tests/losses/test_mutual_information.py
@@ -207,9 +207,9 @@ class TestMutualInformationLoss(BaseTester):
op = mutual_information_loss
op_optimized = torch_optimizer(op)
- self.assert_close(op(*args), op_optimized(*args))
+ self.assert_close(op(*args), op_optimized(*args), low_tolerance=True)
op = normalized_mutual_information_loss
op_optimized = torch_optimizer(op)
- self.assert_close(op(*args), op_optimized(*args))
+ self.assert_close(op(*args), op_optimized(*args), low_tolerance=True)