2020from diffusers .utils .torch_utils import randn_tensor
2121
2222from ...testing_utils import enable_full_determinism , torch_device
23- from ..testing_utils import BaseModelTesterConfig , MemoryTesterMixin , ModelTesterMixin , TrainingTesterMixin
23+ from ..testing_utils import (
24+ BaseModelTesterConfig ,
25+ MemoryTesterMixin ,
26+ ModelTesterMixin ,
27+ TrainingTesterMixin ,
28+ run_nondeterministic ,
29+ )
2430from .testing_utils import NewAutoencoderTesterMixin
2531
2632
2733enable_full_determinism ()
2834
2935
30- def _run_nondeterministic (fn ):
31- # reflection_pad3d_backward_out_cuda has no deterministic CUDA implementation;
32- # temporarily relax the requirement for tests that do backward passes.
33- torch .use_deterministic_algorithms (False )
34- try :
35- fn ()
36- finally :
37- torch .use_deterministic_algorithms (True )
38-
39-
4036class AutoencoderKLKVAEVideoTesterConfig (BaseModelTesterConfig ):
4137 @property
4238 def model_class (self ):
@@ -91,14 +87,16 @@ def test_gradient_checkpointing_is_applied(self):
9187 expected_set = {"KVAECachedEncoder3D" , "KVAECachedDecoder3D" }
9288 super ().test_gradient_checkpointing_is_applied (expected_set = expected_set )
9389
90+ # reflection_pad3d_backward_out_cuda has no deterministic CUDA implementation, so every test with a backward
91+ # pass runs with determinism relaxed.
9492 def test_training (self ):
95- _run_nondeterministic (super ().test_training )
93+ run_nondeterministic (super ().test_training )
9694
9795 def test_training_with_ema (self ):
98- _run_nondeterministic (super ().test_training_with_ema )
96+ run_nondeterministic (super ().test_training_with_ema )
9997
10098 def test_mixed_precision_training (self ):
101- _run_nondeterministic (super ().test_mixed_precision_training )
99+ run_nondeterministic (super ().test_mixed_precision_training )
102100
103101 @pytest .mark .skip (
104102 "Gradient checkpointing recomputes the forward pass, but the model uses a stateful cache_dict "
@@ -112,8 +110,10 @@ def test_gradient_checkpointing_equivalence(self):
112110class TestAutoencoderKLKVAEVideoMemory (AutoencoderKLKVAEVideoTesterConfig , MemoryTesterMixin ):
113111 """Memory optimization tests for AutoencoderKLKVAEVideo."""
114112
113+ # reflection_pad3d_backward_out_cuda has no deterministic CUDA implementation, so every test with a backward
114+ # pass runs with determinism relaxed.
115115 def test_layerwise_casting_training (self ):
116- _run_nondeterministic (super ().test_layerwise_casting_training )
116+ run_nondeterministic (super ().test_layerwise_casting_training )
117117
118118
119119class TestAutoencoderKLKVAEVideoSlicingTiling (AutoencoderKLKVAEVideoTesterConfig , NewAutoencoderTesterMixin ):
0 commit comments