




"""simple docstring"""




import copy
from typing import TYPE_CHECKING, Any, Mapping, Optional, OrderedDict

from packaging import version

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


if TYPE_CHECKING:
					from ... import PreTrainedTokenizerBase, TensorType

lowerCAmelCase							:    Optional[Any]  							=							logging.get_logger(__name__)






class 					__magic_name__							( UpperCAmelCase__       ):






				'''simple docstring'''
				__UpperCamelCase    						=		"vision-encoder-decoder"
				__UpperCamelCase    						=		True





				def __init__( self	,				**_a				):





							"""simple docstring"""
							super().__init__(**_a				)
							if "encoder" not in kwargs or "decoder" not in kwargs:
										raise ValueError(
										    f'A configuraton of type {self.model_type} cannot be instantiated because '
										    f'not both `encoder` and `decoder` sub-configurations are passed, but only {kwargs}'				)

							lowerCamelCase       =      kwargs.pop("""encoder"""				)
							lowerCamelCase       =      encoder_config.pop("""model_type"""				)
							lowerCamelCase       =      kwargs.pop("""decoder"""				)
							lowerCamelCase       =      decoder_config.pop("""model_type"""				)

							lowerCamelCase       =      AutoConfig.for_model(_a	,				**_a				)
							lowerCamelCase       =      AutoConfig.for_model(_a	,				**_a				)
							lowerCamelCase       =      True





				@classmethod
				def      _lowerCAmelCase       ( cls	,				_a	,				_a	,				**_a				):





							"""simple docstring"""
							logger.info("""Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config"""				)
							lowerCamelCase       =      True
							lowerCamelCase       =      True

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





				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							lowerCamelCase       =      copy.deepcopy(self.__dict__				)
							lowerCamelCase       =      self.encoder.to_dict()
							lowerCamelCase       =      self.decoder.to_dict()
							lowerCamelCase       =      self.__class__.model_type
							return output






class 					__magic_name__							( UpperCAmelCase__       ):






				'''simple docstring'''
				__UpperCamelCase    						=		version.parse("1.11"       )





				@property
				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							return OrderedDict(
							    [
							        ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
							    ]				)





				@property
				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							return 1e-4





				@property
				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							return OrderedDict({"""last_hidden_state""": {0: """batch""", 1: """encoder_sequence"""}}				)






class 					__magic_name__							( UpperCAmelCase__       ):






				'''simple docstring'''





				@property
				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							lowerCamelCase       =      OrderedDict()
							lowerCamelCase       =      {0: """batch""", 1: """past_decoder_sequence + sequence"""}
							lowerCamelCase       =      {0: """batch""", 1: """past_decoder_sequence + sequence"""}
							lowerCamelCase       =      {0: """batch""", 1: """encoder_sequence"""}

							return common_inputs





				def      _lowerCAmelCase       ( self	,				_a	,				_a = -1	,				_a = -1	,				_a = False	,				_a = None	,				):





							"""simple docstring"""
							import torch

							lowerCamelCase       =      OrderedDict()

							lowerCamelCase       =      super().generate_dummy_inputs(
							    _a	,				batch_size=_a	,				seq_length=_a	,				is_pair=_a	,				framework=_a				)

							lowerCamelCase   ,     lowerCamelCase       =      dummy_input["""input_ids"""].shape
							lowerCamelCase       =      (batch, encoder_sequence, self._config.encoder_hidden_size)
							lowerCamelCase       =      dummy_input.pop("""input_ids"""				)
							lowerCamelCase       =      dummy_input.pop("""attention_mask"""				)
							lowerCamelCase       =      torch.zeros(_a				)

							return common_inputs






class 					__magic_name__							( UpperCAmelCase__       ):






				'''simple docstring'''





				@property
				def      _lowerCAmelCase       ( self				):





							"""simple docstring"""
							pass





				def      _lowerCAmelCase       ( self	,				_a				):





							"""simple docstring"""
							return VisionEncoderDecoderEncoderOnnxConfig(_a				)





				def      _lowerCAmelCase       ( self	,				_a	,				_a	,				_a = "default"				):





							"""simple docstring"""
							lowerCamelCase       =      encoder_config.hidden_size
							return VisionEncoderDecoderDecoderOnnxConfig(_a	,				_a				)









"""simple docstring"""




from __future__ import annotations



def 					a__				(       snake_case__ ,				snake_case__ = None ,				snake_case__ = None       )		->      None:
			if start is None:
						lowerCamelCase       =      0

			if end is None:
						lowerCamelCase       =      len(snake_case__       ) - 1

			if start >= end:
						return

			lowerCamelCase       =      (start + end) // 2

			slowsort(snake_case__ ,				snake_case__ ,				snake_case__       )
			slowsort(snake_case__ ,				mid + 1 ,				snake_case__       )

			if sequence[end] < sequence[mid]:
						lowerCamelCase   ,     lowerCamelCase       =      sequence[mid], sequence[end]

			slowsort(snake_case__ ,				snake_case__ ,				end - 1       )


if __name__ == "__main__":
					from doctest import testmod

					testmod()



