From 5e3f8fff40604ed2332e9f07b3796b15b43b91bb Mon Sep 17 00:00:00 2001 From: Patrick von Platen Date: Thu, 22 Jun 2023 13:53:27 +0200 Subject: [PATCH] Fix some audio tests (#3841) * Fix some audio tests * make style * fix * make style --- tests/pipelines/audioldm/test_audioldm.py | 10 ++++++++-- tests/pipelines/test_pipelines_common.py | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/pipelines/audioldm/test_audioldm.py b/tests/pipelines/audioldm/test_audioldm.py index 0825fc36a2..1c0e1e2d9a 100644 --- a/tests/pipelines/audioldm/test_audioldm.py +++ b/tests/pipelines/audioldm/test_audioldm.py @@ -36,7 +36,7 @@ from diffusers import ( PNDMScheduler, UNet2DConditionModel, ) -from diffusers.utils import slow, torch_device +from diffusers.utils import is_xformers_available, slow, torch_device from diffusers.utils.testing_utils import enable_full_determinism from ..pipeline_params import TEXT_TO_AUDIO_BATCH_PARAMS, TEXT_TO_AUDIO_PARAMS @@ -361,9 +361,15 @@ class AudioLDMPipelineFastTests(PipelineTesterMixin, unittest.TestCase): def test_inference_batch_single_identical(self): self._test_inference_batch_single_identical(test_mean_pixel_difference=False) + @unittest.skipIf( + torch_device != "cuda" or not is_xformers_available(), + reason="XFormers attention is only available with CUDA and `xformers` installed", + ) + def test_xformers_attention_forwardGenerator_pass(self): + self._test_xformers_attention_forwardGenerator_pass(test_mean_pixel_difference=False) + @slow -# @require_torch_gpu class AudioLDMPipelineSlowTests(unittest.TestCase): def tearDown(self): super().tearDown() diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index fac04bdbe3..008a8a2e63 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -640,7 +640,9 @@ class PipelineTesterMixin: def test_xformers_attention_forwardGenerator_pass(self): self._test_xformers_attention_forwardGenerator_pass() - def _test_xformers_attention_forwardGenerator_pass(self, test_max_difference=True, expected_max_diff=1e-4): + def _test_xformers_attention_forwardGenerator_pass( + self, test_max_difference=True, test_mean_pixel_difference=True, expected_max_diff=1e-4 + ): if not self.test_xformers_attention: return @@ -660,7 +662,8 @@ class PipelineTesterMixin: max_diff = np.abs(output_with_offload - output_without_offload).max() self.assertLess(max_diff, expected_max_diff, "XFormers attention should not affect the inference results") - assert_mean_pixel_difference(output_with_offload[0], output_without_offload[0]) + if test_mean_pixel_difference: + assert_mean_pixel_difference(output_with_offload[0], output_without_offload[0]) def test_progress_bar(self): components = self.get_dummy_components()