




"""simple docstring"""

from importlib import import_module

from .logging import get_logger


_lowerCamelCase  :			Optional[int]        =       get_logger(__name__)

class        lowercase      :







				def __init__(							self   :					Any      ,     _lowerCamelCase   :					Any      ,     _lowerCamelCase   :					Optional[Any]=None       ):



					"""simple docstring"""

					A_  :				Union[str, Any]	   =		attrs or []
					if module is not None:
						for key in module.__dict__:
							if key in attrs or not key.startswith('''__'''       ):
								setattr(self      ,     lowerCamelCase_      ,     getattr(lowerCamelCase_      ,     lowerCamelCase_       )       )
					A_  :				Any	   =		module._original_module if isinstance(lowerCamelCase_      ,     _PatchedModuleObj       ) else module

class        lowercase      :
				__lowerCAmelCase    :    List[Any]         =   []







				def __init__(							self   :					Tuple      ,     _lowerCamelCase   :					Tuple      ,     _lowerCamelCase   :					str      ,     _lowerCamelCase   :					int      ,     _lowerCamelCase   :					Any=None       ):



					"""simple docstring"""

					A_  :				List[str]	   =		obj
					A_  :				List[Any]	   =		target
					A_  :				int	   =		new
					A_  :				List[Any]	   =		target.split('''.'''       )[0]
					A_  :				Optional[Any]	   =		{}
					A_  :				List[str]	   =		attrs or []







				def __enter__(							self   :					int       ):



					"""simple docstring"""

					A_  :				Union[str, Any]	   =		self.target.split('''.'''       )

					# Patch modules:
					# it's used to patch attributes of submodules like "os.path.join";
					# in this case we need to patch "os" and "os.path"

					for i in range(len(lowerCamelCase_       )       ):
						try:
							A_  :				Optional[Any]	   =		import_module('''.'''.join(submodules[: i + 1]       )       )
						except ModuleNotFoundError:
							continue
						# We iterate over all the globals in self.obj in case we find "os" or "os.path"
						for attr in self.obj.__dir__():
							A_  :				Optional[Any]	   =		getattr(self.obj      ,     lowerCamelCase_       )
							# We don't check for the name of the global, but rather if its value *is* "os" or "os.path".
							# This allows to patch renamed modules like "from os import path as ospath".
							if obj_attr is submodule or (
							    (isinstance(lowerCamelCase_      ,     _PatchedModuleObj       ) and obj_attr._original_module is submodule)
							):
								A_  :				Optional[int]	   =		obj_attr
								# patch at top level
								setattr(self.obj      ,     lowerCamelCase_      ,     _PatchedModuleObj(lowerCamelCase_      ,     attrs=self.attrs       )       )
								A_  :				Optional[int]	   =		getattr(self.obj      ,     lowerCamelCase_       )
								# construct lower levels patches
								for key in submodules[i + 1 :]:
									setattr(lowerCamelCase_      ,     lowerCamelCase_      ,     _PatchedModuleObj(getattr(lowerCamelCase_      ,     lowerCamelCase_      ,     lowerCamelCase_       )      ,     attrs=self.attrs       )       )
									A_  :				Optional[Any]	   =		getattr(lowerCamelCase_      ,     lowerCamelCase_       )
								# finally set the target attribute
								setattr(lowerCamelCase_      ,     lowerCamelCase_      ,     self.new       )

        # Patch attribute itself:
        # it's used for builtins like "open",
        # and also to patch "os.path.join" we may also need to patch "join"
        # itself if it was imported as "from os.path import join".

					if submodules:  # if it's an attribute of a submodule like "os.path.join"
						try:
							A_  :				str	   =		getattr(import_module('''.'''.join(lowerCamelCase_       )       )      ,     lowerCamelCase_       )
						except (AttributeError, ModuleNotFoundError):
							return
						# We iterate over all the globals in self.obj in case we find "os.path.join"
						for attr in self.obj.__dir__():
							# We don't check for the name of the global, but rather if its value *is* "os.path.join".
							# This allows to patch renamed attributes like "from os.path import join as pjoin".
							if getattr(self.obj      ,     lowerCamelCase_       ) is attr_value:
								A_  :				Optional[int]	   =		getattr(self.obj      ,     lowerCamelCase_       )
								setattr(self.obj      ,     lowerCamelCase_      ,     self.new       )
					elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
						A_  :				Union[str, Any]	   =		globals()["""__builtins__"""][target_attr]
						setattr(self.obj      ,     lowerCamelCase_      ,     self.new       )
					else:
						raise RuntimeError(F"""Tried to patch attribute {target_attr} instead of a submodule."""       )







				def __exit__(							self   :					Dict      ,     *_lowerCamelCase   :					List[str]       ):



					"""simple docstring"""

					for attr in list(self.original       ):
						setattr(self.obj      ,     lowerCamelCase_      ,     self.original.pop(lowerCamelCase_       )       )







				def 					a_  (							self   :					Tuple       ):



					"""simple docstring"""

					self.__enter__()
					self._active_patches.append(self       )







				def 					a_  (							self   :					int       ):



					"""simple docstring"""

					try:
						self._active_patches.remove(self       )
					except ValueError:
						# If the patch hasn't been started this will fail
						return None

					return self.__exit__()











"""simple docstring"""

from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxSeqaSeqConfigWithPast
from ...utils import logging


_lowerCamelCase  :			List[str]        =       logging.get_logger(__name__)

_lowerCamelCase  :			str        =       {
    'google/umt5-small': 'https://huggingface.co/google/umt5-small/resolve/main/config.json',
    # See all umt5 models at https://huggingface.co/models?filter=umt5
}

class        lowercase      (    __UpperCAmelCase):
				__lowerCAmelCase    :    int         =   """umt5"""
				__lowerCAmelCase    :    List[str]         =   ["""past_key_values"""]







				def __init__(							self   :					Any      ,     _lowerCamelCase   :					Union[str, Any]=25_01_12      ,     _lowerCamelCase   :					Any=5_12      ,     _lowerCamelCase   :					Optional[int]=64      ,     _lowerCamelCase   :					str=10_24      ,     _lowerCamelCase   :					List[str]=8      ,     _lowerCamelCase   :					Union[str, Any]=None      ,     _lowerCamelCase   :					Any=6      ,     _lowerCamelCase   :					List[Any]=32      ,     _lowerCamelCase   :					Optional[Any]=1_28      ,     _lowerCamelCase   :					int=0.1      ,     _lowerCamelCase   :					Union[str, Any]=1E-6      ,     _lowerCamelCase   :					Tuple=1.0      ,     _lowerCamelCase   :					Optional[int]="gated-gelu"      ,     _lowerCamelCase   :					List[str]=True      ,     _lowerCamelCase   :					str=True      ,     _lowerCamelCase   :					Tuple="T5Tokenizer"      ,     _lowerCamelCase   :					Optional[int]=True      ,     _lowerCamelCase   :					Optional[int]=0      ,     _lowerCamelCase   :					Tuple=1      ,     _lowerCamelCase   :					Tuple=0      ,     **_lowerCamelCase   :					List[str]      ,     ):



					"""simple docstring"""

					super().__init__(
					    is_encoder_decoder=_lowerCamelCase      ,     tokenizer_class=_lowerCamelCase      ,     tie_word_embeddings=_lowerCamelCase      ,     pad_token_id=_lowerCamelCase      ,     eos_token_id=_lowerCamelCase      ,     decoder_start_token_id=_lowerCamelCase      ,     **_lowerCamelCase      ,     )
					A_  :				str	   =		vocab_size
					A_  :				List[Any]	   =		d_model
					A_  :				Optional[int]	   =		d_kv
					A_  :				int	   =		d_ff
					A_  :				Union[str, Any]	   =		num_layers
					A_  :				Optional[Any]	   =		(
					    num_decoder_layers if num_decoder_layers is not None else self.num_layers
					)  # default = symmetry
					A_  :				Dict	   =		num_heads
					A_  :				Optional[int]	   =		relative_attention_num_buckets
					A_  :				Union[str, Any]	   =		relative_attention_max_distance
					A_  :				Any	   =		dropout_rate
					A_  :				Optional[int]	   =		layer_norm_epsilon
					A_  :				Tuple	   =		initializer_factor
					A_  :				Optional[int]	   =		feed_forward_proj
					A_  :				Dict	   =		use_cache

					A_  :				Any	   =		self.feed_forward_proj.split('''-'''       )
					A_  :				Tuple	   =		act_info[-1]
					A_  :				Any	   =		act_info[0] == '''gated'''

					if len(_lowerCamelCase       ) > 1 and act_info[0] != "gated" or len(_lowerCamelCase       ) > 2:
						raise ValueError(
						    F"""`feed_forward_proj`: {feed_forward_proj} is not a valid activation function of the dense layer."""
						    '''Please make sure `feed_forward_proj` is of the format `gated-{ACT_FN}` or `{ACT_FN}`, e.g. '''
						    '''\'gated-gelu\' or \'relu\''''       )

					if feed_forward_proj == "gated-gelu":
						A_  :				Dict	   =		'''gelu_new'''







				@property
				def 					a_  (							self   :					Tuple       ):



					"""simple docstring"""

					return self.d_model







				@property
				def 					a_  (							self   :					Optional[int]       ):



					"""simple docstring"""

					return self.num_heads







				@property
				def 					a_  (							self   :					int       ):



					"""simple docstring"""

					return self.num_layers

class        lowercase      (    __UpperCAmelCase):







				@property
				# Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.inputs
				def 					a_  (							self   :					Any       ):



					"""simple docstring"""

					A_  :				str	   =		{
					    '''input_ids''': {0: '''batch''', 1: '''encoder_sequence'''},
					    '''attention_mask''': {0: '''batch''', 1: '''encoder_sequence'''},
					}
					if self.use_past:
						A_  :				Optional[Any]	   =		'''past_encoder_sequence + sequence'''
						A_  :				Optional[Any]	   =		{0: '''batch'''}
						A_  :				List[Any]	   =		{0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
					else:
						A_  :				Optional[int]	   =		{0: '''batch''', 1: '''decoder_sequence'''}
						A_  :				List[str]	   =		{0: '''batch''', 1: '''decoder_sequence'''}

					if self.use_past:
						self.fill_with_past_key_values_(_lowerCamelCase      ,     direction='''inputs'''       )

					return common_inputs







				@property
				# Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.default_onnx_opset
				def 					a_  (							self   :					Union[str, Any]       ):



					"""simple docstring"""

					return 13







				@property
				def 					a_  (							self   :					Any       ):



					"""simple docstring"""

					return 5E-4





