



'''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 					a__  (self       )    ->     Union[str, Any]:


      """simple docstring"""



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

           _a      =  TFAutoModel.from_pretrained(lowerCAmelCase__ ,   from_pt=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )

           _a      =  AutoModel.from_pretrained(lowerCAmelCase__ ,   from_tf=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )



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


      """simple docstring"""



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

           _a      =  TFAutoModelForPreTraining.from_pretrained(lowerCAmelCase__ ,   from_pt=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )

           _a      =  AutoModelForPreTraining.from_pretrained(lowerCAmelCase__ ,   from_tf=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )



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


      """simple docstring"""



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

           _a      =  TFAutoModelForCausalLM.from_pretrained(lowerCAmelCase__ ,   from_pt=lowerCAmelCase__       )
           _a      =  TFAutoModelForCausalLM.from_pretrained(
               lowerCAmelCase__ ,   output_loading_info=lowerCAmelCase__ ,   from_pt=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )

           _a      =  AutoModelForCausalLM.from_pretrained(lowerCAmelCase__ ,   from_tf=lowerCAmelCase__       )
           _a      =  AutoModelForCausalLM.from_pretrained(
               lowerCAmelCase__ ,   output_loading_info=lowerCAmelCase__ ,   from_tf=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )



 @slow
 def 					a__  (self       )    ->     Dict:


      """simple docstring"""



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

           _a      =  TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase__ ,   from_pt=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )

           _a      =  AutoModelWithLMHead.from_pretrained(lowerCAmelCase__ ,   from_tf=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )



 @slow
 def 					a__  (self       )    ->     Tuple:


      """simple docstring"""



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

           _a      =  TFAutoModelForMaskedLM.from_pretrained(lowerCAmelCase__ ,   from_pt=lowerCAmelCase__       )
           _a      =  TFAutoModelForMaskedLM.from_pretrained(
               lowerCAmelCase__ ,   output_loading_info=lowerCAmelCase__ ,   from_pt=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )

           _a      =  AutoModelForMaskedLM.from_pretrained(lowerCAmelCase__ ,   from_tf=lowerCAmelCase__       )
           _a      =  AutoModelForMaskedLM.from_pretrained(
               lowerCAmelCase__ ,   output_loading_info=lowerCAmelCase__ ,   from_tf=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )



 @slow
 def 					a__  (self       )    ->     List[str]:


      """simple docstring"""



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

           _a      =  TFAutoModelForSeqaSeqLM.from_pretrained(lowerCAmelCase__ ,   from_pt=lowerCAmelCase__       )
           _a      =  TFAutoModelForSeqaSeqLM.from_pretrained(
               lowerCAmelCase__ ,   output_loading_info=lowerCAmelCase__ ,   from_pt=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )

           _a      =  AutoModelForSeqaSeqLM.from_pretrained(lowerCAmelCase__ ,   from_tf=lowerCAmelCase__       )
           _a      =  AutoModelForSeqaSeqLM.from_pretrained(
               lowerCAmelCase__ ,   output_loading_info=lowerCAmelCase__ ,   from_tf=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )



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


      """simple docstring"""



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

           _a      =  TFAutoModelForSequenceClassification.from_pretrained(lowerCAmelCase__ ,   from_pt=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )

           _a      =  AutoModelForSequenceClassification.from_pretrained(lowerCAmelCase__ ,   from_tf=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )



 @slow
 def 					a__  (self       )    ->     List[str]:


      """simple docstring"""



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

           _a      =  TFAutoModelForQuestionAnswering.from_pretrained(lowerCAmelCase__ ,   from_pt=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )

           _a      =  AutoModelForQuestionAnswering.from_pretrained(lowerCAmelCase__ ,   from_tf=lowerCAmelCase__       )
           self.assertIsNotNone(lowerCAmelCase__       )
           self.assertIsInstance(lowerCAmelCase__ ,   lowerCAmelCase__       )



 def 					a__  (self       )    ->     Optional[Any]:


      """simple docstring"""



      _a      =  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       )

      _a      =  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 					a__  (self       )    ->     int:


      """simple docstring"""



      _a      =  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       )

      _a      =  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__      )
