






"""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 		snake_case    :





    def __init__(				self      :   List[str]							,						A      :   Optional[Any]							,						):


      '''simple docstring'''




      a	:     Dict							=  parent
      a	:     Tuple							=  1_3
      a	:     Tuple							=  7
      a	:     Any							=  True
      a	:     List[str]							=  True
      a	:     Optional[Any]							=  True
      a	:     Optional[int]							=  True
      a	:     Dict							=  True
      a	:     int							=  9_9
      a	:     int							=  3_2
      a	:     int							=  2
      a	:     Tuple							=  4
      a	:     int							=  3_7
      a	:     Dict							=  'gelu'
      a	:     Optional[int]							=  0.1
      a	:     List[str]							=  0.1
      a	:     int							=  5_1_2
      a	:     Optional[int]							=  1_6
      a	:     int							=  2
      a	:     Dict							=  0.02
      a	:     int							=  3
      a	:     Dict							=  4
      a	:     int							=  None
      a	:     int							=  self.vocab_size - 1





    def 							lowerCamelCase__ (				self      :   str     ):


      '''simple docstring'''




      a	:     Dict							=  ids_tensor([self.batch_size, self.seq_length]							,						self.vocab_size     )

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

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

      a	:     List[Any]							=  None
      if self.use_mc_token_ids:
        a	:     List[Any]							=  ids_tensor([self.batch_size, self.num_choices]							,						self.seq_length     )

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

      a	:     str							=  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							,						)

      a	:     Union[str, 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 							lowerCamelCase__ (				self      :   Optional[Any]							,						A      :   List[str]							,						A      :   int							,						A      :   List[str]							,						A      :   str							,						A      :   Optional[Any]							,						*A      :   Optional[Any]     ):


      '''simple docstring'''




      a	:     int							=  TFOpenAIGPTModel(config=A     )
      a	:     str							=  {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
      a	:     Union[str, Any]							=  model(A     )

      a	:     List[Any]							=  [input_ids, input_mask]
      a	:     Tuple							=  model(A     )

      a	:     List[Any]							=  model(A     )

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





    def 							lowerCamelCase__ (				self      :   Optional[Any]							,						A      :   Any							,						A      :   Union[str, Any]							,						A      :   int							,						A      :   Any							,						A      :   List[Any]							,						*A      :   Tuple     ):


      '''simple docstring'''




      a	:     Optional[Any]							=  TFOpenAIGPTLMHeadModel(config=A     )
      a	:     Optional[int]							=  {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
      a	:     int							=  model(A     )
      self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.seq_length, self.vocab_size)     )





    def 							lowerCamelCase__ (				self      :   Optional[Any]							,						A      :   Optional[int]							,						A      :   Dict							,						A      :   str							,						A      :   int							,						A      :   str							,						A      :   Optional[int]							,						*A      :   Optional[int]     ):


      '''simple docstring'''




      a	:     Any							=  TFOpenAIGPTDoubleHeadsModel(config=A     )

      a	:     Any							=  tf.tile(tf.expand_dims(A							,						1     )							,						(1, self.num_choices, 1)     )
      a	:     Union[str, Any]							=  tf.tile(tf.expand_dims(A							,						1     )							,						(1, self.num_choices, 1)     )
      a	:     List[Any]							=  tf.tile(tf.expand_dims(A							,						1     )							,						(1, self.num_choices, 1)     )

      a	:     int							=  {
          '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,
      }
      a	:     Union[str, Any]							=  model(A     )
      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 							lowerCamelCase__ (				self      :   Tuple							,						A      :   int							,						A      :   List[Any]							,						A      :   int							,						A      :   Any							,						A      :   Optional[Any]							,						*A      :   Any     ):


      '''simple docstring'''




      a	:     Union[str, Any]							=  self.num_labels
      a	:     Dict							=  ids_tensor([self.batch_size]							,						self.type_sequence_label_size     )
      a	:     Any							=  {
          'input_ids': input_ids,
          'attention_mask': input_mask,
          'token_type_ids': token_type_ids,
          'labels': sequence_labels,
      }
      a	:     int							=  TFOpenAIGPTForSequenceClassification(A     )
      a	:     int							=  model(A     )
      self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.num_labels)     )





    def 							lowerCamelCase__ (				self      :   Union[str, Any]     ):


      '''simple docstring'''




      a	:     str							=  self.prepare_config_and_inputs()

      (
          (
          a
      ),	(
          a
      ),	(
          a
      ),	(
          a
      ),	(
          a
      ),	(
          a
      ),	(
          a
      ),	(
          a
      ),	(
          a
      ),	
      )	:     int							=  config_and_inputs

      a	:     List[Any]							=  {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
      return config, inputs_dict






@require_tf
class 		snake_case    (    UpperCAmelCase  ,					UpperCAmelCase  ,					unittest.TestCase			):
    __magic_name__       	=	(
        (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
        if is_tf_available()
        else ()
    )
    __magic_name__       	=	(
        (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
    )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
    __magic_name__       	=	(
        {
            '''feature-extraction''': TFOpenAIGPTModel,
            '''text-classification''': TFOpenAIGPTForSequenceClassification,
            '''text-generation''': TFOpenAIGPTLMHeadModel,
            '''zero-shot''': TFOpenAIGPTForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )
    __magic_name__       	=	False
    __magic_name__       	=	False





    def 							lowerCamelCase__ (				self      :   Any							,						A      :   List[str]							,						A      :   str							,						A      :   Optional[int]							,						A      :   List[str]							,						A      :   List[Any]     ):


      '''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 							lowerCamelCase__ (				self      :   int     ):


      '''simple docstring'''




      a	:     Optional[Any]							=  TFOpenAIGPTModelTester(self     )
      a	:     Any							=  ConfigTester(self							,						config_class=A							,						n_embd=3_7     )





    def 							lowerCamelCase__ (				self      :   Union[str, Any]     ):


      '''simple docstring'''




      self.config_tester.run_common_tests()





    def 							lowerCamelCase__ (				self      :   Any     ):


      '''simple docstring'''




      a	:     List[str]							=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_openai_gpt_model(*A     )





    def 							lowerCamelCase__ (				self      :   Tuple     ):


      '''simple docstring'''




      a	:     Optional[Any]							=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_openai_gpt_lm_head(*A     )





    def 							lowerCamelCase__ (				self      :   List[str]     ):


      '''simple docstring'''




      a	:     Tuple							=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_openai_gpt_double_head(*A     )





    def 							lowerCamelCase__ (				self      :   Optional[Any]     ):


      '''simple docstring'''




      a	:     Any							=  self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*A     )





    @slow
    def 							lowerCamelCase__ (				self      :   Optional[Any]     ):


      '''simple docstring'''




      for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        a	:     Any							=  TFOpenAIGPTModel.from_pretrained(A     )
        self.assertIsNotNone(A     )






@require_tf
class 		snake_case    (    unittest.TestCase			):





    @slow
    def 							lowerCamelCase__ (				self      :   Dict     ):


      '''simple docstring'''




      a	:     str							=  TFOpenAIGPTLMHeadModel.from_pretrained('openai-gpt'     )
      a	:     Any							=  tf.convert_to_tensor([[4_8_1, 4_7_3_5, 5_4_4]]							,						dtype=tf.intaa     )  # the president is
      a	:     List[str]							=  [
          4_8_1,
          4_7_3_5,
          5_4_4,
          2_4_6,
          9_6_3,
          8_7_0,
          7_6_2,
          2_3_9,
          2_4_4,
          4_0_4_7_7,
          2_4_4,
          2_4_9,
          7_1_9,
          8_8_1,
          4_8_7,
          5_4_4,
          2_4_0,
          2_4_4,
          6_0_3,
          4_8_1,
      ]  # the president is a very good man. " \n " i\'m sure he is, " said the

      a	:     Any							=  model.generate(A							,						do_sample=A     )
      self.assertListEqual(output_ids[0].numpy().tolist()							,						A     )












"""simple docstring"""


from doctest import testmod
from math import sqrt




def      snake_case    (A_ :int ):







  '''simple docstring'''

  a	:     list[int]							=  []
  if num < 1:
    return facs
  facs.append(1 )
  if num == 1:
    return facs
  facs.append(A_ )
  for i in range(2      ,     int(sqrt(A_ ) ) + 1 ):
    if num % i == 0:  # If i is a factor of num
      facs.append(A_ )
      a	:     Optional[Any]							=  num // i  # num//i is the other factor of num
      if d != i:  # If d and i are distinct
        facs.append(A_ )  # we have found another factor
  facs.sort()
  return facs


if __name__ == "__main__":
   testmod(name='factors_of_a_number', verbose=True)




