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

_lowercase          =						logging.get_logger(__name__)




class     UpperCAmelCase_	(						_SCREAMING_SNAKE_CASE					):






						'''simple docstring'''






						_lowercase						: Optional[int]										=  '''vision-encoder-decoder'''
						_lowercase						: Optional[Any]										=  True




						def __init__(   self       ,  **_lowercase ):

												"""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}' )

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

												_lowerCAmelCase    		=					AutoConfig.for_model(_lowercase       ,  **_lowercase )
												_lowerCAmelCase    		=					AutoConfig.for_model(_lowercase       ,  **_lowercase )
												_lowerCAmelCase    		=					True




						@classmethod
						def    _lowercase      (   cls       ,  _lowercase       ,  _lowercase       ,  **_lowercase ):

												"""simple docstring"""



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

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




						def    _lowercase      (   self ):

												"""simple docstring"""



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






class     UpperCAmelCase_	(						_SCREAMING_SNAKE_CASE					):






						'''simple docstring'''






						_lowercase						: Optional[Any]										=  version.parse('''1.11'''					)




						@property
						def    _lowercase      (   self ):

												"""simple docstring"""



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




						@property
						def    _lowercase      (   self ):

												"""simple docstring"""



												return 1e-4




						@property
						def    _lowercase      (   self ):

												"""simple docstring"""



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






class     UpperCAmelCase_	(						_SCREAMING_SNAKE_CASE					):






						'''simple docstring'''






						@property
						def    _lowercase      (   self ):

												"""simple docstring"""



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

												return common_inputs




						def    _lowercase      (   self       ,  _lowercase       ,  _lowercase = -1       ,  _lowercase = -1       ,  _lowercase = False       ,  _lowercase = None       ,  ):

												"""simple docstring"""



												import torch

												_lowerCAmelCase    		=					OrderedDict()

												_lowerCAmelCase    		=					super().generate_dummy_inputs(
												    _lowercase       ,  batch_size=_lowercase       ,  seq_length=_lowercase       ,  is_pair=_lowercase       ,  framework=_lowercase )

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

												return common_inputs






class     UpperCAmelCase_	(						_SCREAMING_SNAKE_CASE					):






						'''simple docstring'''






						@property
						def    _lowercase      (   self ):

												"""simple docstring"""



												pass




						def    _lowercase      (   self       ,  _lowercase ):

												"""simple docstring"""



												return VisionEncoderDecoderEncoderOnnxConfig(_lowercase )




						def    _lowercase      (   self       ,  _lowercase       ,  _lowercase       ,  _lowercase = "default" ):

												"""simple docstring"""



												_lowerCAmelCase    		=					encoder_config.hidden_size
												return VisionEncoderDecoderDecoderOnnxConfig(_lowercase       ,  _lowercase )





'''simple docstring'''

import math

import tensorflow as tf
from packaging import version







def a_     (    __UpperCAmelCase					)				->					Optional[Any]:





			"""simple docstring"""







			snake_case:    str      							=tf.convert_to_tensor(__UpperCAmelCase					)
			snake_case:    int      							=0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0					)				,							x.dtype					)					))

			return x * cdf







def a_     (    __UpperCAmelCase					)				->					Dict:





			"""simple docstring"""







			snake_case:    Optional[int]      							=tf.convert_to_tensor(__UpperCAmelCase					)
			snake_case:    Tuple      							=tf.cast(math.pi				,							x.dtype					)
			snake_case:    Dict      							=tf.cast(0.04_4715				,							x.dtype					)
			snake_case:    List[str]      							=0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi					) * (x + coeff * tf.pow(__UpperCAmelCase				,							3					))					))

			return x * cdf







def a_     (    __UpperCAmelCase					)				->					Tuple:





			"""simple docstring"""







			snake_case:    Optional[int]      							=tf.convert_to_tensor(__UpperCAmelCase					)

			return x * tf.tanh(tf.math.softplus(__UpperCAmelCase					)					)







def a_     (    __UpperCAmelCase					)				->					Dict:





			"""simple docstring"""







			snake_case:    List[str]      							=tf.convert_to_tensor(__UpperCAmelCase					)
			snake_case:    Dict      							=tf.cast(0.04_4715				,							x.dtype					)
			snake_case:    List[str]      							=tf.cast(0.79_7884_5608				,							x.dtype					)

			return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)					))







def a_     (    __UpperCAmelCase					)				->					Optional[Any]:





			"""simple docstring"""







			snake_case:    Union[str, Any]      							=tf.convert_to_tensor(__UpperCAmelCase					)
			snake_case:    Tuple      							=tf.cast(1.702				,							x.dtype					)
			return x * tf.math.sigmoid(coeff * x					)







def a_     (    __UpperCAmelCase					)				->					int:





			"""simple docstring"""







			return tf.clip_by_value(_gelu(__UpperCAmelCase					)				,							-10				,							10					)







def a_     (    __UpperCAmelCase				,							__UpperCAmelCase=-1					)				->					List[str]:





			"""simple docstring"""







			snake_case							,  snake_case:    int      							=tf.split(__UpperCAmelCase				,							2				,							axis=__UpperCAmelCase					)
			return a * tf.math.sigmoid(__UpperCAmelCase					)


if version.parse(tf.version.VERSION) >= version.parse('2.4'):







	def a_     (    __UpperCAmelCase					)				->					int:





				"""simple docstring"""







				return tf.keras.activations.gelu(__UpperCAmelCase				,							approximate=__UpperCAmelCase					)

	a							   =				tf.keras.activations.gelu







	a							   =				approximate_gelu_wrap
else:
	a							   =				_gelu
	a							   =				_gelu_new


a							   =				{
    'gelu': gelu,
    'gelu_10': gelu_aa,
    'gelu_fast': gelu_fast,
    'gelu_new': gelu_new,
    'glu': glu,
    'mish': mish,
    'quick_gelu': quick_gelu,
    'relu': tf.keras.activations.relu,
    'sigmoid': tf.keras.activations.sigmoid,
    'silu': tf.keras.activations.swish,
    'swish': tf.keras.activations.swish,
    'tanh': tf.keras.activations.tanh,
}







def a_     (    __UpperCAmelCase					)				->					Dict:





			"""simple docstring"""







			if activation_string in ACTaFN:
						return ACTaFN[activation_string]
			else:
						raise KeyError(f'''function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()					)}'''					)




