






"""simple docstring"""



from typing import Mapping

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


_lowerCAmelCase	:	Dict				=      logging.get_logger(__name__)

_lowerCAmelCase	:	Any				=      {
    '''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 			lowerCAmelCase__			(    lowerCamelCase_   ):
   SCREAMING_SNAKE_CASE_    ="umt5"
   SCREAMING_SNAKE_CASE_    =["past_key_values"]
   def __init__(		self      :	int							,			snake_case__      :	Union[str, Any]=2_5_0_1_1_2							,			snake_case__      :	Any=5_1_2							,			snake_case__      :	int=6_4							,			snake_case__      :	str=1_0_2_4							,			snake_case__      :	Tuple=8							,			snake_case__      :	Optional[int]=None							,			snake_case__      :	Any=6							,			snake_case__      :	str=3_2							,			snake_case__      :	Any=1_2_8							,			snake_case__      :	List[Any]=0.1							,			snake_case__      :	Union[str, Any]=1e-6							,			snake_case__      :	List[str]=1.0							,			snake_case__      :	Any="gated-gelu"							,			snake_case__      :	Union[str, Any]=True							,			snake_case__      :	int=True							,			snake_case__      :	Optional[Any]="T5Tokenizer"							,			snake_case__      :	int=True							,			snake_case__      :	Any=0							,			snake_case__      :	Tuple=1							,			snake_case__      :	List[str]=0							,			**snake_case__      :	Dict							,			):


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

        UpperCAmelCase__						:    Optional[int]							=							self.feed_forward_proj.split("-"							)
        UpperCAmelCase__						:    List[str]							=							act_info[-1]
        UpperCAmelCase__						:    Union[str, Any]							=							act_info[0] == 'gated'

        if len(snake_case__							) > 1 and act_info[0] != "gated" or len(snake_case__							) > 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":
             UpperCAmelCase__						:    List[Any]							=							'gelu_new'
   @property
   def       __a							(		self      :	int							):


        '''simple docstring'''
        return self.d_model
   @property
   def       __a							(		self      :	List[Any]							):


        '''simple docstring'''
        return self.num_heads




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


        '''simple docstring'''
        return self.num_layers




class 			lowerCAmelCase__			(    lowerCamelCase_   ):
   @property
   # Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.inputs
   def       __a							(		self      :	int							):


        '''simple docstring'''
        UpperCAmelCase__						:    Tuple							=							{
            'input_ids': {0: 'batch', 1: 'encoder_sequence'},
            'attention_mask': {0: 'batch', 1: 'encoder_sequence'},
        }
        if self.use_past:
             UpperCAmelCase__						:    Optional[Any]							=							'past_encoder_sequence + sequence'
             UpperCAmelCase__						:    str							=							{0: 'batch'}
             UpperCAmelCase__						:    Any							=							{0: 'batch', 1: 'past_decoder_sequence + sequence'}
        else:
             UpperCAmelCase__						:    Optional[Any]							=							{0: 'batch', 1: 'decoder_sequence'}
             UpperCAmelCase__						:    Any							=							{0: 'batch', 1: 'decoder_sequence'}

        if self.use_past:
             self.fill_with_past_key_values_(snake_case__							,			direction="inputs"							)

        return common_inputs
   @property
   # Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.default_onnx_opset
   def       __a							(		self      :	Dict							):


        '''simple docstring'''
        return 1_3




   @property
   def       __a							(		self      :	List[Any]							):


        '''simple docstring'''
        return 5e-4








import os
import sys
import unittest


UpperCamelCase__ :   Optional[Any]						=							os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, '''utils'''))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
UpperCamelCase__ :   Tuple						=							os.path.join(git_repo_path, '''src''', '''transformers''')

UpperCamelCase__ :   List[Any]						=							'''
{0} = None
'''

UpperCamelCase__ :   str						=							'''
class {0}(metaclass=DummyObject):
    _backends = {1}

    def __init__(self, *args, **kwargs):
        requires_backends(self, {1})
'''


UpperCamelCase__ :   List[Any]						=							'''
def {0}(*args, **kwargs):
    requires_backends({0}, {1})
'''







class 				lowerCAmelCase_       (					unittest.TestCase							):






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : int					  =      find_backend('    _import_structure["models.albert"].append("AlbertTokenizerFast")' )
							self.assertIsNone(snake_case__ )

							SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      find_backend('    if not is_tokenizers_available():' )
							self.assertEqual(snake_case__      ,'tokenizers' )

							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      find_backend('    if not is_tensorflow_text_available():' )
							self.assertEqual(snake_case__      ,'tensorflow_text' )

							SCREAMING_SNAKE_CASE_   : int					  =      find_backend('    if not (is_sentencepiece_available() and is_tokenizers_available()):' )
							self.assertEqual(snake_case__      ,'sentencepiece_and_tokenizers' )

							SCREAMING_SNAKE_CASE_   : str					  =      find_backend(
							    '    if not (is_sentencepiece_available() and is_tensorflow_text_available()):' )
							self.assertEqual(snake_case__      ,'sentencepiece_and_tensorflow_text' )

							SCREAMING_SNAKE_CASE_   : Tuple					  =      find_backend(
							    '    if not (is_sentencepiece_available() and is_tokenizers_available() and is_vision_available()):' )
							self.assertEqual(snake_case__      ,'sentencepiece_and_tokenizers_and_vision' )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : str					  =      read_init()
							# We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
							self.assertIn('torch'      ,snake_case__ )
							self.assertIn('tensorflow_text'      ,snake_case__ )
							self.assertIn('sentencepiece_and_tokenizers'      ,snake_case__ )

							# Likewise, we can't assert on the exact content of a key
							self.assertIn('BertModel'      ,objects['torch'] )
							self.assertIn('TFBertModel'      ,objects['tf'] )
							self.assertIn('FlaxBertModel'      ,objects['flax'] )
							self.assertIn('BertModel'      ,objects['torch'] )
							self.assertIn('TFBertTokenizer'      ,objects['tensorflow_text'] )
							self.assertIn('convert_slow_tokenizer'      ,objects['sentencepiece_and_tokenizers'] )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : str					  =      create_dummy_object('CONSTANT'      ,'\'torch\'' )
							self.assertEqual(snake_case__      ,'\nCONSTANT = None\n' )

							SCREAMING_SNAKE_CASE_   : Dict					  =      create_dummy_object('function'      ,'\'torch\'' )
							self.assertEqual(
							    snake_case__      ,'\ndef function(*args, **kwargs):\n    requires_backends(function, \'torch\')\n' )

							SCREAMING_SNAKE_CASE_   : List[str]					  =      '\nclass FakeClass(metaclass=DummyObject):\n    _backends = \'torch\'\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, \'torch\')\n'
							SCREAMING_SNAKE_CASE_   : Dict					  =      create_dummy_object('FakeClass'      ,'\'torch\'' )
							self.assertEqual(snake_case__      ,snake_case__ )






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      '# This file is autogenerated by the command `make fix-copies`, do not edit.\nfrom ..utils import DummyObject, requires_backends\n\n\nCONSTANT = None\n\n\ndef function(*args, **kwargs):\n    requires_backends(function, ["torch"])\n\n\nclass FakeClass(metaclass=DummyObject):\n    _backends = ["torch"]\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, ["torch"])\n'
							SCREAMING_SNAKE_CASE_   : Dict					  =      create_dummy_files({'torch': ['CONSTANT', 'function', 'FakeClass']} )
							self.assertEqual(dummy_files['torch']      ,snake_case__ )



