


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





							'''simple docstring'''


							@slow
							def UpperCAmelCase_      (       self    ):

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

															_SCREAMING_SNAKE_CASE					:			Dict							= TFAutoModel.from_pretrained(A_       ,   from_pt=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )

															_SCREAMING_SNAKE_CASE					:			Optional[int]							= AutoModel.from_pretrained(A_       ,   from_tf=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )






							@slow
							def UpperCAmelCase_      (       self    ):

											for model_name in ["bert-base-uncased"]:
															_SCREAMING_SNAKE_CASE					:			List[str]							= AutoConfig.from_pretrained(A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )

															_SCREAMING_SNAKE_CASE					:			Dict							= TFAutoModelForPreTraining.from_pretrained(A_       ,   from_pt=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )

															_SCREAMING_SNAKE_CASE					:			Dict							= AutoModelForPreTraining.from_pretrained(A_       ,   from_tf=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )






							@slow
							def UpperCAmelCase_      (       self    ):

											for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															_SCREAMING_SNAKE_CASE					:			str							= AutoConfig.from_pretrained(A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )

															_SCREAMING_SNAKE_CASE					:			Tuple							= TFAutoModelForCausalLM.from_pretrained(A_       ,   from_pt=A_    )
															_SCREAMING_SNAKE_CASE						,			_SCREAMING_SNAKE_CASE					:			Any							= TFAutoModelForCausalLM.from_pretrained(
															    A_       ,   output_loading_info=A_       ,   from_pt=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )

															_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= AutoModelForCausalLM.from_pretrained(A_       ,   from_tf=A_    )
															_SCREAMING_SNAKE_CASE						,			_SCREAMING_SNAKE_CASE					:			List[Any]							= AutoModelForCausalLM.from_pretrained(
															    A_       ,   output_loading_info=A_       ,   from_tf=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )






							@slow
							def UpperCAmelCase_      (       self    ):

											for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															_SCREAMING_SNAKE_CASE					:			Dict							= AutoConfig.from_pretrained(A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )

															_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= TFAutoModelWithLMHead.from_pretrained(A_       ,   from_pt=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )

															_SCREAMING_SNAKE_CASE					:			List[Any]							= AutoModelWithLMHead.from_pretrained(A_       ,   from_tf=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )






							@slow
							def UpperCAmelCase_      (       self    ):

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

															_SCREAMING_SNAKE_CASE					:			Optional[Any]							= TFAutoModelForMaskedLM.from_pretrained(A_       ,   from_pt=A_    )
															_SCREAMING_SNAKE_CASE						,			_SCREAMING_SNAKE_CASE					:			Optional[Any]							= TFAutoModelForMaskedLM.from_pretrained(
															    A_       ,   output_loading_info=A_       ,   from_pt=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )

															_SCREAMING_SNAKE_CASE					:			Dict							= AutoModelForMaskedLM.from_pretrained(A_       ,   from_tf=A_    )
															_SCREAMING_SNAKE_CASE						,			_SCREAMING_SNAKE_CASE					:			Dict							= AutoModelForMaskedLM.from_pretrained(
															    A_       ,   output_loading_info=A_       ,   from_tf=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )






							@slow
							def UpperCAmelCase_      (       self    ):

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

															_SCREAMING_SNAKE_CASE					:			Optional[Any]							= TFAutoModelForSeqaSeqLM.from_pretrained(A_       ,   from_pt=A_    )
															_SCREAMING_SNAKE_CASE						,			_SCREAMING_SNAKE_CASE					:			str							= TFAutoModelForSeqaSeqLM.from_pretrained(
															    A_       ,   output_loading_info=A_       ,   from_pt=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )

															_SCREAMING_SNAKE_CASE					:			Union[str, Any]							= AutoModelForSeqaSeqLM.from_pretrained(A_       ,   from_tf=A_    )
															_SCREAMING_SNAKE_CASE						,			_SCREAMING_SNAKE_CASE					:			List[str]							= AutoModelForSeqaSeqLM.from_pretrained(
															    A_       ,   output_loading_info=A_       ,   from_tf=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )






							@slow
							def UpperCAmelCase_      (       self    ):

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

															_SCREAMING_SNAKE_CASE					:			List[Any]							= TFAutoModelForSequenceClassification.from_pretrained(A_       ,   from_pt=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )

															_SCREAMING_SNAKE_CASE					:			List[str]							= AutoModelForSequenceClassification.from_pretrained(A_       ,   from_tf=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )






							@slow
							def UpperCAmelCase_      (       self    ):

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

															_SCREAMING_SNAKE_CASE					:			Optional[int]							= TFAutoModelForQuestionAnswering.from_pretrained(A_       ,   from_pt=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )

															_SCREAMING_SNAKE_CASE					:			Optional[int]							= AutoModelForQuestionAnswering.from_pretrained(A_       ,   from_tf=A_    )
															self.assertIsNotNone(A_    )
															self.assertIsInstance(A_       ,   A_    )






							def UpperCAmelCase_      (       self    ):
											_SCREAMING_SNAKE_CASE					:			Tuple							= TFAutoModelWithLMHead.from_pretrained(A_       ,   from_pt=A_    )
											self.assertIsInstance(A_       ,   A_    )
											self.assertEqual(model.num_parameters()       ,   1_4410    )
											self.assertEqual(model.num_parameters(only_trainable=A_    )       ,   1_4410    )

											_SCREAMING_SNAKE_CASE					:			str							= AutoModelWithLMHead.from_pretrained(A_       ,   from_tf=A_    )
											self.assertIsInstance(A_       ,   A_    )
											self.assertEqual(model.num_parameters()       ,   1_4410    )
											self.assertEqual(model.num_parameters(only_trainable=A_    )       ,   1_4410    )






							def UpperCAmelCase_      (       self    ):
											_SCREAMING_SNAKE_CASE					:			List[str]							= TFAutoModelWithLMHead.from_pretrained(A_       ,   from_pt=A_    )
											self.assertIsInstance(A_       ,   A_    )
											self.assertEqual(model.num_parameters()       ,   1_4410    )
											self.assertEqual(model.num_parameters(only_trainable=A_    )       ,   1_4410    )

											_SCREAMING_SNAKE_CASE					:			Tuple							= AutoModelWithLMHead.from_pretrained(A_       ,   from_tf=A_    )
											self.assertIsInstance(A_       ,   A_    )
											self.assertEqual(model.num_parameters()       ,   1_4410    )
											self.assertEqual(model.num_parameters(only_trainable=A_    )       ,   1_4410    )











from torch import nn


def 							__snake_case							(    lowerCAmelCase_	)				->						Tuple:
    if act_fn in ["swish", "silu"]:
        return nn.SiLU()
    elif act_fn == "mish":
        return nn.Mish()
    elif act_fn == "gelu":
        return nn.GELU()
    else:
        raise ValueError(f'''Unsupported activation function: {act_fn}'''	)
