from __future__ import annotations

import unittest

from transformers import is_tf_available, is_torch_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, SMALL_MODEL_IDENTIFIER, is_pt_tf_cross_test, slow


if is_tf_available():
				from transformers import (
				    AutoConfig,
				    BertConfig,
				    GPTaConfig,
				    TaConfig,
				    TFAutoModel,
				    TFAutoModelForCausalLM,
				    TFAutoModelForMaskedLM,
				    TFAutoModelForPreTraining,
				    TFAutoModelForQuestionAnswering,
				    TFAutoModelForSeqaSeqLM,
				    TFAutoModelForSequenceClassification,
				    TFAutoModelWithLMHead,
				    TFBertForMaskedLM,
				    TFBertForPreTraining,
				    TFBertForQuestionAnswering,
				    TFBertForSequenceClassification,
				    TFBertModel,
				    TFGPTaLMHeadModel,
				    TFRobertaForMaskedLM,
				    TFTaForConditionalGeneration,
				)
				from transformers.models.bert.modeling_tf_bert import TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST
				from transformers.models.gpta.modeling_tf_gpta import TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST
				from transformers.models.ta.modeling_tf_ta import TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST

if is_torch_available():
				from transformers import (
				    AutoModel,
				    AutoModelForCausalLM,
				    AutoModelForMaskedLM,
				    AutoModelForPreTraining,
				    AutoModelForQuestionAnswering,
				    AutoModelForSeqaSeqLM,
				    AutoModelForSequenceClassification,
				    AutoModelWithLMHead,
				    BertForMaskedLM,
				    BertForPreTraining,
				    BertForQuestionAnswering,
				    BertForSequenceClassification,
				    BertModel,
				    GPTaLMHeadModel,
				    RobertaForMaskedLM,
				    TaForConditionalGeneration,
				)


@is_pt_tf_cross_test
class _lowercase       (							unittest.TestCase    ):





							"""simple docstring"""




							@slow
							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														for model_name in ["bert-base-uncased"]:
																					_lowercase					=						AutoConfig.from_pretrained(UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						TFAutoModel.from_pretrained(UpperCamelCase_  , from_pt=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						AutoModel.from_pretrained(UpperCamelCase_  , from_tf=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)



							@slow
							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														for model_name in ["bert-base-uncased"]:
																					_lowercase					=						AutoConfig.from_pretrained(UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						TFAutoModelForPreTraining.from_pretrained(UpperCamelCase_  , from_pt=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						AutoModelForPreTraining.from_pretrained(UpperCamelCase_  , from_tf=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)



							@slow
							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					_lowercase					=						AutoConfig.from_pretrained(UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						TFAutoModelForCausalLM.from_pretrained(UpperCamelCase_  , from_pt=UpperCamelCase_	)
																					_lowercase					,							_lowercase					=						TFAutoModelForCausalLM.from_pretrained(
																					    UpperCamelCase_  , output_loading_info=UpperCamelCase_  , from_pt=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						AutoModelForCausalLM.from_pretrained(UpperCamelCase_  , from_tf=UpperCamelCase_	)
																					_lowercase					,							_lowercase					=						AutoModelForCausalLM.from_pretrained(
																					    UpperCamelCase_  , output_loading_info=UpperCamelCase_  , from_tf=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)



							@slow
							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					_lowercase					=						AutoConfig.from_pretrained(UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						TFAutoModelWithLMHead.from_pretrained(UpperCamelCase_  , from_pt=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						AutoModelWithLMHead.from_pretrained(UpperCamelCase_  , from_tf=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)



							@slow
							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					_lowercase					=						AutoConfig.from_pretrained(UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						TFAutoModelForMaskedLM.from_pretrained(UpperCamelCase_  , from_pt=UpperCamelCase_	)
																					_lowercase					,							_lowercase					=						TFAutoModelForMaskedLM.from_pretrained(
																					    UpperCamelCase_  , output_loading_info=UpperCamelCase_  , from_pt=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						AutoModelForMaskedLM.from_pretrained(UpperCamelCase_  , from_tf=UpperCamelCase_	)
																					_lowercase					,							_lowercase					=						AutoModelForMaskedLM.from_pretrained(
																					    UpperCamelCase_  , output_loading_info=UpperCamelCase_  , from_tf=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)



							@slow
							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					_lowercase					=						AutoConfig.from_pretrained(UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						TFAutoModelForSeqaSeqLM.from_pretrained(UpperCamelCase_  , from_pt=UpperCamelCase_	)
																					_lowercase					,							_lowercase					=						TFAutoModelForSeqaSeqLM.from_pretrained(
																					    UpperCamelCase_  , output_loading_info=UpperCamelCase_  , from_pt=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						AutoModelForSeqaSeqLM.from_pretrained(UpperCamelCase_  , from_tf=UpperCamelCase_	)
																					_lowercase					,							_lowercase					=						AutoModelForSeqaSeqLM.from_pretrained(
																					    UpperCamelCase_  , output_loading_info=UpperCamelCase_  , from_tf=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)



							@slow
							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														for model_name in ["bert-base-uncased"]:
																					_lowercase					=						AutoConfig.from_pretrained(UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						TFAutoModelForSequenceClassification.from_pretrained(UpperCamelCase_  , from_pt=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						AutoModelForSequenceClassification.from_pretrained(UpperCamelCase_  , from_tf=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)



							@slow
							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														for model_name in ["bert-base-uncased"]:
																					_lowercase					=						AutoConfig.from_pretrained(UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						TFAutoModelForQuestionAnswering.from_pretrained(UpperCamelCase_  , from_pt=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)

																					_lowercase					=						AutoModelForQuestionAnswering.from_pretrained(UpperCamelCase_  , from_tf=UpperCamelCase_	)
																					self.assertIsNotNone(UpperCamelCase_	)
																					self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						TFAutoModelWithLMHead.from_pretrained(UpperCamelCase_  , from_pt=UpperCamelCase_	)
														self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)
														self.assertEqual(model.num_parameters()  , 14410	)
														self.assertEqual(model.num_parameters(only_trainable=UpperCamelCase_	)  , 14410	)

														_lowercase					=						AutoModelWithLMHead.from_pretrained(UpperCamelCase_  , from_tf=UpperCamelCase_	)
														self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)
														self.assertEqual(model.num_parameters()  , 14410	)
														self.assertEqual(model.num_parameters(only_trainable=UpperCamelCase_	)  , 14410	)



							def      _UpperCAmelCase							(     self	):







														'''simple docstring'''






														_lowercase					=						TFAutoModelWithLMHead.from_pretrained(UpperCamelCase_  , from_pt=UpperCamelCase_	)
														self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)
														self.assertEqual(model.num_parameters()  , 14410	)
														self.assertEqual(model.num_parameters(only_trainable=UpperCamelCase_	)  , 14410	)

														_lowercase					=						AutoModelWithLMHead.from_pretrained(UpperCamelCase_  , from_tf=UpperCamelCase_	)
														self.assertIsInstance(UpperCamelCase_  , UpperCamelCase_	)
														self.assertEqual(model.num_parameters()  , 14410	)
														self.assertEqual(model.num_parameters(only_trainable=UpperCamelCase_	)  , 14410	)









'''simple docstring'''




from collections import OrderedDict
from typing import Mapping

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


a__					:			str          =     logging.get_logger(__name__)

a__					:			Any          =     {
    '''xlm-mlm-en-2048''': '''https://huggingface.co/xlm-mlm-en-2048/resolve/main/config.json''',
    '''xlm-mlm-ende-1024''': '''https://huggingface.co/xlm-mlm-ende-1024/resolve/main/config.json''',
    '''xlm-mlm-enfr-1024''': '''https://huggingface.co/xlm-mlm-enfr-1024/resolve/main/config.json''',
    '''xlm-mlm-enro-1024''': '''https://huggingface.co/xlm-mlm-enro-1024/resolve/main/config.json''',
    '''xlm-mlm-tlm-xnli15-1024''': '''https://huggingface.co/xlm-mlm-tlm-xnli15-1024/resolve/main/config.json''',
    '''xlm-mlm-xnli15-1024''': '''https://huggingface.co/xlm-mlm-xnli15-1024/resolve/main/config.json''',
    '''xlm-clm-enfr-1024''': '''https://huggingface.co/xlm-clm-enfr-1024/resolve/main/config.json''',
    '''xlm-clm-ende-1024''': '''https://huggingface.co/xlm-clm-ende-1024/resolve/main/config.json''',
    '''xlm-mlm-17-1280''': '''https://huggingface.co/xlm-mlm-17-1280/resolve/main/config.json''',
    '''xlm-mlm-100-1280''': '''https://huggingface.co/xlm-mlm-100-1280/resolve/main/config.json''',
}






class 				__snake_case     (					__magic_name__							):
	__lowerCAmelCase       						=  '''xlm'''
	__lowerCAmelCase       						=  {
	    '''hidden_size''': '''emb_dim''',
	    '''num_attention_heads''': '''n_heads''',
	    '''num_hidden_layers''': '''n_layers''',
	    '''n_words''': '''vocab_size''',  # For backward compatibility
	}





	def __init__(		self      ,       UpperCamelCase_=3_0145      ,       UpperCamelCase_=2048      ,       UpperCamelCase_=12      ,       UpperCamelCase_=16      ,       UpperCamelCase_=0.1      ,       UpperCamelCase_=0.1      ,       UpperCamelCase_=True      ,       UpperCamelCase_=False      ,       UpperCamelCase_=False      ,       UpperCamelCase_=False      ,       UpperCamelCase_=1      ,       UpperCamelCase_=True      ,       UpperCamelCase_=512      ,       UpperCamelCase_=2048**-0.5      ,       UpperCamelCase_=1E-1_2      ,       UpperCamelCase_=0.0_2      ,       UpperCamelCase_=0      ,       UpperCamelCase_=1      ,       UpperCamelCase_=2      ,       UpperCamelCase_=3      ,       UpperCamelCase_=5      ,       UpperCamelCase_=True      ,       UpperCamelCase_="first"      ,       UpperCamelCase_=True      ,       UpperCamelCase_=None      ,       UpperCamelCase_=True      ,       UpperCamelCase_=0.1      ,       UpperCamelCase_=5      ,       UpperCamelCase_=5      ,       UpperCamelCase_=0      ,       UpperCamelCase_=0      ,       UpperCamelCase_=2      ,       UpperCamelCase_=0      ,       **UpperCamelCase_      ,       )      ->		List[str]:
		snake_case__	       =   vocab_size
		snake_case__	       =   emb_dim
		snake_case__	       =   n_layers
		snake_case__	       =   n_heads
		snake_case__	       =   dropout
		snake_case__	       =   attention_dropout
		snake_case__	       =   gelu_activation
		snake_case__	       =   sinusoidal_embeddings
		snake_case__	       =   causal
		snake_case__	       =   asm
		snake_case__	       =   n_langs
		snake_case__	       =   use_lang_emb
		snake_case__	       =   layer_norm_eps
		snake_case__	       =   bos_index
		snake_case__	       =   eos_index
		snake_case__	       =   pad_index
		snake_case__	       =   unk_index
		snake_case__	       =   mask_index
		snake_case__	       =   is_encoder
		snake_case__	       =   max_position_embeddings
		snake_case__	       =   embed_init_std
		snake_case__	       =   init_std
		snake_case__	       =   summary_type
		snake_case__	       =   summary_use_proj
		snake_case__	       =   summary_activation
		snake_case__	       =   summary_proj_to_labels
		snake_case__	       =   summary_first_dropout
		snake_case__	       =   start_n_top
		snake_case__	       =   end_n_top
		snake_case__	       =   mask_token_id
		snake_case__	       =   lang_id

		if "n_words" in kwargs:
			snake_case__	       =   kwargs['n_words']

		super().__init__(pad_token_id=UpperCamelCase_      ,       bos_token_id=UpperCamelCase_      ,       **UpperCamelCase_		)






class 				__snake_case     (					__magic_name__							):





	@property
	def   _snake_case   (		self		)      ->		Mapping[str, Mapping[int, str]]:
		if self.task == "multiple-choice":
			snake_case__	       =   {0: 'batch', 1: 'choice', 2: 'sequence'}
		else:
			snake_case__	       =   {0: 'batch', 1: 'sequence'}
		return OrderedDict(
		    [
		        ('input_ids', dynamic_axis),
		        ('attention_mask', dynamic_axis),
		        ('token_type_ids', dynamic_axis),
		    ]		)



