




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

import unittest

from transformers import OpenAIGPTConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
    import tensorflow as tf

    from transformers.models.openai.modeling_tf_openai import (
        TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFOpenAIGPTDoubleHeadsModel,
        TFOpenAIGPTForSequenceClassification,
        TFOpenAIGPTLMHeadModel,
        TFOpenAIGPTModel,
    )







class  _SCREAMING_SNAKE_CASE       :



 '''simple docstring'''





 def __init__(self					,     lowerCAmelCase__					,     ):

  '''simple docstring'''







  _UpperCamelCase      :	List[Any]					      =  parent
  _UpperCamelCase      :	int					      =  13
  _UpperCamelCase      :	Union[str, Any]					      =  7
  _UpperCamelCase      :	List[Any]					      =  True
  _UpperCamelCase      :	int					      =  True
  _UpperCamelCase      :	Any					      =  True
  _UpperCamelCase      :	Optional[Any]					      =  True
  _UpperCamelCase      :	Optional[Any]					      =  True
  _UpperCamelCase      :	Optional[Any]					      =  99
  _UpperCamelCase      :	Union[str, Any]					      =  32
  _UpperCamelCase      :	int					      =  2
  _UpperCamelCase      :	Optional[Any]					      =  4
  _UpperCamelCase      :	Dict					      =  37
  _UpperCamelCase      :	Dict					      =  "gelu"
  _UpperCamelCase      :	Any					      =  0.1
  _UpperCamelCase      :	Optional[int]					      =  0.1
  _UpperCamelCase      :	int					      =  5_12
  _UpperCamelCase      :	List[Any]					      =  16
  _UpperCamelCase      :	Optional[Any]					      =  2
  _UpperCamelCase      :	List[Any]					      =  0.02
  _UpperCamelCase      :	List[Any]					      =  3
  _UpperCamelCase      :	List[str]					      =  4
  _UpperCamelCase      :	Tuple					      =  None
  _UpperCamelCase      :	Union[str, Any]					      =  self.vocab_size - 1






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	int					      =  ids_tensor([self.batch_size, self.seq_length]					,     self.vocab_size   )

  _UpperCamelCase      :	Any					      =  None
  if self.use_input_mask:
   _UpperCamelCase      :	Optional[Any]					      =  random_attention_mask([self.batch_size, self.seq_length]   )

  _UpperCamelCase      :	Any					      =  None
  if self.use_token_type_ids:
   _UpperCamelCase      :	str					      =  ids_tensor([self.batch_size, self.seq_length]					,     self.type_vocab_size   )

  _UpperCamelCase      :	Tuple					      =  None
  if self.use_mc_token_ids:
   _UpperCamelCase      :	str					      =  ids_tensor([self.batch_size, self.num_choices]					,     self.seq_length   )

  _UpperCamelCase      :	Any					      =  None
  _UpperCamelCase      :	Tuple					      =  None
  _UpperCamelCase      :	Optional[int]					      =  None
  if self.use_labels:
   _UpperCamelCase      :	Union[str, Any]					      =  ids_tensor([self.batch_size]					,     self.type_sequence_label_size   )
   _UpperCamelCase      :	List[str]					      =  ids_tensor([self.batch_size, self.seq_length]					,     self.num_labels   )
   _UpperCamelCase      :	Dict					      =  ids_tensor([self.batch_size]					,     self.num_choices   )

  _UpperCamelCase      :	Union[str, Any]					      =  OpenAIGPTConfig(
      vocab_size=self.vocab_size					,     n_embd=self.hidden_size					,     n_layer=self.num_hidden_layers					,     n_head=self.num_attention_heads					,     n_positions=self.max_position_embeddings					,     pad_token_id=self.pad_token_id					,     )

  _UpperCamelCase      :	List[Any]					      =  ids_tensor([self.num_hidden_layers, self.num_attention_heads]					,     2   )

  return (
      config,
      input_ids,
      input_mask,
      head_mask,
      token_type_ids,
      mc_token_ids,
      sequence_labels,
      token_labels,
      choice_labels,
  )






 def lowercase_      (self					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     *lowerCAmelCase__   ):

  '''simple docstring'''







  _UpperCamelCase      :	Tuple					      =  TFOpenAIGPTModel(config=lowerCAmelCase__   )
  _UpperCamelCase      :	Optional[Any]					      =  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
  _UpperCamelCase      :	Optional[int]					      =  model(lowerCAmelCase__   )

  _UpperCamelCase      :	Optional[Any]					      =  [input_ids, input_mask]
  _UpperCamelCase      :	Union[str, Any]					      =  model(lowerCAmelCase__   )

  _UpperCamelCase      :	Optional[Any]					      =  model(lowerCAmelCase__   )

  self.parent.assertEqual(result.last_hidden_state.shape					,     (self.batch_size, self.seq_length, self.hidden_size)   )






 def lowercase_      (self					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     *lowerCAmelCase__   ):

  '''simple docstring'''







  _UpperCamelCase      :	Dict					      =  TFOpenAIGPTLMHeadModel(config=lowerCAmelCase__   )
  _UpperCamelCase      :	Optional[Any]					      =  {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
  _UpperCamelCase      :	Any					      =  model(lowerCAmelCase__   )
  self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.seq_length, self.vocab_size)   )






 def lowercase_      (self					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     *lowerCAmelCase__   ):

  '''simple docstring'''







  _UpperCamelCase      :	str					      =  TFOpenAIGPTDoubleHeadsModel(config=lowerCAmelCase__   )

  _UpperCamelCase      :	int					      =  tf.tile(tf.expand_dims(lowerCAmelCase__					,     1   )					,     (1, self.num_choices, 1)   )
  _UpperCamelCase      :	Tuple					      =  tf.tile(tf.expand_dims(lowerCAmelCase__					,     1   )					,     (1, self.num_choices, 1)   )
  _UpperCamelCase      :	Union[str, Any]					      =  tf.tile(tf.expand_dims(lowerCAmelCase__					,     1   )					,     (1, self.num_choices, 1)   )

  _UpperCamelCase      :	List[Any]					      =  {
      "input_ids": multiple_choice_inputs_ids,
      "mc_token_ids": mc_token_ids,
      "attention_mask": multiple_choice_input_mask,
      "token_type_ids": multiple_choice_token_type_ids,
  }
  _UpperCamelCase      :	Tuple					      =  model(lowerCAmelCase__   )
  self.parent.assertEqual(
      result.logits.shape					,     (self.batch_size, self.num_choices, self.seq_length, self.vocab_size)   )
  self.parent.assertEqual(result.mc_logits.shape					,     (self.batch_size, self.num_choices)   )






 def lowercase_      (self					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     *lowerCAmelCase__   ):

  '''simple docstring'''







  _UpperCamelCase      :	Union[str, Any]					      =  self.num_labels
  _UpperCamelCase      :	Tuple					      =  ids_tensor([self.batch_size]					,     self.type_sequence_label_size   )
  _UpperCamelCase      :	Optional[int]					      =  {
      "input_ids": input_ids,
      "attention_mask": input_mask,
      "token_type_ids": token_type_ids,
      "labels": sequence_labels,
  }
  _UpperCamelCase      :	Optional[int]					      =  TFOpenAIGPTForSequenceClassification(lowerCAmelCase__   )
  _UpperCamelCase      :	Optional[Any]					      =  model(lowerCAmelCase__   )
  self.parent.assertEqual(result.logits.shape					,     (self.batch_size, self.num_labels)   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	List[Any]					      =  self.prepare_config_and_inputs()

  (
      (
      _UpperCamelCase
  )      ,	(
      _UpperCamelCase
  )      ,	(
      _UpperCamelCase
  )      ,	(
      _UpperCamelCase
  )      ,	(
      _UpperCamelCase
  )      ,	(
      _UpperCamelCase
  )      ,	(
      _UpperCamelCase
  )      ,	(
      _UpperCamelCase
  )      ,	(
      _UpperCamelCase
  )      ,	
  )      :	Optional[int]					      =  config_and_inputs

  _UpperCamelCase      :	int					      =  {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
  return config, inputs_dict







@require_tf
class  _SCREAMING_SNAKE_CASE       (     SCREAMING_SNAKE_CASE__			,				SCREAMING_SNAKE_CASE__			,				unittest.TestCase				):



 '''simple docstring'''





 __UpperCAmelCase		   =							(
     (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
     if is_tf_available()
     else ()
 )
 __UpperCAmelCase		   =							(
     (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
 )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
 __UpperCAmelCase		   =							(
     {
         """feature-extraction""": TFOpenAIGPTModel,
         """text-classification""": TFOpenAIGPTForSequenceClassification,
         """text-generation""": TFOpenAIGPTLMHeadModel,
         """zero-shot""": TFOpenAIGPTForSequenceClassification,
     }
     if is_tf_available()
     else {}
 )
 __UpperCAmelCase		   =							False
 __UpperCAmelCase		   =							False






 def lowercase_      (self					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__   ):

  '''simple docstring'''







  if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
   # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
   # `OpenAIGPTConfig` was never used in pipeline tests, either because of a missing checkpoint or because a
   # tiny config could not be created.
   return True

  return False






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Optional[int]					      =  TFOpenAIGPTModelTester(self   )
  _UpperCamelCase      :	Any					      =  ConfigTester(self					,     config_class=lowerCAmelCase__					,     n_embd=37   )






 def lowercase_      (self   ):

  '''simple docstring'''







  self.config_tester.run_common_tests()






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Dict					      =  self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_openai_gpt_model(*lowerCAmelCase__   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Tuple					      =  self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_openai_gpt_lm_head(*lowerCAmelCase__   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	int					      =  self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_openai_gpt_double_head(*lowerCAmelCase__   )






 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Optional[int]					      =  self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*lowerCAmelCase__   )






 @slow
 def lowercase_      (self   ):

  '''simple docstring'''







  for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
   _UpperCamelCase      :	str					      =  TFOpenAIGPTModel.from_pretrained(lowerCAmelCase__   )
   self.assertIsNotNone(lowerCAmelCase__   )







@require_tf
class  _SCREAMING_SNAKE_CASE       (     unittest.TestCase				):



 '''simple docstring'''





 @slow
 def lowercase_      (self   ):

  '''simple docstring'''







  _UpperCamelCase      :	Tuple					      =  TFOpenAIGPTLMHeadModel.from_pretrained("openai-gpt"   )
  _UpperCamelCase      :	Optional[int]					      =  tf.convert_to_tensor([[4_81, 47_35, 5_44]]					,     dtype=tf.intaa   )  # the president is
  _UpperCamelCase      :	Optional[Any]					      =  [
      4_81,
      47_35,
      5_44,
      2_46,
      9_63,
      8_70,
      7_62,
      2_39,
      2_44,
      4_04_77,
      2_44,
      2_49,
      7_19,
      8_81,
      4_87,
      5_44,
      2_40,
      2_44,
      6_03,
      4_81,
  ]  # the president is a very good man. " \n " i\'m sure he is, " said the

  _UpperCamelCase      :	List[str]					      =  model.generate(lowerCAmelCase__					,     do_sample=lowerCAmelCase__   )
  self.assertListEqual(output_ids[0].numpy().tolist()					,     lowerCAmelCase__   )









"""simple docstring"""
import math






def 				__lowerCAmelCase					(					__lowerCAmelCase			:		Tuple						)    ->       Any:
 _UpperCamelCase      :	str					      =  0
 if n % 2 == 0:
  count += 1
  while n % 2 == 0:
   _UpperCamelCase      :	List[Any]					      =  int(n / 2						)
    # the n input value must be odd so that
    # we can skip one element (ie i += 2)

 _UpperCamelCase      :	Tuple					      =  3

 while i <= int(math.sqrt(__lowerCAmelCase						)						):
  if n % i == 0:
   count += 1
   while n % i == 0:
    _UpperCamelCase      :	Any					      =  int(n / i						)
  _UpperCamelCase      :	Optional[Any]					      =  i + 2

 # this condition checks the prime
 # number n is greater than 2

 if n > 2:
  count += 1
 return count


if __name__ == "__main__":
    _SCREAMING_SNAKE_CASE						 =     5_1_2_4_2_1_8_3
    print(f'The number of distinct prime factors is/are {exact_prime_factor_count(n)}')
    print(f'The value of log(log(n)) is {math.log(math.log(n)):.4f}')



