


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

UpperCAmelCase						:		Union[str, Any]			= logging.get_logger(__name__)


class    SCREAMING_SNAKE_CASE__ (							__UpperCAmelCase   ):
    lowercase__      =   "vision-encoder-decoder"
    lowercase__      =   True

    def __init__(				self			:				int ,  **lowerCAmelCase_			:				Dict):







      """simple docstring"""







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

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

      lowercase_								= AutoConfig.for_model(lowerCAmelCase_ ,  **lowerCAmelCase_)
      lowercase_								= AutoConfig.for_model(lowerCAmelCase_ ,  **lowerCAmelCase_)
      lowercase_								= True

    @classmethod
    def 					_UpperCAmelCase	(				cls			:				Dict ,  lowerCAmelCase_			:				PretrainedConfig ,  lowerCAmelCase_			:				PretrainedConfig ,  **lowerCAmelCase_			:				Optional[int]):







      """simple docstring"""







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

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




    def 					_UpperCAmelCase	(				self			:				str):







      """simple docstring"""







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







class    SCREAMING_SNAKE_CASE__ (							__UpperCAmelCase   ):
    lowercase__      =   version.parse("1.11"   )

    @property
    def 					_UpperCAmelCase	(				self			:				Any):







      """simple docstring"""







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

    @property
    def 					_UpperCAmelCase	(				self			:				int):







      """simple docstring"""







      return 1E-4




    @property
    def 					_UpperCAmelCase	(				self			:				Dict):







      """simple docstring"""







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







class    SCREAMING_SNAKE_CASE__ (							__UpperCAmelCase   ):

    @property
    def 					_UpperCAmelCase	(				self			:				Any):







      """simple docstring"""







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

      return common_inputs




    def 					_UpperCAmelCase	(				self			:				Dict ,  lowerCAmelCase_			:				"PreTrainedTokenizerBase" ,  lowerCAmelCase_			:				int = -1 ,  lowerCAmelCase_			:				int = -1 ,  lowerCAmelCase_			:				bool = False ,  lowerCAmelCase_			:				Optional["TensorType"] = None ,  ):







      """simple docstring"""







      import torch

      lowercase_								= OrderedDict()

      lowercase_								= super().generate_dummy_inputs(
          lowerCAmelCase_ ,  batch_size=lowerCAmelCase_ ,  seq_length=lowerCAmelCase_ ,  is_pair=lowerCAmelCase_ ,  framework=lowerCAmelCase_)

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

      return common_inputs







class    SCREAMING_SNAKE_CASE__ (							__UpperCAmelCase   ):

    @property
    def 					_UpperCAmelCase	(				self			:				str):







      """simple docstring"""







      pass

    def 					_UpperCAmelCase	(				self			:				Any ,  lowerCAmelCase_			:				PretrainedConfig):







      """simple docstring"""







      return VisionEncoderDecoderEncoderOnnxConfig(lowerCAmelCase_)




    def 					_UpperCAmelCase	(				self			:				Any ,  lowerCAmelCase_			:				PretrainedConfig ,  lowerCAmelCase_			:				PretrainedConfig ,  lowerCAmelCase_			:				str = "default"):







      """simple docstring"""







      lowercase_								= encoder_config.hidden_size
      return VisionEncoderDecoderDecoderOnnxConfig(lowerCAmelCase_ ,  lowerCAmelCase_)






"""simple docstring"""
from ..utils import DummyObject, requires_backends


class    SCREAMING_SNAKE_CASE__ (							metaclass=__UpperCAmelCase   ):
    lowercase__      =   ["keras_nlp"]

    def __init__(				self			:				Dict ,  *lowerCAmelCase_			:				List[str] ,  **lowerCAmelCase_			:				Tuple):







      """simple docstring"""







      requires_backends(self ,  ["""keras_nlp"""])

