






"""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       ):


			@slow
			def      UpperCAmelCase__						(				self					:  str ):
										# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										for model_name in ["bert-base-uncased"]:
																	lowerCamelCase_	:							Optional[int]									=AutoConfig.from_pretrained(__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							Tuple									=TFAutoModel.from_pretrained(__A       ,	from_pt=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							List[Any]									=AutoModel.from_pretrained(__A       ,	from_tf=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )


			@slow
			def      UpperCAmelCase__						(				self					:  Dict ):
										# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										for model_name in ["bert-base-uncased"]:
																	lowerCamelCase_	:							int									=AutoConfig.from_pretrained(__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							Tuple									=TFAutoModelForPreTraining.from_pretrained(__A       ,	from_pt=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							List[str]									=AutoModelForPreTraining.from_pretrained(__A       ,	from_tf=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )


			@slow
			def      UpperCAmelCase__						(				self					:  str ):
										for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	lowerCamelCase_	:							int									=AutoConfig.from_pretrained(__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							List[Any]									=TFAutoModelForCausalLM.from_pretrained(__A       ,	from_pt=__A )
																	lowerCamelCase_							,						lowerCamelCase_	:							Any									=TFAutoModelForCausalLM.from_pretrained(
																	    __A       ,	output_loading_info=__A       ,	from_pt=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

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


			@slow
			def      UpperCAmelCase__						(				self					:  List[str] ):
										for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	lowerCamelCase_	:							List[str]									=AutoConfig.from_pretrained(__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							List[Any]									=TFAutoModelWithLMHead.from_pretrained(__A       ,	from_pt=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							str									=AutoModelWithLMHead.from_pretrained(__A       ,	from_tf=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )


			@slow
			def      UpperCAmelCase__						(				self					:  Union[str, Any] ):
										for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	lowerCamelCase_	:							List[str]									=AutoConfig.from_pretrained(__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							Union[str, Any]									=TFAutoModelForMaskedLM.from_pretrained(__A       ,	from_pt=__A )
																	lowerCamelCase_							,						lowerCamelCase_	:							List[Any]									=TFAutoModelForMaskedLM.from_pretrained(
																	    __A       ,	output_loading_info=__A       ,	from_pt=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							Union[str, Any]									=AutoModelForMaskedLM.from_pretrained(__A       ,	from_tf=__A )
																	lowerCamelCase_							,						lowerCamelCase_	:							str									=AutoModelForMaskedLM.from_pretrained(
																	    __A       ,	output_loading_info=__A       ,	from_tf=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )


			@slow
			def      UpperCAmelCase__						(				self					:  Tuple ):
										for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	lowerCamelCase_	:							Any									=AutoConfig.from_pretrained(__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							List[Any]									=TFAutoModelForSeqaSeqLM.from_pretrained(__A       ,	from_pt=__A )
																	lowerCamelCase_							,						lowerCamelCase_	:							Any									=TFAutoModelForSeqaSeqLM.from_pretrained(
																	    __A       ,	output_loading_info=__A       ,	from_pt=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							List[Any]									=AutoModelForSeqaSeqLM.from_pretrained(__A       ,	from_tf=__A )
																	lowerCamelCase_							,						lowerCamelCase_	:							Tuple									=AutoModelForSeqaSeqLM.from_pretrained(
																	    __A       ,	output_loading_info=__A       ,	from_tf=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )


			@slow
			def      UpperCAmelCase__						(				self					:  List[str] ):
										# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										for model_name in ["bert-base-uncased"]:
																	lowerCamelCase_	:							Optional[int]									=AutoConfig.from_pretrained(__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							Union[str, Any]									=TFAutoModelForSequenceClassification.from_pretrained(__A       ,	from_pt=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							Optional[int]									=AutoModelForSequenceClassification.from_pretrained(__A       ,	from_tf=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )


			@slow
			def      UpperCAmelCase__						(				self					:  Union[str, Any] ):
										# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										for model_name in ["bert-base-uncased"]:
																	lowerCamelCase_	:							Tuple									=AutoConfig.from_pretrained(__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

																	lowerCamelCase_	:							Optional[Any]									=TFAutoModelForQuestionAnswering.from_pretrained(__A       ,	from_pt=__A )
																	self.assertIsNotNone(__A )
																	self.assertIsInstance(__A       ,	__A )

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


			def      UpperCAmelCase__						(				self					:  Optional[int] ):
										lowerCamelCase_	:							List[Any]									=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 )

										lowerCamelCase_	:							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 )


			def      UpperCAmelCase__						(				self					:  str ):
										lowerCamelCase_	:							Any									=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 )

										lowerCamelCase_	:							List[Any]									=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 )











"""simple docstring"""



import torch

def 			_snake_case    (					)    ->     Union[str, Any]:
							if torch.cuda.is_available():
														lowerCamelCase_	:							int									=torch.cuda.device_count()
							else:
														lowerCamelCase_	:							List[str]									=0
							print(F"""Successfully ran on {num_gpus} GPUs"""  )


if __name__ == "__main__":
						main()



