




import unittest

from transformers import AutoConfig, AutoTokenizer, BertConfig, TensorType, is_flax_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, slow


if is_flax_available():
		import jax

		from transformers.models.auto.modeling_flax_auto import FlaxAutoModel
		from transformers.models.bert.modeling_flax_bert import FlaxBertModel
		from transformers.models.roberta.modeling_flax_roberta import FlaxRobertaModel

@require_flax
class 						__lowerCAmelCase      (      unittest.TestCase					):
							@slow
							def  lowerCamelCase__				(		self		:Optional[Any]							):







								'''simple docstring'''







								for model_name in ["bert-base-cased", "bert-large-uncased"]:
									with self.subTest(lowercase__							):
										a									=				AutoConfig.from_pretrained(lowercase__							)
										self.assertIsNotNone(lowercase__							)
										self.assertIsInstance(lowercase__						, lowercase__							)

										a									=				FlaxAutoModel.from_pretrained(lowercase__							)
										self.assertIsNotNone(lowercase__							)
										self.assertIsInstance(lowercase__						, lowercase__							)
							@slow
							def  lowerCamelCase__				(		self		:List[Any]							):







								'''simple docstring'''







								for model_name in ["roberta-base", "roberta-large"]:
									with self.subTest(lowercase__							):
										a									=				AutoConfig.from_pretrained(lowercase__							)
										self.assertIsNotNone(lowercase__							)
										self.assertIsInstance(lowercase__						, lowercase__							)

										a									=				FlaxAutoModel.from_pretrained(lowercase__							)
										self.assertIsNotNone(lowercase__							)
										self.assertIsInstance(lowercase__						, lowercase__							)
							@slow
							def  lowerCamelCase__				(		self		:List[str]							):







								'''simple docstring'''







								for model_name in ["bert-base-cased", "bert-large-uncased"]:
									a									=				AutoTokenizer.from_pretrained(lowercase__							)
									a									=				FlaxBertModel.from_pretrained(lowercase__							)
									a									=				tokenizer("""Do you support jax jitted function?"""						, return_tensors=TensorType.JAX							)

									@jax.jit
									def eval(**__magic_name__		:Optional[Any]							):
										return model(**lowercase__							)

									eval(**lowercase__							).block_until_ready()
							@slow
							def  lowerCamelCase__				(		self		:str							):







								'''simple docstring'''







								for model_name in ["roberta-base", "roberta-large"]:
									a									=				AutoTokenizer.from_pretrained(lowercase__							)
									a									=				FlaxRobertaModel.from_pretrained(lowercase__							)
									a									=				tokenizer("""Do you support jax jitted function?"""						, return_tensors=TensorType.JAX							)

									@jax.jit
									def eval(**__magic_name__		:Dict							):
										return model(**lowercase__							)

									eval(**lowercase__							).block_until_ready()
							def  lowerCamelCase__				(		self		:int							):







								'''simple docstring'''







								with self.assertRaisesRegex(
								    lowercase__						, """bert-base is not a local folder and is not a valid model identifier"""							):
									a									=				FlaxAutoModel.from_pretrained("""bert-base"""							)
							def  lowerCamelCase__				(		self		:Dict							):







								'''simple docstring'''







								with self.assertRaisesRegex(
								    lowercase__						, r"""aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"""							):
									a									=				FlaxAutoModel.from_pretrained(lowercase__						, revision="""aaaaaa"""							)
							def  lowerCamelCase__				(		self		:List[Any]							):







								'''simple docstring'''







								with self.assertRaisesRegex(
								    lowercase__						, """hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack"""						, ):
									a									=				FlaxAutoModel.from_pretrained("""hf-internal-testing/config-no-model"""							)





							def  lowerCamelCase__				(		self		:str							):







								'''simple docstring'''







								with self.assertRaisesRegex(lowercase__						, """Use `from_pt=True` to load this model"""							):
									a									=				FlaxAutoModel.from_pretrained("""hf-internal-testing/tiny-bert-pt-only"""							)







'''simple docstring'''


from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase_      :  str				     =  logging.get_logger(__name__)

lowerCAmelCase_      :  Any				     =  {
    'transfo-xl-wt103': 'https://huggingface.co/transfo-xl-wt103/resolve/main/config.json',
}







class      SCREAMING_SNAKE_CASE    (						snake_case_				):
      __magic_name__  :       str   							=					'''transfo-xl'''
      __magic_name__  :       List[str]   							=					['''mems''']
      __magic_name__  :       Dict   							=					{
          '''n_token''': '''vocab_size''',
          '''hidden_size''': '''d_model''',
          '''num_attention_heads''': '''n_head''',
          '''num_hidden_layers''': '''n_layer''',
      }






      def __init__( self   :  Union[str, Any]						,						lowercase__   :  List[Any]=26_7735						,						lowercase__   :  Optional[Any]=[2_0000, 4_0000, 20_0000]						,						lowercase__   :  Optional[Any]=1024						,						lowercase__   :  str=1024						,						lowercase__   :  Any=16						,						lowercase__   :  int=64						,						lowercase__   :  str=4096						,						lowercase__   :  Union[str, Any]=4						,						lowercase__   :  List[Any]=False						,						lowercase__   :  List[Any]=18						,						lowercase__   :  str=1600						,						lowercase__   :  str=1000						,						lowercase__   :  Any=True						,						lowercase__   :  Optional[Any]=True						,						lowercase__   :  Union[str, Any]=0						,						lowercase__   :  str=-1						,						lowercase__   :  int=True						,						lowercase__   :  str=0.1						,						lowercase__   :  Optional[Any]=0.0						,						lowercase__   :  Tuple=True						,						lowercase__   :  Optional[int]="normal"						,						lowercase__   :  str=0.01						,						lowercase__   :  List[str]=0.01						,						lowercase__   :  Union[str, Any]=0.02						,						lowercase__   :  str=1e-5						,						lowercase__   :  Any=0						,						**lowercase__   :  List[str]						,						):


           '''simple docstring'''

           a_     :							Optional[Any]     						=  vocab_size
           a_     :							Optional[int]     						=  []
           self.cutoffs.extend(lowercase__       )
           if proj_share_all_but_first:
                a_     :							Any     						=  [False] + [True] * len(self.cutoffs       )
           else:
                a_     :							Tuple     						=  [False] + [False] * len(self.cutoffs       )
           a_     :							Tuple     						=  d_model
           a_     :							Optional[int]     						=  d_embed
           a_     :							List[Any]     						=  d_head
           a_     :							List[str]     						=  d_inner
           a_     :							Tuple     						=  div_val
           a_     :							Dict     						=  pre_lnorm
           a_     :							Optional[Any]     						=  n_layer
           a_     :							Dict     						=  n_head
           a_     :							Any     						=  mem_len
           a_     :							Union[str, Any]     						=  same_length
           a_     :							Dict     						=  attn_type
           a_     :							List[str]     						=  clamp_len
           a_     :							str     						=  sample_softmax
           a_     :							Any     						=  adaptive
           a_     :							List[Any]     						=  dropout
           a_     :							str     						=  dropatt
           a_     :							Dict     						=  untie_r
           a_     :							Tuple     						=  init
           a_     :							Optional[int]     						=  init_range
           a_     :							List[Any]     						=  proj_init_std
           a_     :							Optional[int]     						=  init_std
           a_     :							int     						=  layer_norm_epsilon
           super().__init__(eos_token_id=lowercase__						,						**lowercase__       )






      @property
      def 							lowercase_						( self   :  int       ):


           '''simple docstring'''

           logger.info(F"The model {self.model_type} is one of the few models that has no sequence length limit."       )
           return -1






      @max_position_embeddings.setter
      def 							lowercase_						( self   :  Optional[int]						,						lowercase__   :  Tuple       ):


           '''simple docstring'''

           raise NotImplementedError(
               F"The model {self.model_type} is one of the few models that has no sequence length limit."       )
