



'''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

lowercase_		       =  logging.get_logger(__name__)






class __A			(  __lowerCamelCase						):



 '''simple docstring'''







 __lowerCamelCase    :       int          =       'vision-encoder-decoder'
 __lowerCamelCase    :       Union[str, Any]          =       True



 def __init__(self ,   **A       )    ->     List[Any]:


      """simple docstring"""



      super().__init__(**UpperCamelCase_       )
      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}'''       )

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

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



 @classmethod
 def 					a__  (cls ,   A ,   A ,   **A       )    ->     int:


      """simple docstring"""



      logger.info('''Setting `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 					a__  (self       )    ->     int:


      """simple docstring"""



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






class __A			(  __lowerCamelCase						):



 '''simple docstring'''







 __lowerCamelCase    :       Tuple          =       version.parse('1.11'						)



 @property
 def 					a__  (self       )    ->     Dict:


      """simple docstring"""



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



 @property
 def 					a__  (self       )    ->     int:


      """simple docstring"""



      return 1E-4



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


      """simple docstring"""



      return OrderedDict({'''last_hidden_state''': {0: '''batch''', 1: '''encoder_sequence'''}}       )






class __A			(  __lowerCamelCase						):



 '''simple docstring'''







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


      """simple docstring"""



      _a      =  OrderedDict()
      _a      =  {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
      _a      =  {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
      _a      =  {0: '''batch''', 1: '''encoder_sequence'''}

      return common_inputs



 def 					a__  (self ,   A ,   A = -1 ,   A = -1 ,   A = False ,   A = None ,   )    ->     Union[str, Any]:


      """simple docstring"""



      import torch

      _a      =  OrderedDict()

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

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

      return common_inputs






class __A			(  __lowerCamelCase						):



 '''simple docstring'''







 @property
 def 					a__  (self       )    ->     int:


      """simple docstring"""



      pass



 def 					a__  (self ,   A       )    ->     List[Any]:


      """simple docstring"""



      return VisionEncoderDecoderEncoderOnnxConfig(UpperCamelCase_       )



 def 					a__  (self ,   A ,   A ,   A = "default"       )    ->     Any:


      """simple docstring"""



      _a      =  encoder_config.hidden_size
      return VisionEncoderDecoderDecoderOnnxConfig(UpperCamelCase_ ,   UpperCamelCase_       )









from __future__ import annotations




def 					lowerCamelCase__       (						A__       :					list[int | float]  ,			A__       :					int  ,			A__       :					int	):





       '''simple docstring'''



       if len(A__	) == 0:
              raise ValueError("""find_max() arg is an empty sequence"""	)
       if (
           left >= len(A__	)
           or left < -len(A__	)
           or right >= len(A__	)
           or right < -len(A__	)
       ):
              raise IndexError("""list index out of range"""	)
       if left == right:
              return nums[left]
       __lowerCamelCase   =						(left + right) >> 1  # the middle
       __lowerCamelCase   =						find_max(A__  ,			A__  ,			A__	)  # find max in range[left, mid]
       __lowerCamelCase   =						find_max(A__  ,			mid + 1  ,			A__	)  # find max in range[mid + 1, right]

       return left_max if left_max >= right_max else right_max


if __name__ == "__main__":
       import doctest

       doctest.testmod(verbose=True)

