

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

snake_case_   :   Tuple        =       logging.get_logger(__name__)







class       snake_case__  ( lowerCAmelCase_     ):
			SCREAMING_SNAKE_CASE__     				=						'''vision-encoder-decoder'''
			SCREAMING_SNAKE_CASE__     				=						True







			def __init__(			self			: List[str]			,  **lowercase			: List[Any]  ):





								'''simple docstring'''



								super().__init__(**lowercase  )
								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			:   Any      =				kwargs.pop("encoder"  )
								UpperCAmelCase			:   Optional[Any]      =				encoder_config.pop("model_type"  )
								UpperCAmelCase			:   List[Any]      =				kwargs.pop("decoder"  )
								UpperCAmelCase			:   List[str]      =				decoder_config.pop("model_type"  )

								UpperCAmelCase			:   List[str]      =				AutoConfig.for_model(lowercase			,  **lowercase  )
								UpperCAmelCase			:   Union[str, Any]      =				AutoConfig.for_model(lowercase			,  **lowercase  )
								UpperCAmelCase			:   List[str]      =				True







			@classmethod
			def 			__lowerCAmelCase				(			cls			: Union[str, Any]			,  lowercase			: PretrainedConfig			,  lowercase			: PretrainedConfig			,  **lowercase			: Tuple  ):





								'''simple docstring'''



								logger.info("Setting `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config"  )
								UpperCAmelCase			:   List[Any]      =				True
								UpperCAmelCase			:   Tuple      =				True

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







			def 			__lowerCAmelCase				(			self			: List[Any]  ):





								'''simple docstring'''



								UpperCAmelCase			:   List[Any]      =				copy.deepcopy(self.__dict__  )
								UpperCAmelCase			:   Union[str, Any]      =				self.encoder.to_dict()
								UpperCAmelCase			:   str      =				self.decoder.to_dict()
								UpperCAmelCase			:   Any      =				self.__class__.model_type
								return output







class       snake_case__  ( lowerCAmelCase_     ):
			SCREAMING_SNAKE_CASE__     				=						version.parse('''1.11'''     )







			@property
			def 			__lowerCAmelCase				(			self			: int  ):





								'''simple docstring'''



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







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





								'''simple docstring'''



								return 1E-4







			@property
			def 			__lowerCAmelCase				(			self			: str  ):





								'''simple docstring'''



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







class       snake_case__  ( lowerCAmelCase_     ):







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





								'''simple docstring'''



								UpperCAmelCase			:   Any      =				OrderedDict()
								UpperCAmelCase			:   str      =				{0: "batch", 1: "past_decoder_sequence + sequence"}
								UpperCAmelCase			:   int      =				{0: "batch", 1: "past_decoder_sequence + sequence"}
								UpperCAmelCase			:   Tuple      =				{0: "batch", 1: "encoder_sequence"}

								return common_inputs







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





								'''simple docstring'''



								import torch

								UpperCAmelCase			:   Dict      =				OrderedDict()

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

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

								return common_inputs







class       snake_case__  ( lowerCAmelCase_     ):







			@property
			def 			__lowerCAmelCase				(			self			: Any  ):





								'''simple docstring'''



								pass







			def 			__lowerCAmelCase				(			self			: Optional[int]			,  lowercase			: PretrainedConfig  ):





								'''simple docstring'''



								return VisionEncoderDecoderEncoderOnnxConfig(lowercase  )







			def 			__lowerCAmelCase				(			self			: List[Any]			,  lowercase			: PretrainedConfig			,  lowercase			: PretrainedConfig			,  lowercase			: str = "default"  ):





								'''simple docstring'''



								UpperCAmelCase			:   str      =				encoder_config.hidden_size
								return VisionEncoderDecoderDecoderOnnxConfig(lowercase			,  lowercase  )





"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


snake_case_   :   Dict        =       {
    """configuration_mvp""": ["""MVP_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MvpConfig""", """MvpOnnxConfig"""],
    """tokenization_mvp""": ["""MvpTokenizer"""],
}

try:
	if not is_tokenizers_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	snake_case_   :   List[Any]        =       ["""MvpTokenizerFast"""]

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	snake_case_   :   Any        =       [
	    """MVP_PRETRAINED_MODEL_ARCHIVE_LIST""",
	    """MvpForCausalLM""",
	    """MvpForConditionalGeneration""",
	    """MvpForQuestionAnswering""",
	    """MvpForSequenceClassification""",
	    """MvpModel""",
	    """MvpPreTrainedModel""",
	]

if TYPE_CHECKING:
	from .configuration_mvp import MVP_PRETRAINED_CONFIG_ARCHIVE_MAP, MvpConfig, MvpOnnxConfig
	from .tokenization_mvp import MvpTokenizer

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_mvp_fast import MvpTokenizerFast

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_mvp import (
		    MVP_PRETRAINED_MODEL_ARCHIVE_LIST,
		    MvpForCausalLM,
		    MvpForConditionalGeneration,
		    MvpForQuestionAnswering,
		    MvpForSequenceClassification,
		    MvpModel,
		    MvpPreTrainedModel,
		)

else:
	import sys

	snake_case_   :   List[str]        =       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


