


"""simple docstring"""


from math import ceil


def _lowerCamelCase	(		_UpperCamelCase    , _UpperCamelCase      ):

			'''simple docstring'''




			__lowerCAmelCase				    =			list(range(0    , lowercase_      )      )

			__lowerCAmelCase				    =			[item for sublist in list(device_map.values()      ) for item in sublist]

			# Duplicate check
			__lowerCAmelCase				    =			[]
			for i in device_map_blocks:
						if device_map_blocks.count(lowercase_      ) > 1 and i not in duplicate_blocks:
									duplicate_blocks.append(lowercase_      )
    # Missing blocks
			__lowerCAmelCase				    =			[i for i in blocks if i not in device_map_blocks]
			__lowerCAmelCase				    =			[i for i in device_map_blocks if i not in blocks]

			if len(lowercase_      ) != 0:
						raise ValueError(
						    "Duplicate attention blocks specified in device_map. Attention blocks must be specified to one device."
						    " These attention blocks were specified more than once: " + str(lowercase_      )      )
			if len(lowercase_      ) != 0:
						raise ValueError(
						    "There are attention blocks for this model that are not specified in the device_map. Add these attention "
						    "blocks to a device on the device_map: " + str(lowercase_      )      )
			if len(lowercase_      ) != 0:
						raise ValueError(
						    "The device_map contains more attention blocks than this model has. Remove these from the device_map:"
						    + str(lowercase_      )      )


def _lowerCamelCase	(		_UpperCamelCase    , _UpperCamelCase      ):

			'''simple docstring'''




			__lowerCAmelCase				    =			list(range(lowercase_      )      )
			__lowerCAmelCase				    =			int(ceil(n_layers / len(lowercase_      )      )      )
			__lowerCAmelCase				    =			[layers[i : i + n_blocks] for i in range(0    , lowercase_    , lowercase_      )]

			return dict(zip(lowercase_    , lowercase_      )      )










import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowerCamelCase	:		Any							       =   logging.get_logger(__name__)


class 				UpperCamelCase_    ( UpperCAmelCase__     ):

    '''simple docstring'''






    UpperCAmelCase__							  =      '''encoder-decoder'''
    UpperCAmelCase__							  =      True


    def __init__(			self      :	List[str]					, **UpperCAmelCase__      :	Union[str, Any])						->List[Any]:





           '''simple docstring'''

           super().__init__(**UpperCAmelCase__)
           assert (
               "encoder" in kwargs and "decoder" in kwargs
           ), "Config has to be initialized with encoder and decoder config"
           A__       =    kwargs.pop('''encoder''')
           A__       =    encoder_config.pop('''model_type''')
           A__       =    kwargs.pop('''decoder''')
           A__       =    decoder_config.pop('''model_type''')

           from ..auto.configuration_auto import AutoConfig

           A__       =    AutoConfig.for_model(UpperCAmelCase__					, **UpperCAmelCase__)
           A__       =    AutoConfig.for_model(UpperCAmelCase__					, **UpperCAmelCase__)
           A__       =    True


    @classmethod
    def        SCREAMING_SNAKE_CASE							(			cls      :	Union[str, Any]					, UpperCAmelCase__      :	PretrainedConfig					, UpperCAmelCase__      :	PretrainedConfig					, **UpperCAmelCase__      :	Union[str, Any])						->PretrainedConfig:





           '''simple docstring'''

           logger.info('''Set `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config''')
           A__       =    True
           A__       =    True

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





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





           '''simple docstring'''

           A__       =    copy.deepcopy(self.__dict__)
           A__       =    self.encoder.to_dict()
           A__       =    self.decoder.to_dict()
           A__       =    self.__class__.model_type
           return output


