



'''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 )					->  Optional[int]:


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


      """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						,					_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						,					_a											=						AutoModelForCausalLM.from_pretrained(
               lowerCAmelCase_				,     output_loading_info=lowerCAmelCase_				,     from_tf=lowerCAmelCase_ )
           self.assertIsNotNone(lowerCAmelCase_ )
           self.assertIsInstance(lowerCAmelCase_				,     lowerCAmelCase_ )



 @slow
 def       a__						(self )					->  Any:


      """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 )					->  Optional[int]:


      """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						,					_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						,					_a											=						AutoModelForMaskedLM.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_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						,					_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						,					_a											=						AutoModelForSeqaSeqLM.from_pretrained(
               lowerCAmelCase_				,     output_loading_info=lowerCAmelCase_				,     from_tf=lowerCAmelCase_ )
           self.assertIsNotNone(lowerCAmelCase_ )
           self.assertIsInstance(lowerCAmelCase_				,     lowerCAmelCase_ )



 @slow
 def       a__						(self )					->  List[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 )					->  Optional[int]:


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








'''simple docstring'''





import pytest

import datasets


# Import fixture modules as plugins
lowercase_	 =						["tests.fixtures.files", "tests.fixtures.hub", "tests.fixtures.fsspec"]




def lowerCAmelCase						(__A						,			__A):



     """simple docstring"""



     for item in items:
          if any(marker in item.keywords for marker in ['''integration''', '''unit''']):
               continue
          item.add_marker(pytest.mark.unit)




def lowerCAmelCase						(__A):



     """simple docstring"""



     config.addinivalue_line('''markers'''						,			'''torchaudio_latest: mark test to run with torchaudio>=0.12''')




@pytest.fixture(autouse=__A)
def lowerCAmelCase						(__A						,			__A):



     """simple docstring"""



     _a											=						tmp_path_factory.getbasetemp() / '''cache'''
     _a											=						test_hf_cache_home / '''datasets'''
     _a											=						test_hf_cache_home / '''metrics'''
     _a											=						test_hf_cache_home / '''modules'''
     monkeypatch.setattr('''datasets.config.HF_DATASETS_CACHE'''						,			str(__A))
     monkeypatch.setattr('''datasets.config.HF_METRICS_CACHE'''						,			str(__A))
     monkeypatch.setattr('''datasets.config.HF_MODULES_CACHE'''						,			str(__A))
     _a											=						test_hf_datasets_cache / '''downloads'''
     monkeypatch.setattr('''datasets.config.DOWNLOADED_DATASETS_PATH'''						,			str(__A))
     _a											=						test_hf_datasets_cache / '''downloads''' / '''extracted'''
     monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_PATH'''						,			str(__A))




@pytest.fixture(autouse=__A						,			scope='''session''')
def lowerCAmelCase						():



     """simple docstring"""



     datasets.disable_progress_bar()




@pytest.fixture(autouse=__A)
def lowerCAmelCase						(__A):



     """simple docstring"""



     monkeypatch.setattr('''datasets.config.HF_UPDATE_DOWNLOAD_COUNTS'''						,			__A)




@pytest.fixture
def lowerCAmelCase						(__A):



     """simple docstring"""



     monkeypatch.setattr('''sqlalchemy.util.deprecations.SILENCE_UBER_WARNING'''						,			__A)



