



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

A_							: str						 =	logging.get_logger(__name__)



class 							lowercase       (  _lowerCamelCase				):


 """simple docstring"""


 UpperCAmelCase							=  """vision-encoder-decoder"""
 UpperCAmelCase							=  True







 def __init__(							self  ,**a_							)		->   Union[str, Any]:
        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}'''							)

        _UpperCAmelCase  :						Tuple			     = kwargs.pop("""encoder"""							)
        _UpperCAmelCase  :						Dict			     = encoder_config.pop("""model_type"""							)
        _UpperCAmelCase  :						Any			     = kwargs.pop("""decoder"""							)
        _UpperCAmelCase  :						Any			     = decoder_config.pop("""model_type"""							)

        _UpperCAmelCase  :						Union[str, Any]			     = AutoConfig.for_model(a_  ,**a_							)
        _UpperCAmelCase  :						Optional[int]			     = AutoConfig.for_model(a_  ,**a_							)
        _UpperCAmelCase  :						List[Any]			     = True







 @classmethod
 def _snake_case (							cls  ,a_  ,a_  ,**a_							)		->   Union[str, Any]:
        logger.info("""Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config"""							)
        _UpperCAmelCase  :						Any			     = True
        _UpperCAmelCase  :						List[str]			     = True

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







 def _snake_case (							self							)		->   int:
        _UpperCAmelCase  :						int			     = copy.deepcopy(self.__dict__							)
        _UpperCAmelCase  :						str			     = self.encoder.to_dict()
        _UpperCAmelCase  :						Optional[int]			     = self.decoder.to_dict()
        _UpperCAmelCase  :						Optional[Any]			     = self.__class__.model_type
        return output







class 							lowercase       (  _lowerCamelCase				):


 """simple docstring"""


 UpperCAmelCase							=  version.parse("""1.11"""				)







 @property
 def _snake_case (							self							)		->   str:
        return OrderedDict(
            [
                ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
            ]							)







 @property
 def _snake_case (							self							)		->   Optional[int]:
        return 1E-4







 @property
 def _snake_case (							self							)		->   List[str]:
        return OrderedDict({"""last_hidden_state""": {0: """batch""", 1: """encoder_sequence"""}}							)







class 							lowercase       (  _lowerCamelCase				):


 """simple docstring"""


 @property
 def _snake_case (							self							)		->   Union[str, Any]:
        _UpperCAmelCase  :						Optional[int]			     = OrderedDict()
        _UpperCAmelCase  :						Optional[int]			     = {0: 'batch', 1: 'past_decoder_sequence + sequence'}
        _UpperCAmelCase  :						Optional[Any]			     = {0: 'batch', 1: 'past_decoder_sequence + sequence'}
        _UpperCAmelCase  :						Dict			     = {0: 'batch', 1: 'encoder_sequence'}

        return common_inputs







 def _snake_case (							self  ,a_  ,a_ = -1  ,a_ = -1  ,a_ = False  ,a_ = None  ,)		->   int:
        import torch

        _UpperCAmelCase  :						List[str]			     = OrderedDict()

        _UpperCAmelCase  :						Any			     = super().generate_dummy_inputs(
            a_  ,batch_size=a_  ,seq_length=a_  ,is_pair=a_  ,framework=a_							)

        _UpperCAmelCase  :						List[Any]			     = dummy_input['input_ids'].shape
        _UpperCAmelCase  :						Union[str, Any]			     = (batch, encoder_sequence, self._config.encoder_hidden_size)
        _UpperCAmelCase  :						List[str]			     = dummy_input.pop("""input_ids"""							)
        _UpperCAmelCase  :						Dict			     = dummy_input.pop("""attention_mask"""							)
        _UpperCAmelCase  :						List[str]			     = torch.zeros(a_							)

        return common_inputs







class 							lowercase       (  _lowerCamelCase				):


 """simple docstring"""


 @property
 def _snake_case (							self							)		->   str:
        pass







 def _snake_case (							self  ,a_							)		->   Union[str, Any]:
        return VisionEncoderDecoderEncoderOnnxConfig(a_							)







 def _snake_case (							self  ,a_  ,a_  ,a_ = "default"							)		->   Optional[Any]:
        _UpperCAmelCase  :						Any			     = encoder_config.hidden_size
        return VisionEncoderDecoderDecoderOnnxConfig(a_  ,a_							)





import os
from distutils.util import strtobool
def  lowerCAmelCase__			(  SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_     )				->		Optional[Any]:
			for e in env_keys:
						lowerCAmelCase__      :      Union[str, Any]         =		int(os.environ.get(SCREAMING_SNAKE_CASE_       ,							-1     )     )
						if val >= 0:
									return val
			return default
def  lowerCAmelCase__			(  SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_=False     )				->		List[str]:
			lowerCAmelCase__      :      Optional[int]         =		os.environ.get(SCREAMING_SNAKE_CASE_       ,							str(SCREAMING_SNAKE_CASE_     )     )
			return strtobool(SCREAMING_SNAKE_CASE_     ) == 1  # As its name indicates `strtobool` actually returns an int...







def  lowerCAmelCase__			(  SCREAMING_SNAKE_CASE_       ,							SCREAMING_SNAKE_CASE_="no"     )				->		List[str]:
			lowerCAmelCase__      :      Optional[int]         =		os.environ.get(SCREAMING_SNAKE_CASE_       ,							str(SCREAMING_SNAKE_CASE_     )     )
			return value