

import itertools
import random
import unittest

import numpy as np

from transformers import BatchFeature, SpeechTaFeatureExtractor
from transformers.testing_utils import require_torch
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_torch_available():
       import torch


A_		:      Dict					    = random.Random()


def    __a							( SCREAMING_SNAKE_CASE							, SCREAMING_SNAKE_CASE=1.0							, SCREAMING_SNAKE_CASE=None							, SCREAMING_SNAKE_CASE=None   )   ->  Union[str, Any]:






    '''simple docstring'''




    if rng is None:
        __UpperCAmelCase					       =      global_rng

    __UpperCAmelCase					       =      []
    for batch_idx in range(shape[0]   ):
        values.append([]   )
        for _ in range(shape[1]   ):
            values[-1].append(rng.random() * scale   )

    return values
@require_torch
class        A_ (   unittest.TestCase    ):


    '''simple docstring'''






    def __init__(self  ,   lowercase__  ,   lowercase__=7  ,   lowercase__=400  ,   lowercase__=2_000  ,   lowercase__=1  ,   lowercase__=0.0  ,   lowercase__=16_000  ,   lowercase__=True  ,   lowercase__=80  ,   lowercase__=16  ,   lowercase__=64  ,   lowercase__="hann_window"  ,   lowercase__=80  ,   lowercase__=7_600  ,   lowercase__=1E-10  ,   lowercase__=True  ,   )  ->   Any:
        __UpperCAmelCase					       =      parent
        __UpperCAmelCase					       =      batch_size
        __UpperCAmelCase					       =      min_seq_length
        __UpperCAmelCase					       =      max_seq_length
        __UpperCAmelCase					       =      (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
        __UpperCAmelCase					       =      feature_size
        __UpperCAmelCase					       =      padding_value
        __UpperCAmelCase					       =      sampling_rate
        __UpperCAmelCase					       =      do_normalize
        __UpperCAmelCase					       =      num_mel_bins
        __UpperCAmelCase					       =      hop_length
        __UpperCAmelCase					       =      win_length
        __UpperCAmelCase					       =      win_function
        __UpperCAmelCase					       =      fmin
        __UpperCAmelCase					       =      fmax
        __UpperCAmelCase					       =      mel_floor
        __UpperCAmelCase					       =      return_attention_mask


    def   lowerCAmelCase_    (self	)  ->   int:
        return {
            "feature_size": self.feature_size,
            "padding_value": self.padding_value,
            "sampling_rate": self.sampling_rate,
            "do_normalize": self.do_normalize,
            "num_mel_bins": self.num_mel_bins,
            "hop_length": self.hop_length,
            "win_length": self.win_length,
            "win_function": self.win_function,
            "fmin": self.fmin,
            "fmax": self.fmax,
            "mel_floor": self.mel_floor,
            "return_attention_mask": self.return_attention_mask,
        }


    def   lowerCAmelCase_    (self  ,   lowercase__=False  ,   lowercase__=False	)  ->   Union[str, Any]:


        def _flatten(lowercase__	):
            return list(itertools.chain(*SCREAMING_SNAKE_CASE_	)	)

        if equal_length:
            __UpperCAmelCase					       =      floats_list((self.batch_size, self.max_seq_length)	)
        else:
            # make sure that inputs increase in size
            __UpperCAmelCase					       =      [
                _flatten(floats_list((x, self.feature_size)	)	)
                for x in range(self.min_seq_length  ,   self.max_seq_length  ,   self.seq_length_diff	)
            ]

        if numpify:
            __UpperCAmelCase					       =      [np.asarray(SCREAMING_SNAKE_CASE_	) for x in speech_inputs]

        return speech_inputs






    def   lowerCAmelCase_    (self  ,   lowercase__=False  ,   lowercase__=False	)  ->   Dict:


        if equal_length:
            __UpperCAmelCase					       =      [floats_list((self.max_seq_length, self.num_mel_bins)	) for _ in range(self.batch_size	)]
        else:
            # make sure that inputs increase in size
            __UpperCAmelCase					       =      [
                floats_list((x, self.num_mel_bins)	)
                for x in range(self.min_seq_length  ,   self.max_seq_length  ,   self.seq_length_diff	)
            ]

        if numpify:
            __UpperCAmelCase					       =      [np.asarray(SCREAMING_SNAKE_CASE_	) for x in speech_inputs]

        return speech_inputs






@require_torch
class        A_ (   lowercase__			,  unittest.TestCase    ):


    '''simple docstring'''






    a__  				=							SpeechTaFeatureExtractor


    def   lowerCAmelCase_    (self	)  ->   str:
        __UpperCAmelCase					       =      SpeechTaFeatureExtractionTester(self	)


    def   lowerCAmelCase_    (self  ,   lowercase__	)  ->   Tuple:
        self.assertTrue(np.all(np.mean(SCREAMING_SNAKE_CASE_  ,   axis=0	) < 1E-3	)	)
        self.assertTrue(np.all(np.abs(np.var(SCREAMING_SNAKE_CASE_  ,   axis=0	) - 1	) < 1E-3	)	)


    def   lowerCAmelCase_    (self	)  ->   int:
        __UpperCAmelCase					       =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
        # create three inputs of length 800, 1000, and 1200
        __UpperCAmelCase					       =      [floats_list((1, x)	)[0] for x in range(800  ,   1_400  ,   200	)]
        __UpperCAmelCase					       =      [np.asarray(SCREAMING_SNAKE_CASE_	) for speech_input in speech_inputs]

        # Test not batched input
        __UpperCAmelCase					       =      feat_extract(speech_inputs[0]  ,   return_tensors='''np'''	).input_values
        __UpperCAmelCase					       =      feat_extract(np_speech_inputs[0]  ,   return_tensors='''np'''	).input_values
        self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE_  ,   SCREAMING_SNAKE_CASE_  ,   atol=1E-3	)	)

        # Test batched
        __UpperCAmelCase					       =      feat_extract(SCREAMING_SNAKE_CASE_  ,   return_tensors='''np'''	).input_values
        __UpperCAmelCase					       =      feat_extract(SCREAMING_SNAKE_CASE_  ,   return_tensors='''np'''	).input_values
        for enc_seq_a, enc_seq_a in zip(SCREAMING_SNAKE_CASE_  ,   SCREAMING_SNAKE_CASE_	):
            self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE_  ,   SCREAMING_SNAKE_CASE_  ,   atol=1E-3	)	)


    def   lowerCAmelCase_    (self	)  ->   Optional[int]:
        __UpperCAmelCase					       =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
        __UpperCAmelCase					       =      [floats_list((1, x)	)[0] for x in range(800  ,   1_400  ,   200	)]

        __UpperCAmelCase					       =      ['''longest''', '''max_length''', '''do_not_pad''']
        __UpperCAmelCase					       =      [None, 1_600, None]
        for max_length, padding in zip(SCREAMING_SNAKE_CASE_  ,   SCREAMING_SNAKE_CASE_	):
            __UpperCAmelCase					       =      feat_extract(SCREAMING_SNAKE_CASE_  ,   padding=SCREAMING_SNAKE_CASE_  ,   max_length=SCREAMING_SNAKE_CASE_  ,   return_tensors='''np'''	)
            __UpperCAmelCase					       =      processed.input_values

            self._check_zero_mean_unit_variance(input_values[0][:800]	)
            self.assertTrue(input_values[0][800:].sum() < 1E-6	)
            self._check_zero_mean_unit_variance(input_values[1][:1_000]	)
            self.assertTrue(input_values[0][1_000:].sum() < 1E-6	)
            self._check_zero_mean_unit_variance(input_values[2][:1_200]	)


    def   lowerCAmelCase_    (self	)  ->   List[Any]:
        __UpperCAmelCase					       =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
        __UpperCAmelCase					       =      range(800  ,   1_400  ,   200	)
        __UpperCAmelCase					       =      [floats_list((1, x)	)[0] for x in lengths]

        __UpperCAmelCase					       =      ['''longest''', '''max_length''', '''do_not_pad''']
        __UpperCAmelCase					       =      [None, 1_600, None]

        for max_length, padding in zip(SCREAMING_SNAKE_CASE_  ,   SCREAMING_SNAKE_CASE_	):
            __UpperCAmelCase					       =      feat_extract(SCREAMING_SNAKE_CASE_  ,   max_length=SCREAMING_SNAKE_CASE_  ,   padding=SCREAMING_SNAKE_CASE_	)
            __UpperCAmelCase					       =      processed.input_values

            self._check_zero_mean_unit_variance(input_values[0][:800]	)
            self._check_zero_mean_unit_variance(input_values[1][:1_000]	)
            self._check_zero_mean_unit_variance(input_values[2][:1_200]	)


    def   lowerCAmelCase_    (self	)  ->   Dict:
        __UpperCAmelCase					       =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
        __UpperCAmelCase					       =      [floats_list((1, x)	)[0] for x in range(800  ,   1_400  ,   200	)]
        __UpperCAmelCase					       =      feat_extract(
            SCREAMING_SNAKE_CASE_  ,   truncation=SCREAMING_SNAKE_CASE_  ,   max_length=1_000  ,   padding='''max_length'''  ,   return_tensors='''np'''	)
        __UpperCAmelCase					       =      processed.input_values

        self._check_zero_mean_unit_variance(input_values[0, :800]	)
        self._check_zero_mean_unit_variance(input_values[1]	)
        self._check_zero_mean_unit_variance(input_values[2]	)


    def   lowerCAmelCase_    (self	)  ->   Optional[int]:
        __UpperCAmelCase					       =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
        __UpperCAmelCase					       =      [floats_list((1, x)	)[0] for x in range(800  ,   1_400  ,   200	)]
        __UpperCAmelCase					       =      feat_extract(
            SCREAMING_SNAKE_CASE_  ,   truncation=SCREAMING_SNAKE_CASE_  ,   max_length=1_000  ,   padding='''longest'''  ,   return_tensors='''np'''	)
        __UpperCAmelCase					       =      processed.input_values

        self._check_zero_mean_unit_variance(input_values[0, :800]	)
        self._check_zero_mean_unit_variance(input_values[1, :1_000]	)
        self._check_zero_mean_unit_variance(input_values[2]	)

        # make sure that if max_length < longest -> then pad to max_length
        self.assertTrue(input_values.shape == (3, 1_000)	)

        __UpperCAmelCase					       =      [floats_list((1, x)	)[0] for x in range(800  ,   1_400  ,   200	)]
        __UpperCAmelCase					       =      feat_extract(
            SCREAMING_SNAKE_CASE_  ,   truncation=SCREAMING_SNAKE_CASE_  ,   max_length=2_000  ,   padding='''longest'''  ,   return_tensors='''np'''	)
        __UpperCAmelCase					       =      processed.input_values

        self._check_zero_mean_unit_variance(input_values[0, :800]	)
        self._check_zero_mean_unit_variance(input_values[1, :1_000]	)
        self._check_zero_mean_unit_variance(input_values[2]	)

        # make sure that if max_length > longest -> then pad to longest
        self.assertTrue(input_values.shape == (3, 1_200)	)


    def   lowerCAmelCase_    (self	)  ->   Dict:
        __UpperCAmelCase					       =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
        __UpperCAmelCase					       =      np.random.rand(100	).astype(np.floataa	)
        __UpperCAmelCase					       =      np_speech_inputs.tolist()

        for inputs in [py_speech_inputs, np_speech_inputs]:
            __UpperCAmelCase					       =      feature_extractor.pad([{'''input_values''': inputs}]  ,   return_tensors='''np'''	)
            self.assertTrue(np_processed.input_values.dtype == np.floataa	)
            __UpperCAmelCase					       =      feature_extractor.pad([{'''input_values''': inputs}]  ,   return_tensors='''pt'''	)
            self.assertTrue(pt_processed.input_values.dtype == torch.floataa	)


    def   lowerCAmelCase_    (self	)  ->   Union[str, Any]:
        __UpperCAmelCase					       =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()	)
        # create three inputs of length 800, 1000, and 1200
        __UpperCAmelCase					       =      [floats_list((1, x)	)[0] for x in range(800  ,   1_400  ,   200	)]
        __UpperCAmelCase					       =      [np.asarray(SCREAMING_SNAKE_CASE_	) for speech_input in speech_inputs]

        # Test feature size
        __UpperCAmelCase					       =      feature_extractor(audio_target=SCREAMING_SNAKE_CASE_  ,   padding=SCREAMING_SNAKE_CASE_  ,   return_tensors='''np'''	).input_values
        self.assertTrue(input_values.ndim == 3	)
        self.assertTrue(input_values.shape[-1] == feature_extractor.num_mel_bins	)

        # Test not batched input
        __UpperCAmelCase					       =      feature_extractor(speech_inputs[0]  ,   return_tensors='''np'''	).input_values
        __UpperCAmelCase					       =      feature_extractor(np_speech_inputs[0]  ,   return_tensors='''np'''	).input_values
        self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE_  ,   SCREAMING_SNAKE_CASE_  ,   atol=1E-3	)	)

        # Test batched
        __UpperCAmelCase					       =      feature_extractor(SCREAMING_SNAKE_CASE_  ,   return_tensors='''np'''	).input_values
        __UpperCAmelCase					       =      feature_extractor(SCREAMING_SNAKE_CASE_  ,   return_tensors='''np'''	).input_values
        for enc_seq_a, enc_seq_a in zip(SCREAMING_SNAKE_CASE_  ,   SCREAMING_SNAKE_CASE_	):
            self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE_  ,   SCREAMING_SNAKE_CASE_  ,   atol=1E-3	)	)

        # Test 2-D numpy arrays are batched.
        __UpperCAmelCase					       =      [floats_list((1, x)	)[0] for x in (800, 800, 800)]
        __UpperCAmelCase					       =      np.asarray(SCREAMING_SNAKE_CASE_	)
        __UpperCAmelCase					       =      feature_extractor(SCREAMING_SNAKE_CASE_  ,   return_tensors='''np'''	).input_values
        __UpperCAmelCase					       =      feature_extractor(SCREAMING_SNAKE_CASE_  ,   return_tensors='''np'''	).input_values
        for enc_seq_a, enc_seq_a in zip(SCREAMING_SNAKE_CASE_  ,   SCREAMING_SNAKE_CASE_	):
            self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE_  ,   SCREAMING_SNAKE_CASE_  ,   atol=1E-3	)	)


    def   lowerCAmelCase_    (self	)  ->   Tuple:
        __UpperCAmelCase					       =      self.feat_extract_tester.prepare_inputs_for_target()
        __UpperCAmelCase					       =      self.feature_extraction_class(**self.feat_extract_dict	)
        __UpperCAmelCase					       =      feat_extract.model_input_names[0]

        __UpperCAmelCase					       =      BatchFeature({input_name: speech_inputs}	)

        self.assertTrue(all(len(SCREAMING_SNAKE_CASE_	) == len(SCREAMING_SNAKE_CASE_	) for x, y in zip(SCREAMING_SNAKE_CASE_  ,   processed_features[input_name]	)	)	)

        __UpperCAmelCase					       =      self.feat_extract_tester.prepare_inputs_for_target(equal_length=SCREAMING_SNAKE_CASE_	)
        __UpperCAmelCase					       =      BatchFeature({input_name: speech_inputs}  ,   tensor_type='''np'''	)

        __UpperCAmelCase					       =      processed_features[input_name]

        if len(batch_features_input.shape	) < 3:
            __UpperCAmelCase					       =      batch_features_input[:, :, None]

        self.assertTrue(
            batch_features_input.shape
            == (self.feat_extract_tester.batch_size, len(speech_inputs[0]	), self.feat_extract_tester.num_mel_bins)	)


    @require_torch
    def   lowerCAmelCase_    (self	)  ->   Union[str, Any]:
        __UpperCAmelCase					       =      self.feat_extract_tester.prepare_inputs_for_target(equal_length=SCREAMING_SNAKE_CASE_	)
        __UpperCAmelCase					       =      self.feature_extraction_class(**self.feat_extract_dict	)
        __UpperCAmelCase					       =      feat_extract.model_input_names[0]

        __UpperCAmelCase					       =      BatchFeature({input_name: speech_inputs}  ,   tensor_type='''pt'''	)

        __UpperCAmelCase					       =      processed_features[input_name]

        if len(batch_features_input.shape	) < 3:
            __UpperCAmelCase					       =      batch_features_input[:, :, None]

        self.assertTrue(
            batch_features_input.shape
            == (self.feat_extract_tester.batch_size, len(speech_inputs[0]	), self.feat_extract_tester.num_mel_bins)	)


    @require_torch
    def   lowerCAmelCase_    (self	)  ->   Any:
        __UpperCAmelCase					       =      self.feature_extraction_class(**self.feat_extract_dict	)
        __UpperCAmelCase					       =      self.feat_extract_tester.prepare_inputs_for_target()
        __UpperCAmelCase					       =      feat_extract.model_input_names[0]

        __UpperCAmelCase					       =      BatchFeature({input_name: speech_inputs}	)

        __UpperCAmelCase					       =      feat_extract.num_mel_bins  # hack!

        __UpperCAmelCase					       =      feat_extract.pad(SCREAMING_SNAKE_CASE_  ,   padding='''longest'''  ,   return_tensors='''np'''	)[input_name]
        __UpperCAmelCase					       =      feat_extract.pad(SCREAMING_SNAKE_CASE_  ,   padding='''longest'''  ,   return_tensors='''pt'''	)[input_name]

        self.assertTrue(abs(input_np.astype(np.floataa	).sum() - input_pt.numpy().astype(np.floataa	).sum()	) < 1E-2	)


    def   lowerCAmelCase_    (self	)  ->   int:
        __UpperCAmelCase					       =      self.feat_extract_dict
        __UpperCAmelCase					       =      True
        __UpperCAmelCase					       =      self.feature_extraction_class(**SCREAMING_SNAKE_CASE_	)
        __UpperCAmelCase					       =      self.feat_extract_tester.prepare_inputs_for_target()
        __UpperCAmelCase					       =      [len(SCREAMING_SNAKE_CASE_	) for x in speech_inputs]
        __UpperCAmelCase					       =      feat_extract.model_input_names[0]

        __UpperCAmelCase					       =      BatchFeature({input_name: speech_inputs}	)

        __UpperCAmelCase					       =      feat_extract.num_mel_bins  # hack!

        __UpperCAmelCase					       =      feat_extract.pad(SCREAMING_SNAKE_CASE_  ,   padding='''longest'''  ,   return_tensors='''np'''	)
        self.assertIn('''attention_mask'''  ,   SCREAMING_SNAKE_CASE_	)
        self.assertListEqual(list(processed.attention_mask.shape	)  ,   list(processed[input_name].shape[:2]	)	)
        self.assertListEqual(processed.attention_mask.sum(-1	).tolist()  ,   SCREAMING_SNAKE_CASE_	)


    def   lowerCAmelCase_    (self	)  ->   Optional[int]:
        __UpperCAmelCase					       =      self.feat_extract_dict
        __UpperCAmelCase					       =      True
        __UpperCAmelCase					       =      self.feature_extraction_class(**SCREAMING_SNAKE_CASE_	)
        __UpperCAmelCase					       =      self.feat_extract_tester.prepare_inputs_for_target()
        __UpperCAmelCase					       =      [len(SCREAMING_SNAKE_CASE_	) for x in speech_inputs]
        __UpperCAmelCase					       =      feat_extract.model_input_names[0]

        __UpperCAmelCase					       =      BatchFeature({input_name: speech_inputs}	)
        __UpperCAmelCase					       =      min(SCREAMING_SNAKE_CASE_	)

        __UpperCAmelCase					       =      feat_extract.num_mel_bins  # hack!

        __UpperCAmelCase					       =      feat_extract.pad(
            SCREAMING_SNAKE_CASE_  ,   padding='''max_length'''  ,   max_length=SCREAMING_SNAKE_CASE_  ,   truncation=SCREAMING_SNAKE_CASE_  ,   return_tensors='''np'''	)
        self.assertIn('''attention_mask'''  ,   SCREAMING_SNAKE_CASE_	)
        self.assertListEqual(
            list(processed_pad.attention_mask.shape	)  ,   [processed_pad[input_name].shape[0], max_length]	)
        self.assertListEqual(
            processed_pad.attention_mask[:, :max_length].sum(-1	).tolist()  ,   [max_length for x in speech_inputs]	)


    def   lowerCAmelCase_    (self  ,   lowercase__	)  ->   List[str]:
        from datasets import load_dataset

        __UpperCAmelCase					       =      load_dataset('''hf-internal-testing/librispeech_asr_dummy'''  ,   '''clean'''  ,   split='''validation'''	)
        # automatic decoding with librispeech
        __UpperCAmelCase					       =      ds.sort('''id'''	).select(range(SCREAMING_SNAKE_CASE_	)	)[:num_samples]['''audio''']

        return [x["array"] for x in speech_samples]


    def   lowerCAmelCase_    (self	)  ->   List[str]:
        __UpperCAmelCase					       =      torch.tensor(
            [2.3804E-03, 2.0752E-03, 1.9836E-03, 2.1057E-03, 1.6174E-03,
             3.0518E-04, 9.1553E-05, 3.3569E-04, 9.7656E-04, 1.8311E-03,
             2.0142E-03, 2.1057E-03, 1.7395E-03, 4.5776E-04, -3.9673E-04,
             4.5776E-04, 1.0071E-03, 9.1553E-05, 4.8828E-04, 1.1597E-03,
             7.3242E-04, 9.4604E-04, 1.8005E-03, 1.8311E-03, 8.8501E-04,
             4.2725E-04, 4.8828E-04, 7.3242E-04, 1.0986E-03, 2.1057E-03]	)
        # fmt: on

        __UpperCAmelCase					       =      self._load_datasamples(1	)
        __UpperCAmelCase					       =      SpeechTaFeatureExtractor()
        __UpperCAmelCase					       =      feature_extractor(SCREAMING_SNAKE_CASE_  ,   return_tensors='''pt'''	).input_values
        self.assertEquals(input_values.shape  ,   (1, 93_680)	)
        self.assertTrue(torch.allclose(input_values[0, :30]  ,   SCREAMING_SNAKE_CASE_  ,   atol=1E-6	)	)






    def   lowerCAmelCase_    (self	)  ->   int:
        __UpperCAmelCase					       =      torch.tensor(
            [-2.6870, -3.0104, -3.1356, -3.5352, -3.0044, -3.0353, -3.4719, -3.6777,
             -3.1520, -2.9435, -2.6553, -2.8795, -2.9944, -2.5921, -3.0279, -3.0386,
             -3.0864, -3.1291, -3.2353, -2.7444, -2.6831, -2.7287, -3.1761, -3.1571,
             -3.2726, -3.0582, -3.1007, -3.4533, -3.4695, -3.0998]	)
        # fmt: on

        __UpperCAmelCase					       =      self._load_datasamples(1	)
        __UpperCAmelCase					       =      SpeechTaFeatureExtractor()
        __UpperCAmelCase					       =      feature_extractor(audio_target=SCREAMING_SNAKE_CASE_  ,   return_tensors='''pt'''	).input_values
        self.assertEquals(input_values.shape  ,   (1, 366, 80)	)
        self.assertTrue(torch.allclose(input_values[0, 0, :30]  ,   SCREAMING_SNAKE_CASE_  ,   atol=1E-4	)	)






"""simple docstring"""






import unittest

from diffusers.models.unet_ad_blocks import *  # noqa F403
from diffusers.utils import torch_device

from .test_unet_blocks_common import UNetBlockTesterMixin



class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     DownBlockaD  # noqa F405
			lowercase        =     '''down'''






			def 					UpperCAmelCase							(self  :	int			)       ->	List[str]:





				"""simple docstring"""


				lowerCAmelCase												=  [-0.02_32, -0.98_69, 0.80_54, -0.06_37, -0.16_88, -1.42_64, 0.44_70, -1.33_94, 0.09_04]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     ResnetDownsampleBlockaD  # noqa F405
			lowercase        =     '''down'''






			def 					UpperCAmelCase							(self  :	Any			)       ->	List[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  [0.07_10, 0.24_10, -0.73_20, -1.07_57, -1.13_43, 0.35_40, -0.01_33, -0.25_76, 0.09_48]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     AttnDownBlockaD  # noqa F405
			lowercase        =     '''down'''






			def 					UpperCAmelCase							(self  :	Tuple			)       ->	List[str]:





				"""simple docstring"""


				lowerCAmelCase												=  [0.06_36, 0.89_64, -0.62_34, -1.01_31, 0.08_44, 0.49_35, 0.34_37, 0.09_11, -0.29_57]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     CrossAttnDownBlockaD  # noqa F405
			lowercase        =     '''down'''






			def 					UpperCAmelCase							(self  :	int			)       ->	Union[str, Any]:





				"""simple docstring"""


				lowerCAmelCase							,       lowerCAmelCase												=  super().prepare_init_args_and_inputs_for_common()
				lowerCAmelCase												=  32
				return init_dict, inputs_dict






			def 					UpperCAmelCase							(self  :	List[Any]			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  [0.22_38, -0.73_96, -0.22_55, -0.38_29, 0.19_25, 1.16_65, 0.06_03, -0.72_95, 0.19_83]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     SimpleCrossAttnDownBlockaD  # noqa F405
			lowercase        =     '''down'''






			@property
			def 					UpperCAmelCase							(self  :	Dict			)       ->	List[str]:





				"""simple docstring"""


				return super().get_dummy_input(include_encoder_hidden_states=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	List[Any]			)       ->	List[str]:





				"""simple docstring"""


				lowerCAmelCase							,       lowerCAmelCase												=  super().prepare_init_args_and_inputs_for_common()
				lowerCAmelCase												=  32
				return init_dict, inputs_dict






			@unittest.skipIf(torch_device == '''mps'''      ,'''MPS result is not consistent'''			)
			def 					UpperCAmelCase							(self  :	str			)       ->	Tuple:





				"""simple docstring"""


				lowerCAmelCase												=  [0.79_21, -0.09_92, -0.19_62, -0.76_95, -0.42_42, 0.78_04, 0.47_37, 0.27_65, 0.33_38]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     SkipDownBlockaD  # noqa F405
			lowercase        =     '''down'''






			@property
			def 					UpperCAmelCase							(self  :	List[Any]			)       ->	int:





				"""simple docstring"""


				return super().get_dummy_input(include_skip_sample=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	int:





				"""simple docstring"""


				lowerCAmelCase												=  [-0.08_45, -0.20_87, -0.24_65, 0.09_71, 0.19_00, -0.04_84, 0.26_64, 0.41_79, 0.50_69]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     AttnSkipDownBlockaD  # noqa F405
			lowercase        =     '''down'''






			@property
			def 					UpperCAmelCase							(self  :	List[Any]			)       ->	Optional[int]:





				"""simple docstring"""


				return super().get_dummy_input(include_skip_sample=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Any			)       ->	List[str]:





				"""simple docstring"""


				lowerCAmelCase												=  [0.55_39, 0.16_09, 0.49_24, 0.05_37, -0.19_95, 0.40_50, 0.09_79, -0.27_21, -0.06_42]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     DownEncoderBlockaD  # noqa F405
			lowercase        =     '''down'''






			@property
			def 					UpperCAmelCase							(self  :	int			)       ->	str:





				"""simple docstring"""


				return super().get_dummy_input(include_temb=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	int			)       ->	Tuple:





				"""simple docstring"""


				lowerCAmelCase												=  {
				    '''in_channels''': 32,
				    '''out_channels''': 32,
				}
				lowerCAmelCase												=  self.dummy_input
				return init_dict, inputs_dict






			def 					UpperCAmelCase							(self  :	str			)       ->	Optional[int]:





				"""simple docstring"""


				lowerCAmelCase												=  [1.11_02, 0.53_02, 0.48_72, -0.00_23, -0.80_42, 0.04_83, -0.34_89, -0.56_32, 0.76_26]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     AttnDownEncoderBlockaD  # noqa F405
			lowercase        =     '''down'''






			@property
			def 					UpperCAmelCase							(self  :	Tuple			)       ->	Union[str, Any]:





				"""simple docstring"""


				return super().get_dummy_input(include_temb=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	List[Any]			)       ->	Union[str, Any]:





				"""simple docstring"""


				lowerCAmelCase												=  {
				    '''in_channels''': 32,
				    '''out_channels''': 32,
				}
				lowerCAmelCase												=  self.dummy_input
				return init_dict, inputs_dict






			def 					UpperCAmelCase							(self  :	Any			)       ->	Optional[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  [0.89_66, -0.14_86, 0.85_68, 0.81_41, -0.90_46, -0.13_42, -0.09_72, -0.74_17, 0.15_38]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     UNetMidBlockaD  # noqa F405
			lowercase        =     '''mid'''






			def 					UpperCAmelCase							(self  :	List[Any]			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  {
				    '''in_channels''': 32,
				    '''temb_channels''': 128,
				}
				lowerCAmelCase												=  self.dummy_input
				return init_dict, inputs_dict






			def 					UpperCAmelCase							(self  :	Optional[Any]			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  [-0.10_62, 1.72_48, 0.34_94, 1.45_69, -0.09_10, -1.24_21, -0.99_84, 0.67_36, 1.00_28]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     UNetMidBlockaDCrossAttn  # noqa F405
			lowercase        =     '''mid'''






			def 					UpperCAmelCase							(self  :	Union[str, Any]			)       ->	Tuple:





				"""simple docstring"""


				lowerCAmelCase							,       lowerCAmelCase												=  super().prepare_init_args_and_inputs_for_common()
				lowerCAmelCase												=  32
				return init_dict, inputs_dict






			def 					UpperCAmelCase							(self  :	Any			)       ->	Dict:





				"""simple docstring"""


				lowerCAmelCase												=  [0.01_87, 2.42_20, 0.44_84, 1.12_03, -0.61_21, -1.51_22, -0.82_70, 0.78_51, 1.83_35]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     UNetMidBlockaDSimpleCrossAttn  # noqa F405
			lowercase        =     '''mid'''






			@property
			def 					UpperCAmelCase							(self  :	Union[str, Any]			)       ->	str:





				"""simple docstring"""


				return super().get_dummy_input(include_encoder_hidden_states=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	int			)       ->	int:





				"""simple docstring"""


				lowerCAmelCase							,       lowerCAmelCase												=  super().prepare_init_args_and_inputs_for_common()
				lowerCAmelCase												=  32
				return init_dict, inputs_dict






			def 					UpperCAmelCase							(self  :	str			)       ->	Optional[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  [0.71_43, 1.99_74, 0.54_48, 1.39_77, 0.12_82, -1.12_37, -1.42_38, 0.55_30, 0.88_80]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     UpBlockaD  # noqa F405
			lowercase        =     '''up'''






			@property
			def 					UpperCAmelCase							(self  :	int			)       ->	Any:





				"""simple docstring"""


				return super().get_dummy_input(include_res_hidden_states_tuple=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Tuple			)       ->	Optional[int]:





				"""simple docstring"""


				lowerCAmelCase												=  [-0.20_41, -0.41_65, -0.30_22, 0.00_41, -0.66_28, -0.70_53, 0.19_28, -0.03_25, 0.05_23]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     ResnetUpsampleBlockaD  # noqa F405
			lowercase        =     '''up'''






			@property
			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	str:





				"""simple docstring"""


				return super().get_dummy_input(include_res_hidden_states_tuple=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Dict			)       ->	List[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  [0.22_87, 0.35_49, -0.13_46, 0.47_97, -0.17_15, -0.96_49, 0.73_05, -0.58_64, -0.62_44]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     CrossAttnUpBlockaD  # noqa F405
			lowercase        =     '''up'''






			@property
			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	Optional[Any]:





				"""simple docstring"""


				return super().get_dummy_input(include_res_hidden_states_tuple=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Tuple			)       ->	List[str]:





				"""simple docstring"""


				lowerCAmelCase							,       lowerCAmelCase												=  super().prepare_init_args_and_inputs_for_common()
				lowerCAmelCase												=  32
				return init_dict, inputs_dict






			def 					UpperCAmelCase							(self  :	str			)       ->	Tuple:





				"""simple docstring"""


				lowerCAmelCase												=  [-0.14_03, -0.35_15, -0.04_20, -0.14_25, 0.31_67, 0.50_94, -0.21_81, 0.59_31, 0.55_82]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     SimpleCrossAttnUpBlockaD  # noqa F405
			lowercase        =     '''up'''






			@property
			def 					UpperCAmelCase							(self  :	Any			)       ->	List[Any]:





				"""simple docstring"""


				return super().get_dummy_input(include_res_hidden_states_tuple=SCREAMING_SNAKE_CASE_      ,include_encoder_hidden_states=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Union[str, Any]			)       ->	int:





				"""simple docstring"""


				lowerCAmelCase							,       lowerCAmelCase												=  super().prepare_init_args_and_inputs_for_common()
				lowerCAmelCase												=  32
				return init_dict, inputs_dict






			def 					UpperCAmelCase							(self  :	Tuple			)       ->	Any:





				"""simple docstring"""


				lowerCAmelCase												=  [0.26_45, 0.14_80, 0.09_09, 0.80_44, -0.97_58, -0.90_83, 0.09_94, -1.14_53, -0.74_02]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     AttnUpBlockaD  # noqa F405
			lowercase        =     '''up'''






			@property
			def 					UpperCAmelCase							(self  :	List[str]			)       ->	List[Any]:





				"""simple docstring"""


				return super().get_dummy_input(include_res_hidden_states_tuple=SCREAMING_SNAKE_CASE_			)






			@unittest.skipIf(torch_device == '''mps'''      ,'''MPS result is not consistent'''			)
			def 					UpperCAmelCase							(self  :	int			)       ->	Tuple:





				"""simple docstring"""


				lowerCAmelCase												=  [0.09_79, 0.13_26, 0.00_21, 0.06_59, 0.22_49, 0.00_59, 0.11_32, 0.59_52, 0.10_33]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     SkipUpBlockaD  # noqa F405
			lowercase        =     '''up'''






			@property
			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	List[str]:





				"""simple docstring"""


				return super().get_dummy_input(include_res_hidden_states_tuple=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	str			)       ->	int:





				"""simple docstring"""


				lowerCAmelCase												=  [-0.08_93, -0.12_34, -0.15_06, -0.03_32, 0.01_23, -0.02_11, 0.05_66, 0.01_43, 0.03_62]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     AttnSkipUpBlockaD  # noqa F405
			lowercase        =     '''up'''






			@property
			def 					UpperCAmelCase							(self  :	Optional[Any]			)       ->	str:





				"""simple docstring"""


				return super().get_dummy_input(include_res_hidden_states_tuple=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Any			)       ->	int:





				"""simple docstring"""


				lowerCAmelCase												=  [0.03_61, 0.06_17, 0.27_87, -0.03_50, 0.03_42, 0.34_21, -0.08_43, 0.09_13, 0.30_15]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     UpDecoderBlockaD  # noqa F405
			lowercase        =     '''up'''






			@property
			def 					UpperCAmelCase							(self  :	List[str]			)       ->	List[Any]:





				"""simple docstring"""


				return super().get_dummy_input(include_temb=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	List[str]			)       ->	Union[str, Any]:





				"""simple docstring"""


				lowerCAmelCase												=  {'''in_channels''': 32, '''out_channels''': 32}

				lowerCAmelCase												=  self.dummy_input
				return init_dict, inputs_dict






			def 					UpperCAmelCase							(self  :	Dict			)       ->	Union[str, Any]:





				"""simple docstring"""


				lowerCAmelCase												=  [0.44_04, 0.19_98, -0.98_86, -0.33_20, -0.31_28, -0.70_34, -0.69_55, -0.23_38, -0.31_37]
				super().test_output(SCREAMING_SNAKE_CASE_			)





class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     AttnUpDecoderBlockaD  # noqa F405
			lowercase        =     '''up'''






			@property
			def 					UpperCAmelCase							(self  :	Any			)       ->	Dict:





				"""simple docstring"""


				return super().get_dummy_input(include_temb=SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Any			)       ->	Optional[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  {'''in_channels''': 32, '''out_channels''': 32}

				lowerCAmelCase												=  self.dummy_input
				return init_dict, inputs_dict






			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	Optional[int]:





				"""simple docstring"""


				lowerCAmelCase												=  [0.67_38, 0.44_91, 0.10_55, 1.07_10, 0.73_16, 0.33_39, 0.33_52, 0.10_23, 0.35_68]
				super().test_output(SCREAMING_SNAKE_CASE_			)


