



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

SCREAMING_SNAKE_CASE__       =      logging.get_logger(__name__)


class      __lowerCAmelCase     (		lowercase__      ):
					"""simple docstring"""






					A__				:		Union[str, Any]			       =    'vision-encoder-decoder'
					A__				:		List[str]			       =    True



					def __init__(     self					:       Union[str, Any]				,					**_snake_case					:       Optional[int]					):






								"""simple docstring"""


								super().__init__(**_snake_case					)
								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(_snake_case				,					**_snake_case					)
								A__       =    AutoConfig.for_model(_snake_case				,					**_snake_case					)
								A__       =    True



					@classmethod
					def     _a							(     cls					:       Union[str, Any]				,					_snake_case					:       Dict				,					_snake_case					:       str				,					**_snake_case					:       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()				,					**_snake_case					)



					def     _a							(     self					:       Optional[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      __lowerCAmelCase     (		lowercase__      ):
					"""simple docstring"""






					A__				:		Any			       =    version.parse("1.11"      )



					@property
					def     _a							(     self					:       int					):






								"""simple docstring"""


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



					@property
					def     _a							(     self					:       Optional[Any]					):






								"""simple docstring"""


								return 1E-4



					@property
					def     _a							(     self					:       List[str]					):






								"""simple docstring"""


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







class      __lowerCAmelCase     (		lowercase__      ):
					"""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					:       List[Any]				,					_snake_case					:       Any				,					_snake_case					:       Optional[Any] = -1				,					_snake_case					:       Any = -1				,					_snake_case					:       Optional[Any] = False				,					_snake_case					:       int = None				,					):






								"""simple docstring"""


								import torch

								A__       =    OrderedDict()

								A__       =    super().generate_dummy_inputs(
								    _snake_case				,					batch_size=_snake_case				,					seq_length=_snake_case				,					is_pair=_snake_case				,					framework=_snake_case					)

								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(_snake_case					)

								return common_inputs







class      __lowerCAmelCase     (		lowercase__      ):
					"""simple docstring"""






					@property
					def     _a							(     self					:       Optional[Any]					):






								"""simple docstring"""


								pass



					def     _a							(     self					:       Optional[Any]				,					_snake_case					:       Tuple					):






								"""simple docstring"""


								return VisionEncoderDecoderEncoderOnnxConfig(_snake_case					)



					def     _a							(     self					:       int				,					_snake_case					:       List[Any]				,					_snake_case					:       Union[str, Any]				,					_snake_case					:       Any = "default"					):






								"""simple docstring"""


								A__       =    encoder_config.hidden_size
								return VisionEncoderDecoderDecoderOnnxConfig(_snake_case				,					_snake_case					)









from typing import Dict

from .base import GenericTensor, Pipeline


class      __lowerCAmelCase     (		UpperCAmelCase_      ):
					"""simple docstring"""






					def     _a							(     self					:       Any				,					_snake_case					:       str=None				,					_snake_case					:       Dict=None				,					_snake_case					:       Any=None				,					**_snake_case					:       str					):






								"""simple docstring"""


								if tokenize_kwargs is None:
											A__       =    {}

								if truncation is not None:
											if "truncation" in tokenize_kwargs:
														raise ValueError(
														    'truncation parameter defined twice (given as keyword argument as well as in tokenize_kwargs)'					)
											A__       =    truncation

								A__       =    tokenize_kwargs

								A__       =    {}
								if return_tensors is not None:
											A__       =    return_tensors

								return preprocess_params, {}, postprocess_params



					def     _a							(     self					:       Any				,					_snake_case					:       Dict				,					**_snake_case					:       Optional[Any]					):






								"""simple docstring"""


								A__       =    self.framework
								A__       =    self.tokenizer(_snake_case				,					return_tensors=_snake_case				,					**_snake_case					)
								return model_inputs



					def     _a							(     self					:       List[Any]				,					_snake_case					:       Dict					):






								"""simple docstring"""


								A__       =    self.model(**_snake_case					)
								return model_outputs



					def     _a							(     self					:       Optional[Any]				,					_snake_case					:       List[Any]				,					_snake_case					:       str=False					):






								"""simple docstring"""


								if return_tensors:
											return model_outputs[0]
								if self.framework == "pt":
											return model_outputs[0].tolist()
								elif self.framework == "tf":
											return model_outputs[0].numpy().tolist()



					def __call__(     self					:       Dict				,					*_snake_case					:       int				,					**_snake_case					:       List[str]					):






								"""simple docstring"""


								return super().__call__(*_snake_case				,					**_snake_case					)




