From 357b6818903f0990a5e4815f31d1655555a035a7 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Mon, 6 Apr 2026 11:10:21 +0200 Subject: [PATCH] [tests] refactor autoencoderdc tests (#13369) * refactor autoencoderdc tests * fix * propagate new changes. --- .../test_models_autoencoder_dc.py | 62 ++++++++++--------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/tests/models/autoencoders/test_models_autoencoder_dc.py b/tests/models/autoencoders/test_models_autoencoder_dc.py index b1b5531d01..f6542a49da 100644 --- a/tests/models/autoencoders/test_models_autoencoder_dc.py +++ b/tests/models/autoencoders/test_models_autoencoder_dc.py @@ -13,24 +13,34 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest +import pytest +import torch from diffusers import AutoencoderDC +from diffusers.utils.torch_utils import randn_tensor -from ...testing_utils import IS_GITHUB_ACTIONS, enable_full_determinism, floats_tensor, torch_device -from ..test_modeling_common import ModelTesterMixin -from .testing_utils import AutoencoderTesterMixin +from ...testing_utils import IS_GITHUB_ACTIONS, enable_full_determinism, torch_device +from ..testing_utils import BaseModelTesterConfig, MemoryTesterMixin, ModelTesterMixin, TrainingTesterMixin +from .testing_utils import NewAutoencoderTesterMixin 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 - def get_autoencoder_dc_config(self): + @property + 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, "latent_channels": 4, @@ -56,33 +66,29 @@ class AutoencoderDCTests(ModelTesterMixin, AutoencoderTesterMixin, unittest.Test "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) - + image = randn_tensor((batch_size, num_channels, *sizes), generator=self.generator, device=torch_device) return {"sample": image} - @property - def input_shape(self): - return (3, 32, 32) - @property - def output_shape(self): - return (3, 32, 32) +class TestAutoencoderDC(AutoencoderDCTesterConfig, ModelTesterMixin): + base_precision = 1e-2 - 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 - @unittest.skipIf(IS_GITHUB_ACTIONS, reason="Skipping test inside GitHub Actions environment") - def test_layerwise_casting_inference(self): - super().test_layerwise_casting_inference() +class TestAutoencoderDCTraining(AutoencoderDCTesterConfig, TrainingTesterMixin): + """Training tests for AutoencoderDC.""" - @unittest.skipIf(IS_GITHUB_ACTIONS, reason="Skipping test inside GitHub Actions environment") + +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, NewAutoencoderTesterMixin): + """Slicing and tiling tests for AutoencoderDC."""