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


    '''simple docstring'''





    def __init__(  self					,       __lowerCamelCase					,       ):




         '''simple docstring'''



         __A					:					Union[str, Any]								=		parent
         __A					:					int								=		13
         __A					:					str								=		7
         __A					:					Tuple								=		True
         __A					:					List[Any]								=		True
         __A					:					Union[str, Any]								=		True
         __A					:					List[str]								=		True
         __A					:					Tuple								=		True
         __A					:					List[str]								=		99
         __A					:					Dict								=		32
         __A					:					List[str]								=		2
         __A					:					Union[str, Any]								=		4
         __A					:					Dict								=		37
         __A					:					Any								=		"""gelu"""
         __A					:					Tuple								=		0.1
         __A					:					str								=		0.1
         __A					:					str								=		512
         __A					:					Optional[Any]								=		16
         __A					:					Optional[int]								=		2
         __A					:					Any								=		0.02
         __A					:					str								=		3
         __A					:					Dict								=		4
         __A					:					int								=		None
         __A					:					str								=		self.vocab_size - 1
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					List[str]								=		ids_tensor([self.batch_size, self.seq_length]					,       self.vocab_size	)

         __A					:					List[str]								=		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					:					List[str]								=		ids_tensor([self.batch_size, self.seq_length]					,       self.type_vocab_size	)

         __A					:					Union[str, Any]								=		None
         if self.use_mc_token_ids:
              __A					:					Optional[Any]								=		ids_tensor([self.batch_size, self.num_choices]					,       self.seq_length	)

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

         __A					:					Optional[int]								=		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					:					str								=		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 						_a							(  self					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       *__lowerCamelCase	):




         '''simple docstring'''



         __A					:					str								=		TFOpenAIGPTModel(config=a_	)
         __A					:					Optional[Any]								=		{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
         __A					:					Any								=		model(a_	)

         __A					:					Dict								=		[input_ids, input_mask]
         __A					:					Optional[Any]								=		model(a_	)

         __A					:					Tuple								=		model(a_	)

         self.parent.assertEqual(result.last_hidden_state.shape					,       (self.batch_size, self.seq_length, self.hidden_size)	)
    def 						_a							(  self					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       *__lowerCamelCase	):




         '''simple docstring'''



         __A					:					int								=		TFOpenAIGPTLMHeadModel(config=a_	)
         __A					:					Any								=		{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
         __A					:					Union[str, Any]								=		model(a_	)
         self.parent.assertEqual(result.logits.shape					,       (self.batch_size, self.seq_length, self.vocab_size)	)
    def 						_a							(  self					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       *__lowerCamelCase	):




         '''simple docstring'''



         __A					:					Any								=		TFOpenAIGPTDoubleHeadsModel(config=a_	)

         __A					:					Dict								=		tf.tile(tf.expand_dims(a_					,       1	)					,       (1, self.num_choices, 1)	)
         __A					:					int								=		tf.tile(tf.expand_dims(a_					,       1	)					,       (1, self.num_choices, 1)	)
         __A					:					Optional[int]								=		tf.tile(tf.expand_dims(a_					,       1	)					,       (1, self.num_choices, 1)	)

         __A					:					Dict								=		{
             """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					:					Dict								=		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 						_a							(  self					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       __lowerCamelCase					,       *__lowerCamelCase	):




         '''simple docstring'''



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

    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Any								=		self.prepare_config_and_inputs()

         (
             __A
         )					:					Any								=		config_and_inputs

         __A					:					List[str]								=		{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
         return config, inputs_dict







@require_tf
class 							__snake_case(					_lowerCamelCase				,	_lowerCamelCase				,	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 						_a							(  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 						_a							(  self	):




         '''simple docstring'''



         __A					:					Any								=		TFOpenAIGPTModelTester(self	)
         __A					:					int								=		ConfigTester(self					,       config_class=a_					,       n_embd=37	)
    def 						_a							(  self	):




         '''simple docstring'''



         self.config_tester.run_common_tests()
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					List[Any]								=		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_openai_gpt_model(*a_	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					List[str]								=		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_openai_gpt_lm_head(*a_	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					int								=		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_openai_gpt_double_head(*a_	)
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					Dict								=		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*a_	)

    @slow
    def 						_a							(  self	):




         '''simple docstring'''



         for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              __A					:					Tuple								=		TFOpenAIGPTModel.from_pretrained(a_	)
              self.assertIsNotNone(a_	)







@require_tf
class 							__snake_case(					unittest.TestCase	):


    '''simple docstring'''





    @slow
    def 						_a							(  self	):




         '''simple docstring'''



         __A					:					List[str]								=		TFOpenAIGPTLMHeadModel.from_pretrained('openai-gpt'	)
         __A					:					Dict								=		tf.convert_to_tensor([[481, 4735, 544]]					,       dtype=tf.intaa	)  # the president is
         __A					:					Any								=		[
             481,
             4735,
             544,
             246,
             963,
             870,
             762,
             239,
             244,
             40477,
             244,
             249,
             719,
             881,
             487,
             544,
             240,
             244,
             603,
             481,
         ]  # the president is a very good man. " \n " i\'m sure he is, " said the

         __A					:					List[Any]								=		model.generate(a_					,       do_sample=a_	)
         self.assertListEqual(output_ids[0].numpy().tolist()					,       a_	)








'''simple docstring'''






def        snake_case_   (	lowerCAmelCase_			,  lowerCAmelCase_						)->						float:





       '''simple docstring'''


       return a + b


if __name__ == "__main__":
   A_				:					Tuple							=      5
   A_				:					Tuple							=      6
   print(f"""The sum of {a} + {b} is {add(a, b)}""")



