




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						:      Optional[Any]									= logging.get_logger(__name__)




class 				lowerCamelCase__							(       lowercase__):




	'''simple docstring'''




	_A			=  'vision-encoder-decoder'
	_A			=  True







	def __init__(      self	:int  ,     **a	:List[str]		)	->				List[str]:
								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}'		)

								__UpperCamelCase			:     Dict         =      kwargs.pop("encoder"		)
								__UpperCamelCase			:     Union[str, Any]         =      encoder_config.pop("model_type"		)
								__UpperCamelCase			:     Tuple         =      kwargs.pop("decoder"		)
								__UpperCamelCase			:     List[Any]         =      decoder_config.pop("model_type"		)

								__UpperCamelCase			:     Dict         =      AutoConfig.for_model(__lowerCamelCase  ,     **__lowerCamelCase		)
								__UpperCamelCase			:     int         =      AutoConfig.for_model(__lowerCamelCase  ,     **__lowerCamelCase		)
								__UpperCamelCase			:     Optional[int]         =      True







	@classmethod
	def      _lowerCamelCase       (      cls	:Tuple  ,     a	:PretrainedConfig  ,     a	:PretrainedConfig  ,     **a	:int		)	->				Tuple:
								logger.info("Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config"		)
								__UpperCamelCase			:     Tuple         =      True
								__UpperCamelCase			:     str         =      True

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







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




class 				lowerCamelCase__							(       lowercase__):




	'''simple docstring'''




	_A			=  version.parse('1.11')







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







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







	@property
	def      _lowerCamelCase       (      self	:str		)	->				Tuple:
								return OrderedDict({"last_hidden_state": {0: "batch", 1: "encoder_sequence"}}		)




class 				lowerCamelCase__							(       lowercase__):




	'''simple docstring'''




	@property
	def      _lowerCamelCase       (      self	:Tuple		)	->				Optional[Any]:
								__UpperCamelCase			:     List[Any]         =      OrderedDict()
								__UpperCamelCase			:     Optional[Any]         =      {0: "batch", 1: "past_decoder_sequence + sequence"}
								__UpperCamelCase			:     List[str]         =      {0: "batch", 1: "past_decoder_sequence + sequence"}
								__UpperCamelCase			:     Optional[int]         =      {0: "batch", 1: "encoder_sequence"}

								return common_inputs







	def      _lowerCamelCase       (      self	:Optional[int]  ,     a	:"PreTrainedTokenizerBase"  ,     a	:int = -1  ,     a	:int = -1  ,     a	:bool = False  ,     a	:Optional["TensorType"] = None  ,     )	->				Optional[Any]:
								import torch

								__UpperCamelCase			:     str         =      OrderedDict()

								__UpperCamelCase			:     Optional[int]         =      super().generate_dummy_inputs(
								    __lowerCamelCase  ,     batch_size=__lowerCamelCase  ,     seq_length=__lowerCamelCase  ,     is_pair=__lowerCamelCase  ,     framework=__lowerCamelCase		)

								__UpperCamelCase			:     Any         =      dummy_input["input_ids"].shape
								__UpperCamelCase			:     Optional[int]         =      (batch, encoder_sequence, self._config.encoder_hidden_size)
								__UpperCamelCase			:     Optional[int]         =      dummy_input.pop("input_ids"		)
								__UpperCamelCase			:     Dict         =      dummy_input.pop("attention_mask"		)
								__UpperCamelCase			:     Union[str, Any]         =      torch.zeros(__lowerCamelCase		)

								return common_inputs




class 				lowerCamelCase__							(       lowercase__):




	'''simple docstring'''




	@property
	def      _lowerCamelCase       (      self	:Tuple		)	->				List[str]:
								pass







	def      _lowerCamelCase       (      self	:List[Any]  ,     a	:PretrainedConfig		)	->				int:
								return VisionEncoderDecoderEncoderOnnxConfig(__lowerCamelCase		)







	def      _lowerCamelCase       (      self	:str  ,     a	:PretrainedConfig  ,     a	:PretrainedConfig  ,     a	:str = "default"		)	->				Tuple:
								__UpperCamelCase			:     Union[str, Any]         =      encoder_config.hidden_size
								return VisionEncoderDecoderDecoderOnnxConfig(__lowerCamelCase  ,     __lowerCamelCase		)

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowercase						:      Optional[Any]									= {
    'configuration_blip_2': [
        'BLIP_2_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'Blip2Config',
        'Blip2QFormerConfig',
        'Blip2VisionConfig',
    ],
    'processing_blip_2': ['Blip2Processor'],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase						:      Tuple									= [
		    'BLIP_2_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'Blip2Model',
		    'Blip2QFormerModel',
		    'Blip2PreTrainedModel',
		    'Blip2ForConditionalGeneration',
		    'Blip2VisionModel',
		]

if TYPE_CHECKING:
		from .configuration_blip_a import (
		    BLIP_2_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    BlipaConfig,
		    BlipaQFormerConfig,
		    BlipaVisionConfig,
		)
		from .processing_blip_a import BlipaProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_blip_a import (
				    BLIP_2_PRETRAINED_MODEL_ARCHIVE_LIST,
				    BlipaForConditionalGeneration,
				    BlipaModel,
				    BlipaPreTrainedModel,
				    BlipaQFormerModel,
				    BlipaVisionModel,
				)

else:
		import sys

		lowercase						:      Dict									= _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)