



"""simple docstring"""







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        __A       (	unittest.TestCase    ):







		'''simple docstring'''





		@slow
		def 					UpperCAmelCase    (	self						:  Optional[Any]						)					->		Union[str, Any]:






				"""simple docstring"""



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

						lowercase__   :    Dict				=			TFAutoModel.from_pretrained(_snake_case			,from_pt=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)

						lowercase__   :    List[str]				=			AutoModel.from_pretrained(_snake_case			,from_tf=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)







		@slow
		def 					UpperCAmelCase    (	self						:  Union[str, Any]						)					->		Tuple:






				"""simple docstring"""



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

						lowercase__   :    str				=			TFAutoModelForPreTraining.from_pretrained(_snake_case			,from_pt=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)

						lowercase__   :    Optional[Any]				=			AutoModelForPreTraining.from_pretrained(_snake_case			,from_tf=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)







		@slow
		def 					UpperCAmelCase    (	self						:  Tuple						)					->		Dict:






				"""simple docstring"""



				for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						lowercase__   :    Any				=			AutoConfig.from_pretrained(_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)

						lowercase__   :    List[str]				=			TFAutoModelForCausalLM.from_pretrained(_snake_case			,from_pt=_snake_case						)
						lowercase__		,			lowercase__   :    Optional[Any]				=			TFAutoModelForCausalLM.from_pretrained(
						    _snake_case			,output_loading_info=_snake_case			,from_pt=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)

						lowercase__   :    Union[str, Any]				=			AutoModelForCausalLM.from_pretrained(_snake_case			,from_tf=_snake_case						)
						lowercase__		,			lowercase__   :    Optional[Any]				=			AutoModelForCausalLM.from_pretrained(
						    _snake_case			,output_loading_info=_snake_case			,from_tf=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)







		@slow
		def 					UpperCAmelCase    (	self						:  Any						)					->		Tuple:






				"""simple docstring"""



				for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						lowercase__   :    Any				=			AutoConfig.from_pretrained(_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)

						lowercase__   :    Optional[Any]				=			TFAutoModelWithLMHead.from_pretrained(_snake_case			,from_pt=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)

						lowercase__   :    Any				=			AutoModelWithLMHead.from_pretrained(_snake_case			,from_tf=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)







		@slow
		def 					UpperCAmelCase    (	self						:  List[str]						)					->		Optional[Any]:






				"""simple docstring"""



				for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						lowercase__   :    str				=			AutoConfig.from_pretrained(_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)

						lowercase__   :    Union[str, Any]				=			TFAutoModelForMaskedLM.from_pretrained(_snake_case			,from_pt=_snake_case						)
						lowercase__		,			lowercase__   :    str				=			TFAutoModelForMaskedLM.from_pretrained(
						    _snake_case			,output_loading_info=_snake_case			,from_pt=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)

						lowercase__   :    List[str]				=			AutoModelForMaskedLM.from_pretrained(_snake_case			,from_tf=_snake_case						)
						lowercase__		,			lowercase__   :    Any				=			AutoModelForMaskedLM.from_pretrained(
						    _snake_case			,output_loading_info=_snake_case			,from_tf=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)







		@slow
		def 					UpperCAmelCase    (	self						:  List[Any]						)					->		Dict:






				"""simple docstring"""



				for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						lowercase__   :    Union[str, Any]				=			AutoConfig.from_pretrained(_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)

						lowercase__   :    List[str]				=			TFAutoModelForSeqaSeqLM.from_pretrained(_snake_case			,from_pt=_snake_case						)
						lowercase__		,			lowercase__   :    List[str]				=			TFAutoModelForSeqaSeqLM.from_pretrained(
						    _snake_case			,output_loading_info=_snake_case			,from_pt=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)

						lowercase__   :    Any				=			AutoModelForSeqaSeqLM.from_pretrained(_snake_case			,from_tf=_snake_case						)
						lowercase__		,			lowercase__   :    Optional[int]				=			AutoModelForSeqaSeqLM.from_pretrained(
						    _snake_case			,output_loading_info=_snake_case			,from_tf=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)







		@slow
		def 					UpperCAmelCase    (	self						:  List[str]						)					->		Union[str, Any]:






				"""simple docstring"""



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

						lowercase__   :    Any				=			TFAutoModelForSequenceClassification.from_pretrained(_snake_case			,from_pt=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)

						lowercase__   :    Union[str, Any]				=			AutoModelForSequenceClassification.from_pretrained(_snake_case			,from_tf=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)







		@slow
		def 					UpperCAmelCase    (	self						:  Tuple						)					->		Optional[Any]:






				"""simple docstring"""



				for model_name in ["bert-base-uncased"]:
						lowercase__   :    List[Any]				=			AutoConfig.from_pretrained(_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)

						lowercase__   :    str				=			TFAutoModelForQuestionAnswering.from_pretrained(_snake_case			,from_pt=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)

						lowercase__   :    Any				=			AutoModelForQuestionAnswering.from_pretrained(_snake_case			,from_tf=_snake_case						)
						self.assertIsNotNone(_snake_case						)
						self.assertIsInstance(_snake_case			,_snake_case						)







		def 					UpperCAmelCase    (	self						:  Dict						)					->		Any:






				"""simple docstring"""



				lowercase__   :    Optional[Any]				=			TFAutoModelWithLMHead.from_pretrained(_snake_case			,from_pt=_snake_case						)
				self.assertIsInstance(_snake_case			,_snake_case						)
				self.assertEqual(model.num_parameters()			,14_410						)
				self.assertEqual(model.num_parameters(only_trainable=_snake_case						)			,14_410						)

				lowercase__   :    Union[str, Any]				=			AutoModelWithLMHead.from_pretrained(_snake_case			,from_tf=_snake_case						)
				self.assertIsInstance(_snake_case			,_snake_case						)
				self.assertEqual(model.num_parameters()			,14_410						)
				self.assertEqual(model.num_parameters(only_trainable=_snake_case						)			,14_410						)







		def 					UpperCAmelCase    (	self						:  int						)					->		List[Any]:






				"""simple docstring"""



				lowercase__   :    List[Any]				=			TFAutoModelWithLMHead.from_pretrained(_snake_case			,from_pt=_snake_case						)
				self.assertIsInstance(_snake_case			,_snake_case						)
				self.assertEqual(model.num_parameters()			,14_410						)
				self.assertEqual(model.num_parameters(only_trainable=_snake_case						)			,14_410						)

				lowercase__   :    int				=			AutoModelWithLMHead.from_pretrained(_snake_case			,from_tf=_snake_case						)
				self.assertIsInstance(_snake_case			,_snake_case						)
				self.assertEqual(model.num_parameters()			,14_410						)
				self.assertEqual(model.num_parameters(only_trainable=_snake_case						)			,14_410						)


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


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

lowercase  :					Any						    =							{
    """uclanlp/visualbert-vqa""": """https://huggingface.co/uclanlp/visualbert-vqa/resolve/main/config.json""",
    """uclanlp/visualbert-vqa-pre""": """https://huggingface.co/uclanlp/visualbert-vqa-pre/resolve/main/config.json""",
    """uclanlp/visualbert-vqa-coco-pre""": (
        """https://huggingface.co/uclanlp/visualbert-vqa-coco-pre/resolve/main/config.json"""
    ),
    """uclanlp/visualbert-vcr""": """https://huggingface.co/uclanlp/visualbert-vcr/resolve/main/config.json""",
    """uclanlp/visualbert-vcr-pre""": """https://huggingface.co/uclanlp/visualbert-vcr-pre/resolve/main/config.json""",
    """uclanlp/visualbert-vcr-coco-pre""": (
        """https://huggingface.co/uclanlp/visualbert-vcr-coco-pre/resolve/main/config.json"""
    ),
    """uclanlp/visualbert-nlvr2""": """https://huggingface.co/uclanlp/visualbert-nlvr2/resolve/main/config.json""",
    """uclanlp/visualbert-nlvr2-pre""": """https://huggingface.co/uclanlp/visualbert-nlvr2-pre/resolve/main/config.json""",
    """uclanlp/visualbert-nlvr2-coco-pre""": (
        """https://huggingface.co/uclanlp/visualbert-nlvr2-coco-pre/resolve/main/config.json"""
    )
    # See all VisualBERT models at https://huggingface.co/models?filter=visual_bert
}

class __snake_case		(      lowerCAmelCase     ):
    _a		:						Union[str, Any]=				"visual_bert"
    def __init__(  self		,snake_case=30522		,snake_case=768		,snake_case=512		,snake_case=12		,snake_case=12		,snake_case=3072		,snake_case="gelu"		,snake_case=0.1		,snake_case=0.1		,snake_case=512		,snake_case=2		,snake_case=0.02		,snake_case=1e-12		,snake_case=False		,snake_case=True		,snake_case=1		,snake_case=0		,snake_case=2		,**snake_case		,):



           '''simple docstring'''







           super().__init__(pad_token_id=snake_case		,bos_token_id=snake_case		,eos_token_id=snake_case		,**snake_case      )

           lowercase							:     Tuple       	=      vocab_size
           lowercase							:     int       	=      max_position_embeddings
           lowercase							:     Optional[Any]       	=      hidden_size
           lowercase							:     int       	=      visual_embedding_dim
           lowercase							:     Tuple       	=      num_hidden_layers
           lowercase							:     str       	=      num_attention_heads
           lowercase							:     Optional[Any]       	=      intermediate_size
           lowercase							:     str       	=      hidden_act
           lowercase							:     Tuple       	=      hidden_dropout_prob
           lowercase							:     List[Any]       	=      attention_probs_dropout_prob
           lowercase							:     Union[str, Any]       	=      initializer_range
           lowercase							:     int       	=      type_vocab_size
           lowercase							:     Union[str, Any]       	=      layer_norm_eps
           lowercase							:     Union[str, Any]       	=      bypass_transformer
           lowercase							:     int       	=      special_visual_initialize
