Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

test: make Sequential test_forward deterministic (#4449)

Ayush Srivastava156789a04a74
diff --git a/testing/half_precision_xfails/cpu_float16.txt b/testing/half_precision_xfails/cpu_float16.txt
index ad742f73b..c1ab96495 100644
--- a/testing/half_precision_xfails/cpu_float16.txt
+++ b/testing/half_precision_xfails/cpu_float16.txt
@@ -29,7 +29,7 @@ call builtins.AssertionError tests/augmentation/container/test_augmentation_sequ
call builtins.RuntimeError tests/augmentation/container/test_patch_sequential.py::TestPatchSequential::test_autocast[cpu-float16]
call builtins.AssertionError tests/augmentation/container/test_sequential_aug.py::TestSequential::test_forward[cpu-float16-10]
call builtins.AssertionError tests/augmentation/container/test_sequential_aug.py::TestSequential::test_forward[cpu-float16-False]
-call builtins.AssertionError tests/augmentation/container/test_sequential_aug.py::TestSequential::test_forward[cpu-float16-random_apply3]
+call builtins.AssertionError tests/augmentation/container/test_sequential_aug.py::TestSequential::test_forward[cpu-float16-True]
call builtins.AssertionError tests/augmentation/container/test_video_sequential.py::TestVideoSequential::test_against_sequential[cpu-float16-BCTHW-augmentations2]
call builtins.AssertionError tests/augmentation/container/test_video_sequential.py::TestVideoSequential::test_against_sequential[cpu-float16-BTCHW-augmentations2]
call builtins.RuntimeError tests/augmentation/container/test_video_sequential.py::TestVideoSequential::test_autocast[cpu-float16-BCTHW]
diff --git a/tests/augmentation/container/test_sequential_aug.py b/tests/augmentation/container/test_sequential_aug.py
index dd8ba77d7..64384dfd0 100644
--- a/tests/augmentation/container/test_sequential_aug.py
+++ b/tests/augmentation/container/test_sequential_aug.py
@@ -55,21 +55,23 @@ class TestSequential:
@pytest.mark.parametrize("random_apply", [1, (2, 2), (1, 2), (2,), 10, True, False])
def test_forward(self, random_apply, device, dtype):
- inp = torch.randn(1, 3, 30, 30, device=device, dtype=dtype)
- aug = K.ImageSequential(
- K.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=1.0),
- kornia.filters.MedianBlur((3, 3)),
- K.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=1.0),
- K.ImageSequential(K.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=1.0)),
- K.ImageSequential(K.RandomAffine(360, p=1.0)),
- K.RandomAffine(360, p=1.0),
- K.RandomMixUpV2(p=1.0),
- random_apply=random_apply,
- )
- out = aug(inp)
- assert out.shape == inp.shape
- aug.inverse(inp)
- reproducibility_test(inp, aug)
+ with torch.random.fork_rng():
+ torch.manual_seed(0)
+ inp = torch.randn(1, 3, 30, 30, device=device, dtype=dtype)
+ aug = K.ImageSequential(
+ K.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=1.0),
+ kornia.filters.MedianBlur((3, 3)),
+ K.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=1.0),
+ K.ImageSequential(K.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=1.0)),
+ K.ImageSequential(K.RandomAffine(360, p=1.0)),
+ K.RandomAffine(360, p=1.0),
+ K.RandomMixUpV2(p=1.0),
+ random_apply=random_apply,
+ )
+ out = aug(inp)
+ assert out.shape == inp.shape
+ aug.inverse(inp)
+ reproducibility_test(inp, aug)
@pytest.mark.usefixtures("restore_torch_rng")