


import sacrebleu as scb
from packaging import version
from sacrebleu import CHRF

import datasets


_UpperCAmelCase	:     Optional[int]   ="""\\n@inproceedings{popovic-2015-chrf,\n    title = \"chr{F}: character n-gram {F}-score for automatic {MT} evaluation\",\n    author = \"Popovi{\'c}, Maja\",\n    booktitle = \"Proceedings of the Tenth Workshop on Statistical Machine Translation\",\n    month = sep,\n    year = \"2015\",\n    address = \"Lisbon, Portugal\",\n    publisher = \"Association for Computational Linguistics\",\n    url = \"https://aclanthology.org/W15-3049\",\n    doi = \"10.18653/v1/W15-3049\",\n    pages = \"392--395\",\n}\n@inproceedings{popovic-2017-chrf,\n    title = \"chr{F}++: words helping character n-grams\",\n    author = \"Popovi{\'c}, Maja\",\n    booktitle = \"Proceedings of the Second Conference on Machine Translation\",\n    month = sep,\n    year = \"2017\",\n    address = \"Copenhagen, Denmark\",\n    publisher = \"Association for Computational Linguistics\",\n    url = \"https://aclanthology.org/W17-4770\",\n    doi = \"10.18653/v1/W17-4770\",\n    pages = \"612--618\",\n}\n@inproceedings{post-2018-call,\n    title = \"A Call for Clarity in Reporting {BLEU} Scores\",\n    author = \"Post, Matt\",\n    booktitle = \"Proceedings of the Third Conference on Machine Translation: Research Papers\",\n    month = oct,\n    year = \"2018\",\n    address = \"Belgium, Brussels\",\n    publisher = \"Association for Computational Linguistics\",\n    url = \"https://www.aclweb.org/anthology/W18-6319\",\n    pages = \"186--191\",\n}\n"""

_UpperCAmelCase	:     Optional[int]   ="""\\nChrF and ChrF++ are two MT evaluation metrics. They both use the F-score statistic for character n-gram matches,\nand ChrF++ adds word n-grams as well which correlates more strongly with direct assessment. We use the implementation\nthat is already present in sacrebleu.\n\nThe implementation here is slightly different from sacrebleu in terms of the required input format. The length of\nthe references and hypotheses lists need to be the same, so you may need to transpose your references compared to\nsacrebleu's required input format. See https://github.com/huggingface/datasets/issues/3154#issuecomment-950746534\n\nSee the README.md file at https://github.com/mjpost/sacreBLEU#chrf--chrf for more information.\n"""

_UpperCAmelCase	:     int   ="""\nProduces ChrF(++) scores for hypotheses given reference translations.\n\nArgs:\n    predictions (list of str): The predicted sentences.\n    references (list of list of str): The references. There should be one reference sub-list for each prediction sentence.\n    char_order (int): Character n-gram order. Defaults to `6`.\n    word_order (int): Word n-gram order. If equals to `2`, the metric is referred to as chrF++. Defaults to `0`.\n    beta (int): Determine the importance of recall w.r.t precision. Defaults to `2`.\n    lowercase (bool): if `True`, enables case-insensitivity. Defaults to `False`.\n    whitespace (bool): If `True`, include whitespaces when extracting character n-grams.\n    eps_smoothing (bool): If `True`, applies epsilon smoothing similar\n    to reference chrF++.py, NLTK and Moses implementations. If `False`,\n    it takes into account effective match order similar to sacreBLEU < 2.0.0. Defaults to `False`.\n\nReturns:\n    'score' (float): The chrF (chrF++) score,\n    'char_order' (int): The character n-gram order,\n    'word_order' (int): The word n-gram order. If equals to 2, the metric is referred to as chrF++,\n    'beta' (int): Determine the importance of recall w.r.t precision\n\nExamples:\n    Example 1--a simple example of calculating chrF:\n        >>> prediction = [\"The relationship between cats and dogs is not exactly friendly.\", \"a good bookshop is just a genteel black hole that knows how to read.\"]\n        >>> reference = [[\"The relationship between dogs and cats is not exactly friendly.\"], [\"A good bookshop is just a genteel Black Hole that knows how to read.\"]]\n        >>> chrf = datasets.load_metric(\"chrf\")\n        >>> results = chrf.compute(predictions=prediction, references=reference)\n        >>> print(results)\n        {'score': 84.64214891738334, 'char_order': 6, 'word_order': 0, 'beta': 2}\n\n    Example 2--the same example, but with the argument word_order=2, to calculate chrF++ instead of chrF:\n        >>> prediction = [\"The relationship between cats and dogs is not exactly friendly.\", \"a good bookshop is just a genteel black hole that knows how to read.\"]\n        >>> reference = [[\"The relationship between dogs and cats is not exactly friendly.\"], [\"A good bookshop is just a genteel Black Hole that knows how to read.\"]]\n        >>> chrf = datasets.load_metric(\"chrf\")\n        >>> results = chrf.compute(predictions=prediction,\n        ...                         references=reference,\n        ...                         word_order=2)\n        >>> print(results)\n        {'score': 82.87263732906315, 'char_order': 6, 'word_order': 2, 'beta': 2}\n\n    Example 3--the same chrF++ example as above, but with `lowercase=True` to normalize all case:\n        >>> prediction = [\"The relationship between cats and dogs is not exactly friendly.\", \"a good bookshop is just a genteel black hole that knows how to read.\"]\n        >>> reference = [[\"The relationship between dogs and cats is not exactly friendly.\"], [\"A good bookshop is just a genteel Black Hole that knows how to read.\"]]\n        >>> chrf = datasets.load_metric(\"chrf\")\n        >>> results = chrf.compute(predictions=prediction,\n        ...                         references=reference,\n        ...                         word_order=2,\n        ...                         lowercase=True)\n        >>> print(results)\n        {'score': 92.12853119829202, 'char_order': 6, 'word_order': 2, 'beta': 2}\n"""







@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION,  _KWARGS_DESCRIPTION							)
class  snake_case__(							datasets.Metric							):







						'''simple docstring'''




						def   lowercase_       ( self							)    ->			Tuple:






										if version.parse(scb.__version__							) < version.parse('''1.4.12'''							):
														raise ImportWarning(
														    '''To use `sacrebleu`, the module `sacrebleu>=1.4.12` is required, and the current version of `sacrebleu` doesn\'t match this condition.\n'''
														    '''You can install it with `pip install "sacrebleu>=1.4.12"`.'''							)
										return datasets.MetricInfo(
										    description=_DESCRIPTION      ,  citation=_CITATION      ,  homepage='''https://github.com/mjpost/sacreBLEU#chrf--chrf'''      ,  inputs_description=_KWARGS_DESCRIPTION      ,  features=datasets.Features(
										        {
										            '''predictions''': datasets.Value('''string'''      ,  id='''sequence'''							),
										            '''references''': datasets.Sequence(datasets.Value('''string'''      ,  id='''sequence'''							)      ,  id='''references'''							),
										        }							)      ,  codebase_urls=['''https://github.com/mjpost/sacreBLEU#chrf--chrf''']      ,  reference_urls=[
										        '''https://github.com/m-popovic/chrF''',
										    ]      ,  )




						def   lowercase_       ( self      ,  __lowercase      ,  __lowercase      ,  __lowercase = CHRF.CHAR_ORDER      ,  __lowercase = CHRF.WORD_ORDER      ,  __lowercase = CHRF.BETA      ,  __lowercase = False      ,  __lowercase = False      ,  __lowercase = False      ,  )    ->			str:
										lowerCAmelCase_       :					Optional[int]			 = len(references[0]							)
										if any(len(SCREAMING_SNAKE_CASE__							) != references_per_prediction for refs in references							):
														raise ValueError('''Sacrebleu requires the same number of references for each prediction'''							)
										lowerCAmelCase_       :					Optional[Any]			 = [[refs[i] for refs in references] for i in range(SCREAMING_SNAKE_CASE__							)]

										lowerCAmelCase_       :					str			 = CHRF(SCREAMING_SNAKE_CASE__      ,  SCREAMING_SNAKE_CASE__      ,  SCREAMING_SNAKE_CASE__      ,  SCREAMING_SNAKE_CASE__      ,  SCREAMING_SNAKE_CASE__      ,  SCREAMING_SNAKE_CASE__							)
										lowerCAmelCase_       :					Dict			 = sb_chrf.corpus_score(SCREAMING_SNAKE_CASE__      ,  SCREAMING_SNAKE_CASE__							)

										return {
										    "score": output.score,
										    "char_order": output.char_order,
										    "word_order": output.word_order,
										    "beta": output.beta,
										}






"""simple docstring"""
from __future__ import annotations

import copy
import tempfile
import unittest

from transformers import CONFIG_MAPPING, AutoConfig, BertConfig, GPTaConfig, TaConfig, TapasConfig, is_tf_available
from transformers.testing_utils import (
    DUMMY_UNKNOWN_IDENTIFIER,
    SMALL_MODEL_IDENTIFIER,
    RequestCounter,
    require_tensorflow_probability,
    require_tf,
    slow,
)

from ..bert.test_modeling_bert import BertModelTester


if is_tf_available():
  from transformers import (
      TFAutoModel,
      TFAutoModelForCausalLM,
      TFAutoModelForMaskedLM,
      TFAutoModelForPreTraining,
      TFAutoModelForQuestionAnswering,
      TFAutoModelForSeqaSeqLM,
      TFAutoModelForSequenceClassification,
      TFAutoModelForTableQuestionAnswering,
      TFAutoModelForTokenClassification,
      TFAutoModelWithLMHead,
      TFBertForMaskedLM,
      TFBertForPreTraining,
      TFBertForQuestionAnswering,
      TFBertForSequenceClassification,
      TFBertModel,
      TFFunnelBaseModel,
      TFFunnelModel,
      TFGPTaLMHeadModel,
      TFRobertaForMaskedLM,
      TFTaForConditionalGeneration,
      TFTapasForQuestionAnswering,
  )
  from transformers.models.auto.modeling_tf_auto import (
      TF_MODEL_FOR_CAUSAL_LM_MAPPING,
      TF_MODEL_FOR_MASKED_LM_MAPPING,
      TF_MODEL_FOR_PRETRAINING_MAPPING,
      TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
      TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
      TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
      TF_MODEL_MAPPING,
  )
  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
  from transformers.models.tapas.modeling_tf_tapas import TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST






class 					_SCREAMING_SNAKE_CASE(   A  ):
       SCREAMING_SNAKE_CASE_   :      int							=  '''new-model'''


if is_tf_available():






  class 					_SCREAMING_SNAKE_CASE(   A  ):
         SCREAMING_SNAKE_CASE_   :      Union[str, Any]							=  NewModelConfig






@require_tf
class 					_SCREAMING_SNAKE_CASE(   unittest.TestCase  ):




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Tuple						=  '''bert-base-cased'''
             __SCREAMING_SNAKE_CASE   :int						=  AutoConfig.from_pretrained(SCREAMING_SNAKE_CASE__							)
             self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
             self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

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




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Tuple						=  '''bert-base-cased'''
             __SCREAMING_SNAKE_CASE   :List[str]						=  AutoConfig.from_pretrained(SCREAMING_SNAKE_CASE__							)
             self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
             self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

             __SCREAMING_SNAKE_CASE   :str						=  TFAutoModelForPreTraining.from_pretrained(SCREAMING_SNAKE_CASE__							)
             self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
             self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)




       @slow
       def     _UpperCamelCase     (						self							)			->      Dict:





             """simple docstring"""






             for model_name in TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   __SCREAMING_SNAKE_CASE   :List[str]						=  AutoConfig.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

                   __SCREAMING_SNAKE_CASE   :Optional[int]						=  TFAutoModelForCausalLM.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   __SCREAMING_SNAKE_CASE				,__SCREAMING_SNAKE_CASE   :Dict						=  TFAutoModelForCausalLM.from_pretrained(SCREAMING_SNAKE_CASE__		,output_loading_info=SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)




       @slow
       def     _UpperCamelCase     (						self							)			->      int:





             """simple docstring"""






             for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   __SCREAMING_SNAKE_CASE   :List[str]						=  AutoConfig.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

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




       @slow
       def     _UpperCamelCase     (						self							)			->      Optional[int]:





             """simple docstring"""






             for model_name in TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  AutoConfig.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

                   __SCREAMING_SNAKE_CASE   :Tuple						=  TFAutoModelForMaskedLM.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   __SCREAMING_SNAKE_CASE				,__SCREAMING_SNAKE_CASE   :Tuple						=  TFAutoModelForMaskedLM.from_pretrained(SCREAMING_SNAKE_CASE__		,output_loading_info=SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)




       @slow
       def     _UpperCamelCase     (						self							)			->      Dict:





             """simple docstring"""






             for model_name in TF_T5_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   __SCREAMING_SNAKE_CASE   :Optional[Any]						=  AutoConfig.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

                   __SCREAMING_SNAKE_CASE   :str						=  TFAutoModelForSeqaSeqLM.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   __SCREAMING_SNAKE_CASE				,__SCREAMING_SNAKE_CASE   :Optional[int]						=  TFAutoModelForSeqaSeqLM.from_pretrained(SCREAMING_SNAKE_CASE__		,output_loading_info=SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)




       @slow
       def     _UpperCamelCase     (						self							)			->      Tuple:





             """simple docstring"""






             for model_name in ["bert-base-uncased"]:
                   __SCREAMING_SNAKE_CASE   :Optional[int]						=  AutoConfig.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

                   __SCREAMING_SNAKE_CASE   :List[str]						=  TFAutoModelForSequenceClassification.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)




       @slow
       def     _UpperCamelCase     (						self							)			->      Tuple:





             """simple docstring"""






             for model_name in ["bert-base-uncased"]:
                   __SCREAMING_SNAKE_CASE   :Optional[int]						=  AutoConfig.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

                   __SCREAMING_SNAKE_CASE   :Optional[Any]						=  TFAutoModelForQuestionAnswering.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)




       @slow
       @require_tensorflow_probability
       def     _UpperCamelCase     (						self							)			->      int:





             """simple docstring"""






             for model_name in TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST[5:6]:
                   __SCREAMING_SNAKE_CASE   :int						=  AutoConfig.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

                   __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  TFAutoModelForTableQuestionAnswering.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   __SCREAMING_SNAKE_CASE				,__SCREAMING_SNAKE_CASE   :Optional[int]						=  TFAutoModelForTableQuestionAnswering.from_pretrained(
                       SCREAMING_SNAKE_CASE__		,output_loading_info=SCREAMING_SNAKE_CASE__							)
                   self.assertIsNotNone(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)




       def     _UpperCamelCase     (						self							)			->      List[Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :int						=  TFAutoModelWithLMHead.from_pretrained(SCREAMING_SNAKE_CASE__							)
             self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)
             self.assertEqual(model.num_parameters()		,1_44_10							)
             self.assertEqual(model.num_parameters(only_trainable=SCREAMING_SNAKE_CASE__							)		,1_44_10							)




       def     _UpperCamelCase     (						self							)			->      str:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  TFAutoModelWithLMHead.from_pretrained(SCREAMING_SNAKE_CASE__							)
             self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)
             self.assertEqual(model.num_parameters()		,1_44_10							)
             self.assertEqual(model.num_parameters(only_trainable=SCREAMING_SNAKE_CASE__							)		,1_44_10							)




       def     _UpperCamelCase     (						self							)			->      Tuple:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  TFAutoModel.from_pretrained('''sgugger/funnel-random-tiny'''							)
             self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

             __SCREAMING_SNAKE_CASE   :str						=  copy.deepcopy(model.config							)
             __SCREAMING_SNAKE_CASE   :List[str]						=  ['''FunnelBaseModel''']
             __SCREAMING_SNAKE_CASE   :int						=  TFAutoModel.from_config(SCREAMING_SNAKE_CASE__							)
             self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

             with tempfile.TemporaryDirectory() as tmp_dir:
                   model.save_pretrained(SCREAMING_SNAKE_CASE__							)
                   __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  TFAutoModel.from_pretrained(SCREAMING_SNAKE_CASE__							)
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)




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





             """simple docstring"""






             try:
                   AutoConfig.register('''new-model'''		,SCREAMING_SNAKE_CASE__							)

                   __SCREAMING_SNAKE_CASE   :Tuple						=  [
                       TFAutoModel,
                       TFAutoModelForCausalLM,
                       TFAutoModelForMaskedLM,
                       TFAutoModelForPreTraining,
                       TFAutoModelForQuestionAnswering,
                       TFAutoModelForSequenceClassification,
                       TFAutoModelForTokenClassification,
                   ]

                   for auto_class in auto_classes:
                         with self.subTest(auto_class.__name__							):
                               # Wrong config class will raise an error
                               with self.assertRaises(SCREAMING_SNAKE_CASE__							):
                                     auto_class.register(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)
                               auto_class.register(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)
                               # Trying to register something existing in the Transformers library will raise an error
                               with self.assertRaises(SCREAMING_SNAKE_CASE__							):
                                     auto_class.register(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

                               # Now that the config is registered, it can be used as any other config with the auto-API
                               __SCREAMING_SNAKE_CASE   :Any						=  BertModelTester(self							).get_config()
                               __SCREAMING_SNAKE_CASE   :Dict						=  NewModelConfig(**tiny_config.to_dict()							)
                               __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  auto_class.from_config(SCREAMING_SNAKE_CASE__							)
                               self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

                               with tempfile.TemporaryDirectory() as tmp_dir:
                                     model.save_pretrained(SCREAMING_SNAKE_CASE__							)
                                     __SCREAMING_SNAKE_CASE   :str						=  auto_class.from_pretrained(SCREAMING_SNAKE_CASE__							)
                                     self.assertIsInstance(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)

             finally:
                   if "new-model" in CONFIG_MAPPING._extra_content:
                         del CONFIG_MAPPING._extra_content["new-model"]
                   for mapping in (
                       TF_MODEL_MAPPING,
                       TF_MODEL_FOR_PRETRAINING_MAPPING,
                       TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING,
                       TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
                       TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
                       TF_MODEL_FOR_CAUSAL_LM_MAPPING,
                       TF_MODEL_FOR_MASKED_LM_MAPPING,
                   ):
                         if NewModelConfig in mapping._extra_content:
                               del mapping._extra_content[NewModelConfig]




       def     _UpperCamelCase     (						self							)			->      int:





             """simple docstring"""






             with self.assertRaisesRegex(
                 SCREAMING_SNAKE_CASE__		,'''bert-base is not a local folder and is not a valid model identifier'''							):
                   __SCREAMING_SNAKE_CASE   :int						=  TFAutoModel.from_pretrained('''bert-base'''							)




       def     _UpperCamelCase     (						self							)			->      Any:





             """simple docstring"""






             with self.assertRaisesRegex(
                 SCREAMING_SNAKE_CASE__		,R'''aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'''							):
                   __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  TFAutoModel.from_pretrained(SCREAMING_SNAKE_CASE__		,revision='''aaaaaa'''							)




       def     _UpperCamelCase     (						self							)			->      List[str]:





             """simple docstring"""






             with self.assertRaisesRegex(
                 SCREAMING_SNAKE_CASE__		,'''hf-internal-testing/config-no-model does not appear to have a file named pytorch_model.bin'''		,):
                   __SCREAMING_SNAKE_CASE   :Optional[Any]						=  TFAutoModel.from_pretrained('''hf-internal-testing/config-no-model'''							)




       def     _UpperCamelCase     (						self							)			->      List[Any]:





             """simple docstring"""






             with self.assertRaisesRegex(SCREAMING_SNAKE_CASE__		,'''Use `from_pt=True` to load this model'''							):
                   __SCREAMING_SNAKE_CASE   :List[str]						=  TFAutoModel.from_pretrained('''hf-internal-testing/tiny-bert-pt-only'''							)




       def     _UpperCamelCase     (						self							)			->      List[str]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :int						=  TFAutoModel.from_pretrained('''hf-internal-testing/tiny-random-bert'''							)
             with RequestCounter() as counter:
                   __SCREAMING_SNAKE_CASE   :int						=  TFAutoModel.from_pretrained('''hf-internal-testing/tiny-random-bert'''							)
                   self.assertEqual(counter.get_request_count		,0							)
                   self.assertEqual(counter.head_request_count		,1							)
                   self.assertEqual(counter.other_request_count		,0							)

             # With a sharded checkpoint
             __SCREAMING_SNAKE_CASE   :Dict						=  TFAutoModel.from_pretrained('''ArthurZ/tiny-random-bert-sharded'''							)
             with RequestCounter() as counter:
                   __SCREAMING_SNAKE_CASE   :Optional[Any]						=  TFAutoModel.from_pretrained('''ArthurZ/tiny-random-bert-sharded'''							)
                   self.assertEqual(counter.get_request_count		,0							)
                   self.assertEqual(counter.head_request_count		,1							)
                   self.assertEqual(counter.other_request_count		,0							)