code: 
  
  
  '''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 							__UpperCamelCase       :
  
  
  
  
  	def __init__(     self		,       __a		,       ):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[Any]      					=						parent
  						__a    : List[Any]      					=						13
  						__a    : Any      					=						7
  						__a    : Any      					=						True
  						__a    : List[Any]      					=						True
  						__a    : int      					=						True
  						__a    : Optional[int]      					=						True
  						__a    : Optional[int]      					=						True
  						__a    : List[str]      					=						99
  						__a    : str      					=						32
  						__a    : Optional[int]      					=						2
  						__a    : Union[str, Any]      					=						4
  						__a    : Any      					=						37
  						__a    : Optional[Any]      					=						'gelu'
  						__a    : List[str]      					=						0.1
  						__a    : Any      					=						0.1
  						__a    : List[Any]      					=						512
  						__a    : List[str]      					=						16
  						__a    : Tuple      					=						2
  						__a    : Optional[int]      					=						0.02
  						__a    : str      					=						3
  						__a    : Dict      					=						4
  						__a    : Optional[Any]      					=						None
  						__a    : int      					=						self.vocab_size - 1
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Tuple      					=						ids_tensor([self.batch_size, self.seq_length]		,       self.vocab_size							)
  
  						__a    : str      					=						None
  						if self.use_input_mask:
  											__a    : Tuple      					=						random_attention_mask([self.batch_size, self.seq_length]							)
  
  						__a    : str      					=						None
  						if self.use_token_type_ids:
  											__a    : Tuple      					=						ids_tensor([self.batch_size, self.seq_length]		,       self.type_vocab_size							)
  
  						__a    : str      					=						None
  						if self.use_mc_token_ids:
  											__a    : Optional[Any]      					=						ids_tensor([self.batch_size, self.num_choices]		,       self.seq_length							)
  
  						__a    : List[str]      					=						None
  						__a    : Optional[int]      					=						None
  						__a    : List[str]      					=						None
  						if self.use_labels:
  											__a    : str      					=						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    : Dict      					=						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    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a		,       __a		,       *__a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[Any]      					=						TFOpenAIGPTModel(config=__a							)
  						__a    : Dict      					=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
  						__a    : int      					=						model(__a							)
  
  						__a    : int      					=						[input_ids, input_mask]
  						__a    : List[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    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a		,       __a		,       *__a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Dict      					=						TFOpenAIGPTLMHeadModel(config=__a							)
  						__a    : Tuple      					=						{'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    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a		,       __a		,       __a		,       *__a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[Any]      					=						TFOpenAIGPTDoubleHeadsModel(config=__a							)
  
  						__a    : List[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    : Union[str, Any]      					=						tf.tile(tf.expand_dims(__a		,       1							)		,       (1, self.num_choices, 1)							)
  
  						__a    : Union[str, 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,
  						}
  						__a    : int      					=						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    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a		,       __a		,       *__a							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Tuple      					=						self.num_labels
  						__a    : int      					=						ids_tensor([self.batch_size]		,       self.type_sequence_label_size							)
  						__a    : List[Any]      					=						{
  						    'input_ids': input_ids,
  						    'attention_mask': input_mask,
  						    'token_type_ids': token_type_ids,
  						    'labels': sequence_labels,
  						}
  						__a    : Optional[int]      					=						TFOpenAIGPTForSequenceClassification(__a							)
  						__a    : List[str]      					=						model(__a							)
  						self.parent.assertEqual(result.logits.shape		,       (self.batch_size, self.num_labels)							)
  
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[str]      					=						self.prepare_config_and_inputs()
  
  						(
  						    (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       (
  						    __a
  						)					,       
  						)    : Optional[int]      					=						config_and_inputs
  
  						__a    : Union[str, Any]      					=						{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
  						return config, inputs_dict
  
  
  
  
  
  @require_tf
  class 							__UpperCamelCase       (	lowerCAmelCase_	,   lowerCAmelCase_	,   unittest.TestCase      ):
  	A_			    =					(
  	    (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
  	    if is_tf_available()
  	    else ()
  	)
  	A_			    =					(
  	    (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
  	)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
  	A_			    =					(
  	    {
  	        "feature-extraction": TFOpenAIGPTModel,
  	        "text-classification": TFOpenAIGPTForSequenceClassification,
  	        "text-generation": TFOpenAIGPTLMHeadModel,
  	        "zero-shot": TFOpenAIGPTForSequenceClassification,
  	    }
  	    if is_tf_available()
  	    else {}
  	)
  	A_			    =					False
  	A_			    =					False
  
  
  
  
  	def    __UpperCAmelCase							(     self		,       __a		,       __a		,       __a		,       __a		,       __a							):
  
  						'''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    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[Any]      					=						TFOpenAIGPTModelTester(self							)
  						__a    : Optional[Any]      					=						ConfigTester(self		,       config_class=__a		,       n_embd=37							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						self.config_tester.run_common_tests()
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Union[str, Any]      					=						self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_openai_gpt_model(*__a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Tuple      					=						self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_openai_gpt_lm_head(*__a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : List[str]      					=						self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_openai_gpt_double_head(*__a							)
  
  
  
  
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : str      					=						self.model_tester.prepare_config_and_inputs()
  						self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*__a							)
  
  
  
  
  
  	@slow
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  											__a    : List[str]      					=						TFOpenAIGPTModel.from_pretrained(__a							)
  											self.assertIsNotNone(__a							)
  
  
  
  
  
  @require_tf
  class 							__UpperCamelCase       (	unittest.TestCase      ):
  
  
  
  
  	@slow
  	def    __UpperCAmelCase							(     self							):
  
  						'''simple docstring'''
  
  
  
  
  
  						__a    : Optional[int]      					=						TFOpenAIGPTLMHeadModel.from_pretrained('openai-gpt'							)
  						__a    : str      					=						tf.convert_to_tensor([[481, 4735, 544]]		,       dtype=tf.intaa							)  # the president is
  						__a    : Dict      					=						[
  						    481,
  						    4735,
  						    544,
  						    246,
  						    963,
  						    870,
  						    762,
  						    239,
  						    244,
  						    4_0477,
  						    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							)
  
  
  
  
style_context: 
  
  
  '''simple docstring'''
  
  
  
  from typing import TYPE_CHECKING
  
  from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available
  
  
  __lowercase			:		Any =			{'configuration_visual_bert': ['VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'VisualBertConfig']}
  
  try:
  	if not is_torch_available():
  		raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
  	pass
  else:
  	__lowercase			:		Optional[int] =			[
  	    'VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST',
  	    'VisualBertForMultipleChoice',
  	    'VisualBertForPreTraining',
  	    'VisualBertForQuestionAnswering',
  	    'VisualBertForRegionToPhraseAlignment',
  	    'VisualBertForVisualReasoning',
  	    'VisualBertLayer',
  	    'VisualBertModel',
  	    'VisualBertPreTrainedModel',
  	]
  
  
  if TYPE_CHECKING:
  	from .configuration_visual_bert import VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, VisualBertConfig
  
  	try:
  		if not is_torch_available():
  			raise OptionalDependencyNotAvailable()
  	except OptionalDependencyNotAvailable:
  		pass
  	else:
  		from .modeling_visual_bert import (
  		    VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
  		    VisualBertForMultipleChoice,
  		    VisualBertForPreTraining,
  		    VisualBertForQuestionAnswering,
  		    VisualBertForRegionToPhraseAlignment,
  		    VisualBertForVisualReasoning,
  		    VisualBertLayer,
  		    VisualBertModel,
  		    VisualBertPreTrainedModel,
  		)
  
  
  else:
  	import sys
  
  	__lowercase			:		Tuple =			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
  
  
  
  