


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 		__magic_name__(       self			:int	)		->			Union[str, Any]:
										# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										for model_name in ["bert-base-uncased"]:
																__SCREAMING_SNAKE_CASE						:     Dict					=		AutoConfig.from_pretrained(lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     List[str]					=		TFAutoModel.from_pretrained(lowerCAmelCase__			,			from_pt=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     Dict					=		AutoModel.from_pretrained(lowerCAmelCase__			,			from_tf=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)


				@slow
				def 		__magic_name__(       self			:int	)		->			Union[str, Any]:
										# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										for model_name in ["bert-base-uncased"]:
																__SCREAMING_SNAKE_CASE						:     int					=		AutoConfig.from_pretrained(lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     Any					=		TFAutoModelForPreTraining.from_pretrained(lowerCAmelCase__			,			from_pt=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     int					=		AutoModelForPreTraining.from_pretrained(lowerCAmelCase__			,			from_tf=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)


				@slow
				def 		__magic_name__(       self			:int	)		->			List[Any]:
										for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																__SCREAMING_SNAKE_CASE						:     Tuple					=		AutoConfig.from_pretrained(lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     List[str]					=		TFAutoModelForCausalLM.from_pretrained(lowerCAmelCase__			,			from_pt=lowerCAmelCase__	)
																__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     List[str]					=		TFAutoModelForCausalLM.from_pretrained(
																    lowerCAmelCase__			,			output_loading_info=lowerCAmelCase__			,			from_pt=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     Dict					=		AutoModelForCausalLM.from_pretrained(lowerCAmelCase__			,			from_tf=lowerCAmelCase__	)
																__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     List[str]					=		AutoModelForCausalLM.from_pretrained(
																    lowerCAmelCase__			,			output_loading_info=lowerCAmelCase__			,			from_tf=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)


				@slow
				def 		__magic_name__(       self			:Optional[int]	)		->			Dict:
										for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		AutoConfig.from_pretrained(lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     Any					=		TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase__			,			from_pt=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     int					=		AutoModelWithLMHead.from_pretrained(lowerCAmelCase__			,			from_tf=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)


				@slow
				def 		__magic_name__(       self			:List[str]	)		->			Tuple:
										for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		AutoConfig.from_pretrained(lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		TFAutoModelForMaskedLM.from_pretrained(lowerCAmelCase__			,			from_pt=lowerCAmelCase__	)
																__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     Dict					=		TFAutoModelForMaskedLM.from_pretrained(
																    lowerCAmelCase__			,			output_loading_info=lowerCAmelCase__			,			from_pt=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

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


				@slow
				def 		__magic_name__(       self			:int	)		->			List[str]:
										for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																__SCREAMING_SNAKE_CASE						:     str					=		AutoConfig.from_pretrained(lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     Any					=		TFAutoModelForSeqaSeqLM.from_pretrained(lowerCAmelCase__			,			from_pt=lowerCAmelCase__	)
																__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		TFAutoModelForSeqaSeqLM.from_pretrained(
																    lowerCAmelCase__			,			output_loading_info=lowerCAmelCase__			,			from_pt=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		AutoModelForSeqaSeqLM.from_pretrained(lowerCAmelCase__			,			from_tf=lowerCAmelCase__	)
																__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     int					=		AutoModelForSeqaSeqLM.from_pretrained(
																    lowerCAmelCase__			,			output_loading_info=lowerCAmelCase__			,			from_tf=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)


				@slow
				def 		__magic_name__(       self			:Any	)		->			Union[str, Any]:
										# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										for model_name in ["bert-base-uncased"]:
																__SCREAMING_SNAKE_CASE						:     str					=		AutoConfig.from_pretrained(lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     Dict					=		TFAutoModelForSequenceClassification.from_pretrained(lowerCAmelCase__			,			from_pt=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     str					=		AutoModelForSequenceClassification.from_pretrained(lowerCAmelCase__			,			from_tf=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)


				@slow
				def 		__magic_name__(       self			:Tuple	)		->			List[str]:
										# for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										for model_name in ["bert-base-uncased"]:
																__SCREAMING_SNAKE_CASE						:     Dict					=		AutoConfig.from_pretrained(lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     Tuple					=		TFAutoModelForQuestionAnswering.from_pretrained(lowerCAmelCase__			,			from_pt=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)

																__SCREAMING_SNAKE_CASE						:     List[str]					=		AutoModelForQuestionAnswering.from_pretrained(lowerCAmelCase__			,			from_tf=lowerCAmelCase__	)
																self.assertIsNotNone(lowerCAmelCase__	)
																self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)


				def 		__magic_name__(       self			:List[str]	)		->			Optional[Any]:
										__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase__			,			from_pt=lowerCAmelCase__	)
										self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)
										self.assertEqual(model.num_parameters()			,			14_410	)
										self.assertEqual(model.num_parameters(only_trainable=lowerCAmelCase__	)			,			14_410	)

										__SCREAMING_SNAKE_CASE						:     Optional[int]					=		AutoModelWithLMHead.from_pretrained(lowerCAmelCase__			,			from_tf=lowerCAmelCase__	)
										self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)
										self.assertEqual(model.num_parameters()			,			14_410	)
										self.assertEqual(model.num_parameters(only_trainable=lowerCAmelCase__	)			,			14_410	)



				def 		__magic_name__(       self			:Any	)		->			int:
										__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase__			,			from_pt=lowerCAmelCase__	)
										self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)
										self.assertEqual(model.num_parameters()			,			14_410	)
										self.assertEqual(model.num_parameters(only_trainable=lowerCAmelCase__	)			,			14_410	)

										__SCREAMING_SNAKE_CASE						:     str					=		AutoModelWithLMHead.from_pretrained(lowerCAmelCase__			,			from_tf=lowerCAmelCase__	)
										self.assertIsInstance(lowerCAmelCase__			,			lowerCAmelCase__	)
										self.assertEqual(model.num_parameters()			,			14_410	)
										self.assertEqual(model.num_parameters(only_trainable=lowerCAmelCase__	)			,			14_410	)




import importlib.metadata
import operator
import re
import sys
from typing import Optional

from packaging import version


__lowerCAmelCase	: Union[str, Any]  				={
    '<': operator.lt,
    '<=': operator.le,
    '==': operator.eq,
    '!=': operator.ne,
    '>=': operator.ge,
    '>': operator.gt,
}


def        _UpperCamelCase							(      lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__      ):
						if got_ver is None or want_ver is None:
												raise ValueError(
												    F'''Unable to compare versions for {requirement}: need={want_ver} found={got_ver}. This is unusual. Consider'''
												    F''' reinstalling {pkg}.'''      )
						if not ops[op](version.parse(lowercase__      )    ,       version.parse(lowercase__      )      ):
												raise ImportError(
												    F'''{requirement} is required for a normal functioning of this module, but found {pkg}=={got_ver}.{hint}'''      )


def        _UpperCamelCase							(      lowercase__    ,       lowercase__ = None      ):
						__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		F'''\n{hint}''' if hint is not None else ''''''

						# non-versioned check
						if re.match(R'''^[\w_\-\d]+$'''    ,       lowercase__      ):
												__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     str					=		requirement, None, None
						else:
												__SCREAMING_SNAKE_CASE						:     List[Any]					=		re.findall(R'''^([^!=<>\s]+)([\s!=<>]{1,2}.+)'''    ,       lowercase__      )
												if not match:
																		raise ValueError(
																		    '''requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but'''
																		    F''' got {requirement}'''      )
												__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     Tuple					=		match[0]
												__SCREAMING_SNAKE_CASE						:     Optional[int]					=		want_full.split(''','''      )  # there could be multiple requirements
												__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		{}
												for w in want_range:
																		__SCREAMING_SNAKE_CASE						:     Any					=		re.findall(R'''^([\s!=<>]{1,2})(.+)'''    ,       lowercase__      )
																		if not match:
																								raise ValueError(
																								    '''requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23,'''
																								    F''' but got {requirement}'''      )
																		__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     Tuple					=		match[0]
																		__SCREAMING_SNAKE_CASE						:     List[Any]					=		want_ver
																		if op not in ops:
																								raise ValueError(F'''{requirement}: need one of {list(ops.keys()      )}, but got {op}'''      )

    # special case
						if pkg == "python":
												__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		'''.'''.join([str(lowercase__      ) for x in sys.version_info[:3]]      )
												for op, want_ver in wanted.items():
																		_compare_versions(lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__      )
												return

						# check if any version is installed
						try:
												__SCREAMING_SNAKE_CASE						:     Optional[int]					=		importlib.metadata.version(lowercase__      )
						except importlib.metadata.PackageNotFoundError:
												raise importlib.metadata.PackageNotFoundError(
												    F'''The \'{requirement}\' distribution was not found and is required by this application. {hint}'''      )

						# check that the right version is installed if version number or a range was provided
						if want_ver is not None:
												for op, want_ver in wanted.items():
																		_compare_versions(lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__    ,       lowercase__      )


def        _UpperCamelCase							(      lowercase__      ):
						__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		'''Try: pip install transformers -U or pip install -e \'.[dev]\' if you\'re working with git main'''
						return require_version(lowercase__    ,       lowercase__      )
