From c346ad5eb865136ae2cd311dc08046de6f381d6a Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Mon, 30 Mar 2026 15:30:18 +0530 Subject: [PATCH 1/3] refactor autoencoderdc tests --- .../test_models_autoencoder_dc.py | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/tests/models/autoencoders/test_models_autoencoder_dc.py b/tests/models/autoencoders/test_models_autoencoder_dc.py index b1b5531d0134..40923b004b73 100644 --- a/tests/models/autoencoders/test_models_autoencoder_dc.py +++ b/tests/models/autoencoders/test_models_autoencoder_dc.py @@ -13,24 +13,28 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest +import pytest from diffusers import AutoencoderDC from ...testing_utils import IS_GITHUB_ACTIONS, enable_full_determinism, floats_tensor, torch_device -from ..test_modeling_common import ModelTesterMixin +from ..testing_utils import BaseModelTesterConfig, MemoryTesterMixin, ModelTesterMixin, TrainingTesterMixin from .testing_utils import AutoencoderTesterMixin enable_full_determinism() -class AutoencoderDCTests(ModelTesterMixin, AutoencoderTesterMixin, unittest.TestCase): - model_class = AutoencoderDC - main_input_name = "sample" - base_precision = 1e-2 +class AutoencoderDCTesterConfig(BaseModelTesterConfig): + @property + def model_class(self): + return AutoencoderDC + + @property + def output_shape(self): + return (3, 32, 32) - def get_autoencoder_dc_config(self): + def get_init_dict(self): return { "in_channels": 3, "latent_channels": 4, @@ -56,33 +60,33 @@ def get_autoencoder_dc_config(self): "scaling_factor": 0.41407, } - @property - def dummy_input(self): + def get_dummy_inputs(self): batch_size = 4 num_channels = 3 sizes = (32, 32) - image = floats_tensor((batch_size, num_channels) + sizes).to(torch_device) - return {"sample": image} - @property - def input_shape(self): - return (3, 32, 32) + # Bridge for AutoencoderTesterMixin which still uses the old interface + def prepare_init_args_and_inputs_for_common(self): + return self.get_init_dict(), self.get_dummy_inputs() - @property - def output_shape(self): - return (3, 32, 32) - def prepare_init_args_and_inputs_for_common(self): - init_dict = self.get_autoencoder_dc_config() - inputs_dict = self.dummy_input - return init_dict, inputs_dict +class TestAutoencoderDC(AutoencoderDCTesterConfig, ModelTesterMixin): + base_precision = 1e-2 - @unittest.skipIf(IS_GITHUB_ACTIONS, reason="Skipping test inside GitHub Actions environment") - def test_layerwise_casting_inference(self): - super().test_layerwise_casting_inference() - @unittest.skipIf(IS_GITHUB_ACTIONS, reason="Skipping test inside GitHub Actions environment") +class TestAutoencoderDCTraining(AutoencoderDCTesterConfig, TrainingTesterMixin): + """Training tests for AutoencoderDC.""" + + +class TestAutoencoderDCMemory(AutoencoderDCTesterConfig, MemoryTesterMixin): + """Memory optimization tests for AutoencoderDC.""" + + @pytest.mark.skipif(IS_GITHUB_ACTIONS, reason="Skipping test inside GitHub Actions environment") def test_layerwise_casting_memory(self): super().test_layerwise_casting_memory() + + +class TestAutoencoderDCSlicingTiling(AutoencoderDCTesterConfig, AutoencoderTesterMixin): + """Slicing and tiling tests for AutoencoderDC.""" From 119daffdf17c45dbdd64ff204f54be911c0f29ae Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Mon, 30 Mar 2026 16:05:22 +0530 Subject: [PATCH 2/3] fix --- tests/models/autoencoders/test_models_autoencoder_dc.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/models/autoencoders/test_models_autoencoder_dc.py b/tests/models/autoencoders/test_models_autoencoder_dc.py index 40923b004b73..bf850bd050d4 100644 --- a/tests/models/autoencoders/test_models_autoencoder_dc.py +++ b/tests/models/autoencoders/test_models_autoencoder_dc.py @@ -14,10 +14,11 @@ # limitations under the License. import pytest +import torch from diffusers import AutoencoderDC -from ...testing_utils import IS_GITHUB_ACTIONS, enable_full_determinism, floats_tensor, torch_device +from ...testing_utils import IS_GITHUB_ACTIONS, enable_full_determinism, torch_device from ..testing_utils import BaseModelTesterConfig, MemoryTesterMixin, ModelTesterMixin, TrainingTesterMixin from .testing_utils import AutoencoderTesterMixin @@ -60,11 +61,12 @@ def get_init_dict(self): "scaling_factor": 0.41407, } - def get_dummy_inputs(self): + def get_dummy_inputs(self, seed=0): + torch.manual_seed(seed) batch_size = 4 num_channels = 3 sizes = (32, 32) - image = floats_tensor((batch_size, num_channels) + sizes).to(torch_device) + image = torch.randn(batch_size, num_channels, *sizes).to(torch_device) return {"sample": image} # Bridge for AutoencoderTesterMixin which still uses the old interface From 7db96460536016f64eef65d9819187291693c649 Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Fri, 3 Apr 2026 07:39:39 +0200 Subject: [PATCH 3/3] propagate new changes. --- src/diffusers/__init__.py | 4 ++-- .../autoencoders/test_models_autoencoder_dc.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/diffusers/__init__.py b/src/diffusers/__init__.py index 0f74c0bbcb4a..e220eb10d562 100644 --- a/src/diffusers/__init__.py +++ b/src/diffusers/__init__.py @@ -178,13 +178,12 @@ ] ) _import_structure["image_processor"] = [ - "IPAdapterMaskProcessor", "InpaintProcessor", + "IPAdapterMaskProcessor", "PixArtImageProcessor", "VaeImageProcessor", "VaeImageProcessorLDM3D", ] - _import_structure["video_processor"] = ["VideoProcessor"] _import_structure["models"].extend( [ "AllegroTransformer3DModel", @@ -396,6 +395,7 @@ ] ) _import_structure["training_utils"] = ["EMAModel"] + _import_structure["video_processor"] = ["VideoProcessor"] try: if not (is_torch_available() and is_scipy_available()): diff --git a/tests/models/autoencoders/test_models_autoencoder_dc.py b/tests/models/autoencoders/test_models_autoencoder_dc.py index bf850bd050d4..f6542a49da71 100644 --- a/tests/models/autoencoders/test_models_autoencoder_dc.py +++ b/tests/models/autoencoders/test_models_autoencoder_dc.py @@ -17,10 +17,11 @@ import torch from diffusers import AutoencoderDC +from diffusers.utils.torch_utils import randn_tensor from ...testing_utils import IS_GITHUB_ACTIONS, enable_full_determinism, torch_device from ..testing_utils import BaseModelTesterConfig, MemoryTesterMixin, ModelTesterMixin, TrainingTesterMixin -from .testing_utils import AutoencoderTesterMixin +from .testing_utils import NewAutoencoderTesterMixin enable_full_determinism() @@ -35,6 +36,10 @@ def model_class(self): def output_shape(self): return (3, 32, 32) + @property + def generator(self): + return torch.Generator("cpu").manual_seed(0) + def get_init_dict(self): return { "in_channels": 3, @@ -61,18 +66,13 @@ def get_init_dict(self): "scaling_factor": 0.41407, } - def get_dummy_inputs(self, seed=0): - torch.manual_seed(seed) + def get_dummy_inputs(self): batch_size = 4 num_channels = 3 sizes = (32, 32) - image = torch.randn(batch_size, num_channels, *sizes).to(torch_device) + image = randn_tensor((batch_size, num_channels, *sizes), generator=self.generator, device=torch_device) return {"sample": image} - # Bridge for AutoencoderTesterMixin which still uses the old interface - def prepare_init_args_and_inputs_for_common(self): - return self.get_init_dict(), self.get_dummy_inputs() - class TestAutoencoderDC(AutoencoderDCTesterConfig, ModelTesterMixin): base_precision = 1e-2 @@ -90,5 +90,5 @@ def test_layerwise_casting_memory(self): super().test_layerwise_casting_memory() -class TestAutoencoderDCSlicingTiling(AutoencoderDCTesterConfig, AutoencoderTesterMixin): +class TestAutoencoderDCSlicingTiling(AutoencoderDCTesterConfig, NewAutoencoderTesterMixin): """Slicing and tiling tests for AutoencoderDC."""