




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











from timeit import timeit

def   a_    ( lowerCAmelCase_      :			int	):
   if number < 0:
      raise ValueError('the value of input must not be negative'	)
   __lowerCAmelCase								=	0
   while number:
      number &= number - 1
      result += 1
   return result

def   a_    ( lowerCAmelCase_      :			int	):
   if number < 0:
      raise ValueError('the value of input must not be negative'	)
   __lowerCAmelCase								=	0
   while number:
      if number % 2 == 1:
         result += 1
      number >>= 1
   return result

def   a_    ( ):

   def do_benchmark(lowerCAmelCase_      :			int	) -> None:
      __lowerCAmelCase								=	'import __main__ as z'
      print(F"""Benchmark when {number = }:"""	)
      print(F"""{get_set_bits_count_using_modulo_operator(lowerCAmelCase_	) = }"""	)
      __lowerCAmelCase								=	timeit('z.get_set_bits_count_using_modulo_operator(25)',	setup=lowerCAmelCase_	)
      print(F"""timeit() runs in {timing} seconds"""	)
      print(F"""{get_set_bits_count_using_brian_kernighans_algorithm(lowerCAmelCase_	) = }"""	)
      __lowerCAmelCase								=	timeit(
          'z.get_set_bits_count_using_brian_kernighans_algorithm(25)',	setup=lowerCAmelCase_,	)
      print(F"""timeit() runs in {timing} seconds"""	)

   for number in (25, 37, 58, 0):
      do_benchmark(lowerCAmelCase_	)
      print()


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     benchmark()

