




'''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   __UpperCamelCase       ( unittest.TestCase				):






       @slow
       def      lowercase__     (							self  ):



              """simple docstring"""







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

                     lowerCamelCase_							=TFAutoModel.from_pretrained(lowerCAmelCase,		from_pt=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )

                     lowerCamelCase_							=AutoModel.from_pretrained(lowerCAmelCase,		from_tf=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )






       @slow
       def      lowercase__     (							self  ):



              """simple docstring"""







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

                     lowerCamelCase_							=TFAutoModelForPreTraining.from_pretrained(lowerCAmelCase,		from_pt=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )

                     lowerCamelCase_							=AutoModelForPreTraining.from_pretrained(lowerCAmelCase,		from_tf=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )






       @slow
       def      lowercase__     (							self  ):



              """simple docstring"""







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

                     lowerCamelCase_							=TFAutoModelForCausalLM.from_pretrained(lowerCAmelCase,		from_pt=lowerCAmelCase  )
                     lowerCamelCase_,      lowerCamelCase_							=TFAutoModelForCausalLM.from_pretrained(
                         lowerCAmelCase,		output_loading_info=lowerCAmelCase,		from_pt=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )

                     lowerCamelCase_							=AutoModelForCausalLM.from_pretrained(lowerCAmelCase,		from_tf=lowerCAmelCase  )
                     lowerCamelCase_,      lowerCamelCase_							=AutoModelForCausalLM.from_pretrained(
                         lowerCAmelCase,		output_loading_info=lowerCAmelCase,		from_tf=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )






       @slow
       def      lowercase__     (							self  ):



              """simple docstring"""







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

                     lowerCamelCase_							=TFAutoModelWithLMHead.from_pretrained(lowerCAmelCase,		from_pt=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )

                     lowerCamelCase_							=AutoModelWithLMHead.from_pretrained(lowerCAmelCase,		from_tf=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )






       @slow
       def      lowercase__     (							self  ):



              """simple docstring"""







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

                     lowerCamelCase_							=TFAutoModelForMaskedLM.from_pretrained(lowerCAmelCase,		from_pt=lowerCAmelCase  )
                     lowerCamelCase_,      lowerCamelCase_							=TFAutoModelForMaskedLM.from_pretrained(
                         lowerCAmelCase,		output_loading_info=lowerCAmelCase,		from_pt=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )

                     lowerCamelCase_							=AutoModelForMaskedLM.from_pretrained(lowerCAmelCase,		from_tf=lowerCAmelCase  )
                     lowerCamelCase_,      lowerCamelCase_							=AutoModelForMaskedLM.from_pretrained(
                         lowerCAmelCase,		output_loading_info=lowerCAmelCase,		from_tf=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )






       @slow
       def      lowercase__     (							self  ):



              """simple docstring"""







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

                     lowerCamelCase_							=TFAutoModelForSeqaSeqLM.from_pretrained(lowerCAmelCase,		from_pt=lowerCAmelCase  )
                     lowerCamelCase_,      lowerCamelCase_							=TFAutoModelForSeqaSeqLM.from_pretrained(
                         lowerCAmelCase,		output_loading_info=lowerCAmelCase,		from_pt=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )

                     lowerCamelCase_							=AutoModelForSeqaSeqLM.from_pretrained(lowerCAmelCase,		from_tf=lowerCAmelCase  )
                     lowerCamelCase_,      lowerCamelCase_							=AutoModelForSeqaSeqLM.from_pretrained(
                         lowerCAmelCase,		output_loading_info=lowerCAmelCase,		from_tf=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )






       @slow
       def      lowercase__     (							self  ):



              """simple docstring"""







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

                     lowerCamelCase_							=TFAutoModelForSequenceClassification.from_pretrained(lowerCAmelCase,		from_pt=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )

                     lowerCamelCase_							=AutoModelForSequenceClassification.from_pretrained(lowerCAmelCase,		from_tf=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )






       @slow
       def      lowercase__     (							self  ):



              """simple docstring"""







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

                     lowerCamelCase_							=TFAutoModelForQuestionAnswering.from_pretrained(lowerCAmelCase,		from_pt=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )

                     lowerCamelCase_							=AutoModelForQuestionAnswering.from_pretrained(lowerCAmelCase,		from_tf=lowerCAmelCase  )
                     self.assertIsNotNone(lowerCAmelCase  )
                     self.assertIsInstance(lowerCAmelCase,		lowerCAmelCase  )






       def      lowercase__     (							self  ):



              """simple docstring"""







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

              lowerCamelCase_							=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      lowercase__     (							self  ):



              """simple docstring"""







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

              lowerCamelCase_							=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 os
import unittest

from transformers import LayoutLMTokenizer, LayoutLMTokenizerFast
from transformers.models.layoutlm.tokenization_layoutlm import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin






@require_tokenizers
class 						_A  (  _a    ,unittest.TestCase  ):







    """simple docstring"""




    UpperCAmelCase       :							str	=       LayoutLMTokenizer
    UpperCAmelCase       :							int	=       LayoutLMTokenizerFast
    UpperCAmelCase       :							Union[str, Any]	=       True
    UpperCAmelCase       :							Optional[Any]	=       True






    def 	__snake_case							(					self				:    Optional[int]):
      super().setUp()

      a						:		Tuple      							=			[
          "[UNK]",
          "[CLS]",
          "[SEP]",
          "want",
          "##want",
          "##ed",
          "wa",
          "un",
          "runn",
          "##ing",
          ",",
          "low",
          "lowest",
      ]
      a						:		Optional[Any]      							=			os.path.join(self.tmpdirname				, VOCAB_FILES_NAMES["vocab_file"])
      with open(self.vocab_file				, "w"				, encoding="utf-8") as vocab_writer:
        vocab_writer.write("".join([x + "\n" for x in vocab_tokens]))






    def 	__snake_case							(					self				:    Optional[int]				, **__UpperCAmelCase				:    Tuple):
      return LayoutLMTokenizer.from_pretrained(self.tmpdirname				, **__UpperCAmelCase)






    def 	__snake_case							(					self				:    Union[str, Any]				, __UpperCAmelCase				:    str):
      a						:		Tuple      							=			"UNwant\u00E9d,running"
      a						:		Dict      							=			"unwanted, running"
      return input_text, output_text






    def 	__snake_case							(					self				:    Any):
      a						:		List[Any]      							=			self.tokenizer_class(self.vocab_file)

      a						:		str      							=			tokenizer.tokenize("UNwant\u00E9d,running")
      self.assertListEqual(__UpperCAmelCase				, ["un", "##want", "##ed", ",", "runn", "##ing"])
      self.assertListEqual(tokenizer.convert_tokens_to_ids(__UpperCAmelCase)				, [7, 4, 5, 10, 8, 9])






    def 	__snake_case							(					self				:    Dict):
      pass






