

import unittest
from dataclasses import dataclass
from typing import List, Union

import numpy as np
import PIL.Image

from diffusers.utils.outputs import BaseOutput
@dataclass
class 					A_   (      _a						):


    '''simple docstring'''






    a__     							=       42






class 					A_   (      unittest.TestCase						):


    '''simple docstring'''






    def      lowerCAmelCase_						(self  )     ->      Union[str, Any]:
        __UpperCAmelCase									=			CustomOutput(images=np.random.rand(1     ,      3     ,      4     ,      4  )  )

        # check every way of getting the attribute
        assert isinstance(outputs.images     ,      np.ndarray  )
        assert outputs.images.shape == (1, 3, 4, 4)
        assert isinstance(outputs['''images''']     ,      np.ndarray  )
        assert outputs["images"].shape == (1, 3, 4, 4)
        assert isinstance(outputs[0]     ,      np.ndarray  )
        assert outputs[0].shape == (1, 3, 4, 4)

        # test with a non-tensor attribute
        __UpperCAmelCase									=			CustomOutput(images=[PIL.Image.new('''RGB'''     ,      (4, 4)  )]  )

        # check every way of getting the attribute
        assert isinstance(outputs.images     ,      lowercase__  )
        assert isinstance(outputs.images[0]     ,      PIL.Image.Image  )
        assert isinstance(outputs['''images''']     ,      lowercase__  )
        assert isinstance(outputs['''images'''][0]     ,      PIL.Image.Image  )
        assert isinstance(outputs[0]     ,      lowercase__  )
        assert isinstance(outputs[0][0]     ,      PIL.Image.Image  )






    def      lowerCAmelCase_						(self  )     ->      int:
        # test output reinitialization with a `dict` for compatibility with `accelerate`
        __UpperCAmelCase									=			CustomOutput({'''images''': np.random.rand(1     ,      3     ,      4     ,      4  )}  )

        # check every way of getting the attribute
        assert isinstance(outputs.images     ,      np.ndarray  )
        assert outputs.images.shape == (1, 3, 4, 4)
        assert isinstance(outputs['''images''']     ,      np.ndarray  )
        assert outputs["images"].shape == (1, 3, 4, 4)
        assert isinstance(outputs[0]     ,      np.ndarray  )
        assert outputs[0].shape == (1, 3, 4, 4)

        # test with a non-tensor attribute
        __UpperCAmelCase									=			CustomOutput({'''images''': [PIL.Image.new('''RGB'''     ,      (4, 4)  )]}  )

        # check every way of getting the attribute
        assert isinstance(outputs.images     ,      lowercase__  )
        assert isinstance(outputs.images[0]     ,      PIL.Image.Image  )
        assert isinstance(outputs['''images''']     ,      lowercase__  )
        assert isinstance(outputs['''images'''][0]     ,      PIL.Image.Image  )
        assert isinstance(outputs[0]     ,      lowercase__  )
        assert isinstance(outputs[0][0]     ,      PIL.Image.Image  )







import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig


A_		:			int										=   logging.get_logger(__name__)
class 					A_   (      _a						):


    '''simple docstring'''






    a__     							=       "speech-encoder-decoder"
    a__     							=       True


    def __init__(self     ,      **lowercase__  )     ->      Optional[int]:
        super().__init__(**lowercase__  )
        if "encoder" not in kwargs or "decoder" not in kwargs:
            raise ValueError(
                F'''A configuraton of type {self.model_type} cannot be instantiated because not both `encoder` and'''
                F''' `decoder` sub-configurations are passed, but only {kwargs}'''  )

        __UpperCAmelCase									=			kwargs.pop('''encoder'''  )
        __UpperCAmelCase									=			encoder_config.pop('''model_type'''  )
        __UpperCAmelCase									=			kwargs.pop('''decoder'''  )
        __UpperCAmelCase									=			decoder_config.pop('''model_type'''  )

        __UpperCAmelCase									=			AutoConfig.for_model(lowercase__     ,      **lowercase__  )
        __UpperCAmelCase									=			AutoConfig.for_model(lowercase__     ,      **lowercase__  )
        __UpperCAmelCase									=			True


    @classmethod
    def      lowerCAmelCase_						(cls     ,      lowercase__     ,      lowercase__     ,      **lowercase__  )     ->      PretrainedConfig:
        logger.info('''Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config'''  )
        __UpperCAmelCase									=			True
        __UpperCAmelCase									=			True

        return cls(encoder=encoder_config.to_dict()     ,      decoder=decoder_config.to_dict()     ,      **lowercase__  )






    def      lowerCAmelCase_						(self  )     ->      Optional[Any]:
        __UpperCAmelCase									=			copy.deepcopy(self.__dict__  )
        __UpperCAmelCase									=			self.encoder.to_dict()
        __UpperCAmelCase									=			self.decoder.to_dict()
        __UpperCAmelCase									=			self.__class__.model_type
        return output




