




"""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													=      logging.get_logger(__name__)


class _lowerCamelCase    (					a_						):
   _lowerCamelCase    :Any     				=     "vision-encoder-decoder"
   _lowerCamelCase    :Any     				=     True






   def __init__(		self       :		Any   ,     **UpperCamelCase       :		List[Any]   )			->						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}"""   )

         lowerCAmelCase__      :			Tuple   =	kwargs.pop("""encoder"""   )
         lowerCAmelCase__      :			Optional[Any]   =	encoder_config.pop("""model_type"""   )
         lowerCAmelCase__      :			Tuple   =	kwargs.pop("""decoder"""   )
         lowerCAmelCase__      :			Optional[Any]   =	decoder_config.pop("""model_type"""   )

         lowerCAmelCase__      :			Union[str, Any]   =	AutoConfig.for_model(UpperCamelCase   ,     **UpperCamelCase   )
         lowerCAmelCase__      :			str   =	AutoConfig.for_model(UpperCamelCase   ,     **UpperCamelCase   )
         lowerCAmelCase__      :			Tuple   =	True






   @classmethod
   def 	_lowerCAmelCase   (		cls       :		Any   ,     UpperCamelCase       :		PretrainedConfig   ,     UpperCamelCase       :		PretrainedConfig   ,     **UpperCamelCase       :		Any   )			->						PretrainedConfig:

         """simple docstring"""
         logger.info("""Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config"""   )
         lowerCAmelCase__      :			Dict   =	True
         lowerCAmelCase__      :			Optional[Any]   =	True

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






   def 	_lowerCAmelCase   (		self       :		Optional[int]   )			->						Any:

         """simple docstring"""
         lowerCAmelCase__      :			Dict   =	copy.deepcopy(self.__dict__   )
         lowerCAmelCase__      :			List[Any]   =	self.encoder.to_dict()
         lowerCAmelCase__      :			Optional[Any]   =	self.decoder.to_dict()
         lowerCAmelCase__      :			Union[str, Any]   =	self.__class__.model_type
         return output






class _lowerCamelCase    (					a_						):
   _lowerCamelCase    :List[Any]     				=     version.parse("1.11"						)






   @property
   def 	_lowerCAmelCase   (		self       :		Tuple   )			->						Mapping[str, Mapping[int, str]]:

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






   @property
   def 	_lowerCAmelCase   (		self       :		Optional[Any]   )			->						float:

         """simple docstring"""
         return 1E-4






   @property
   def 	_lowerCAmelCase   (		self       :		int   )			->						Mapping[str, Mapping[int, str]]:

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






class _lowerCamelCase    (					a_						):






   @property
   def 	_lowerCAmelCase   (		self       :		Dict   )			->						Mapping[str, Mapping[int, str]]:

         """simple docstring"""
         lowerCAmelCase__      :			str   =	OrderedDict()
         lowerCAmelCase__      :			Optional[int]   =	{0: """batch""", 1: """past_decoder_sequence + sequence"""}
         lowerCAmelCase__      :			Union[str, Any]   =	{0: """batch""", 1: """past_decoder_sequence + sequence"""}
         lowerCAmelCase__      :			Optional[int]   =	{0: """batch""", 1: """encoder_sequence"""}

         return common_inputs






   def 	_lowerCAmelCase   (		self       :		List[Any]   ,     UpperCamelCase       :		"PreTrainedTokenizerBase"   ,     UpperCamelCase       :		int = -1   ,     UpperCamelCase       :		int = -1   ,     UpperCamelCase       :		bool = False   ,     UpperCamelCase       :		Optional["TensorType"] = None   ,     )			->						Mapping[str, Any]:

         """simple docstring"""
         import torch

         lowerCAmelCase__      :			Any   =	OrderedDict()

         lowerCAmelCase__      :			Tuple   =	super().generate_dummy_inputs(
             UpperCamelCase   ,     batch_size=UpperCamelCase   ,     seq_length=UpperCamelCase   ,     is_pair=UpperCamelCase   ,     framework=UpperCamelCase   )

         lowerCAmelCase__ ,   lowerCAmelCase__      :			Any   =	dummy_input["""input_ids"""].shape
         lowerCAmelCase__      :			List[Any]   =	(batch, encoder_sequence, self._config.encoder_hidden_size)
         lowerCAmelCase__      :			Dict   =	dummy_input.pop("""input_ids"""   )
         lowerCAmelCase__      :			Any   =	dummy_input.pop("""attention_mask"""   )
         lowerCAmelCase__      :			Any   =	torch.zeros(UpperCamelCase   )

         return common_inputs






class _lowerCamelCase    (					a_						):






   @property
   def 	_lowerCAmelCase   (		self       :		int   )			->						None:

         """simple docstring"""
         pass






   def 	_lowerCAmelCase   (		self       :		Optional[Any]   ,     UpperCamelCase       :		PretrainedConfig   )			->						OnnxConfig:

         """simple docstring"""
         return VisionEncoderDecoderEncoderOnnxConfig(UpperCamelCase   )






   def 	_lowerCAmelCase   (		self       :		Dict   ,     UpperCamelCase       :		PretrainedConfig   ,     UpperCamelCase       :		PretrainedConfig   ,     UpperCamelCase       :		str = "default"   )			->						OnnxConfig:

         """simple docstring"""
         lowerCAmelCase__      :			List[Any]   =	encoder_config.hidden_size
         return VisionEncoderDecoderDecoderOnnxConfig(UpperCamelCase   ,     UpperCamelCase   )











"""simple docstring"""


import warnings

from ...utils import logging
from .image_processing_clip import CLIPImageProcessor


_A													=      logging.get_logger(__name__)


class _lowerCamelCase    (					a_						):






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

         """simple docstring"""
         warnings.warn(
             """The class CLIPFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please"""
             """ use CLIPImageProcessor instead."""   ,     UpperCamelCase   ,     )
         super().__init__(*UpperCamelCase   ,     **UpperCamelCase   )





