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 A_			:
  
  
  
  
    '''simple docstring'''
  
  
  
  
  
  
  
    def __init__(	self       ,     lowercase_       ,     ):
  
       """simple docstring"""
       UpperCAmelCase_      :      List[Any]      =					parent
       UpperCAmelCase_      :      Dict      =					13
       UpperCAmelCase_      :      Dict      =					7
       UpperCAmelCase_      :      Dict      =					True
       UpperCAmelCase_      :      List[Any]      =					True
       UpperCAmelCase_      :      str      =					True
       UpperCAmelCase_      :      Union[str, Any]      =					True
       UpperCAmelCase_      :      Optional[Any]      =					True
       UpperCAmelCase_      :      Union[str, Any]      =					99
       UpperCAmelCase_      :      Any      =					32
       UpperCAmelCase_      :      Union[str, Any]      =					2
       UpperCAmelCase_      :      Union[str, Any]      =					4
       UpperCAmelCase_      :      str      =					37
       UpperCAmelCase_      :      int      =					"""gelu"""
       UpperCAmelCase_      :      Optional[Any]      =					0.1
       UpperCAmelCase_      :      List[Any]      =					0.1
       UpperCAmelCase_      :      List[str]      =					512
       UpperCAmelCase_      :      Optional[Any]      =					16
       UpperCAmelCase_      :      str      =					2
       UpperCAmelCase_      :      List[str]      =					0.02
       UpperCAmelCase_      :      Any      =					3
       UpperCAmelCase_      :      str      =					4
       UpperCAmelCase_      :      Any      =					None
       UpperCAmelCase_      :      Any      =					self.vocab_size - 1
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      List[str]      =					ids_tensor([self.batch_size, self.seq_length]       ,     self.vocab_size						)
  
       UpperCAmelCase_      :      Tuple      =					None
       if self.use_input_mask:
          UpperCAmelCase_      :      List[str]      =					random_attention_mask([self.batch_size, self.seq_length]						)
  
       UpperCAmelCase_      :      Optional[int]      =					None
       if self.use_token_type_ids:
          UpperCAmelCase_      :      int      =					ids_tensor([self.batch_size, self.seq_length]       ,     self.type_vocab_size						)
  
       UpperCAmelCase_      :      int      =					None
       if self.use_mc_token_ids:
          UpperCAmelCase_      :      int      =					ids_tensor([self.batch_size, self.num_choices]       ,     self.seq_length						)
  
       UpperCAmelCase_      :      str      =					None
       UpperCAmelCase_      :      Dict      =					None
       UpperCAmelCase_      :      Optional[Any]      =					None
       if self.use_labels:
          UpperCAmelCase_      :      Union[str, Any]      =					ids_tensor([self.batch_size]       ,     self.type_sequence_label_size						)
          UpperCAmelCase_      :      Dict      =					ids_tensor([self.batch_size, self.seq_length]       ,     self.num_labels						)
          UpperCAmelCase_      :      str      =					ids_tensor([self.batch_size]       ,     self.num_choices						)
  
       UpperCAmelCase_      :      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_      :      Tuple      =					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       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     *lowercase_						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Any      =					TFOpenAIGPTModel(config=_lowerCamelCase						)
       UpperCAmelCase_      :      Any      =					{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
       UpperCAmelCase_      :      Optional[int]      =					model(_lowerCamelCase						)
  
       UpperCAmelCase_      :      List[str]      =					[input_ids, input_mask]
       UpperCAmelCase_      :      Dict      =					model(_lowerCamelCase						)
  
       UpperCAmelCase_      :      List[str]      =					model(_lowerCamelCase						)
  
       self.parent.assertEqual(result.last_hidden_state.shape       ,     (self.batch_size, self.seq_length, self.hidden_size)						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     *lowercase_						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Union[str, Any]      =					TFOpenAIGPTLMHeadModel(config=_lowerCamelCase						)
       UpperCAmelCase_      :      Tuple      =					{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
       UpperCAmelCase_      :      str      =					model(_lowerCamelCase						)
       self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.seq_length, self.vocab_size)						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     *lowercase_						):
  
       """simple docstring"""
       UpperCAmelCase_      :      int      =					TFOpenAIGPTDoubleHeadsModel(config=_lowerCamelCase						)
  
       UpperCAmelCase_      :      Optional[Any]      =					tf.tile(tf.expand_dims(_lowerCamelCase       ,     1						)       ,     (1, self.num_choices, 1)						)
       UpperCAmelCase_      :      Any      =					tf.tile(tf.expand_dims(_lowerCamelCase       ,     1						)       ,     (1, self.num_choices, 1)						)
       UpperCAmelCase_      :      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_      :      int      =					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  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     *lowercase_						):
  
       """simple docstring"""
       UpperCAmelCase_      :      List[Any]      =					self.num_labels
       UpperCAmelCase_      :      int      =					ids_tensor([self.batch_size]       ,     self.type_sequence_label_size						)
       UpperCAmelCase_      :      Any      =					{
           """input_ids""": input_ids,
           """attention_mask""": input_mask,
           """token_type_ids""": token_type_ids,
           """labels""": sequence_labels,
       }
       UpperCAmelCase_      :      Tuple      =					TFOpenAIGPTForSequenceClassification(_lowerCamelCase						)
       UpperCAmelCase_      :      Union[str, Any]      =					model(_lowerCamelCase						)
       self.parent.assertEqual(result.logits.shape       ,     (self.batch_size, self.num_labels)						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      int      =					self.prepare_config_and_inputs()
  
       (
           UpperCAmelCase_		
       )      :      Optional[Any]      =					config_and_inputs
  
       UpperCAmelCase_      :      Tuple      =					{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
       return config, inputs_dict
  
  
  
  
  @require_tf
  class A_			(lowerCAmelCase__       ,lowerCAmelCase__       ,unittest.TestCase   ):
  
  
  
  
    '''simple docstring'''
    SCREAMING_SNAKE_CASE__    :		Optional[int]						  =	(
        (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
        if is_tf_available()
        else ()
    )
    SCREAMING_SNAKE_CASE__    :		int						  =	(
        (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
    )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
    SCREAMING_SNAKE_CASE__    :		Any						  =	(
        {
            """feature-extraction""": TFOpenAIGPTModel,
            """text-classification""": TFOpenAIGPTForSequenceClassification,
            """text-generation""": TFOpenAIGPTLMHeadModel,
            """zero-shot""": TFOpenAIGPTForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )
    SCREAMING_SNAKE_CASE__    :		str						  =	False
    SCREAMING_SNAKE_CASE__    :		Optional[Any]						  =	False
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_       ,     lowercase_						):
  
       """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"""
       UpperCAmelCase_      :      List[str]      =					TFOpenAIGPTModelTester(self						)
       UpperCAmelCase_      :      Optional[int]      =					ConfigTester(self       ,     config_class=_lowerCamelCase       ,     n_embd=37						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       self.config_tester.run_common_tests()
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Tuple      =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_openai_gpt_model(*_lowerCamelCase						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Union[str, Any]      =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_openai_gpt_lm_head(*_lowerCamelCase						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Dict      =					self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_openai_gpt_double_head(*_lowerCamelCase						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	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  UpperCamelCase__      (	self						):
  
       """simple docstring"""
  
       for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          UpperCAmelCase_      :      int      =					TFOpenAIGPTModel.from_pretrained(_lowerCamelCase						)
          self.assertIsNotNone(_lowerCamelCase						)
  
  
  
  
  @require_tf
  class A_			(unittest.TestCase   ):
  
  
  
  
    '''simple docstring'''
  
  
  
  
  
  
  
    @slow
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      int      =					TFOpenAIGPTLMHeadModel.from_pretrained("openai-gpt"						)
       UpperCAmelCase_      :      Optional[int]      =					tf.convert_to_tensor([[481, 4735, 544]]       ,     dtype=tf.intaa						)  # the president is
       UpperCAmelCase_      :      Union[str, Any]      =					[
           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
  
       UpperCAmelCase_      :      Any      =					model.generate(_lowerCamelCase       ,     do_sample=_lowerCamelCase						)
       self.assertListEqual(output_ids[0].numpy().tolist()       ,     _lowerCamelCase						)
  
style_context: 
  """simple docstring"""
  
  
  
  
  
  import shutil
  import tempfile
  import unittest
  
  import numpy as np
  import pytest
  
  from transformers.testing_utils import require_vision
  from transformers.utils import is_vision_available
  
  
  if is_vision_available():
      from PIL import Image
  
      from transformers import AutoProcessor, BertTokenizer, CLIPImageProcessor, GitProcessor, PreTrainedTokenizerFast
  
  
  @require_vision
  class A_			(unittest.TestCase   ):
  
  
  
  
    '''simple docstring'''
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Optional[int]      =					tempfile.mkdtemp()
  
       UpperCAmelCase_      :      List[Any]      =					CLIPImageProcessor()
       UpperCAmelCase_      :      Any      =					BertTokenizer.from_pretrained(
           "hf-internal-testing/tiny-random-BertModel"       ,     model_input_names=["input_ids", "attention_mask"]						)
  
       UpperCAmelCase_      :      Tuple      =					GitProcessor(lowercase_       ,     lowercase_						)
  
       processor.save_pretrained(self.tmpdirname						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     **lowercase_						):
  
       """simple docstring"""
       return AutoProcessor.from_pretrained(self.tmpdirname       ,     **lowercase_						).tokenizer
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self       ,     **lowercase_						):
  
       """simple docstring"""
       return AutoProcessor.from_pretrained(self.tmpdirname       ,     **lowercase_						).image_processor
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       shutil.rmtree(self.tmpdirname						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Optional[int]      =					[np.random.randint(255       ,     size=(3, 30, 400)       ,     dtype=np.uinta						)]
  
       UpperCAmelCase_      :      Optional[Any]      =					[Image.fromarray(np.moveaxis(lowercase_       ,     0       ,     -1						)						) for x in image_inputs]
  
       return image_inputs
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      List[Any]      =					GitProcessor(tokenizer=self.get_tokenizer()       ,     image_processor=self.get_image_processor()						)
       processor.save_pretrained(self.tmpdirname						)
  
       UpperCAmelCase_      :      Optional[int]      =					self.get_tokenizer(bos_token="(BOS)"       ,     eos_token="(EOS)"						)
       UpperCAmelCase_      :      Union[str, Any]      =					self.get_image_processor(do_normalize=lowercase_       ,     padding_value=1.0						)
  
       UpperCAmelCase_      :      str      =					GitProcessor.from_pretrained(
           self.tmpdirname       ,     bos_token="(BOS)"       ,     eos_token="(EOS)"       ,     do_normalize=lowercase_       ,     padding_value=1.0						)
  
       self.assertEqual(processor.tokenizer.get_vocab()       ,     tokenizer_add_kwargs.get_vocab()						)
       self.assertIsInstance(processor.tokenizer       ,     lowercase_						)
  
       self.assertEqual(processor.image_processor.to_json_string()       ,     image_processor_add_kwargs.to_json_string()						)
       self.assertIsInstance(processor.image_processor       ,     lowercase_						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Dict      =					self.get_image_processor()
       UpperCAmelCase_      :      Union[str, Any]      =					self.get_tokenizer()
  
       UpperCAmelCase_      :      Union[str, Any]      =					GitProcessor(tokenizer=lowercase_       ,     image_processor=lowercase_						)
  
       UpperCAmelCase_      :      List[Any]      =					self.prepare_image_inputs()
  
       UpperCAmelCase_      :      Optional[Any]      =					image_processor(lowercase_       ,     return_tensors="np"						)
       UpperCAmelCase_      :      int      =					processor(images=lowercase_       ,     return_tensors="np"						)
  
       for key in input_feat_extract.keys():
          self.assertAlmostEqual(input_feat_extract[key].sum()       ,     input_processor[key].sum()       ,     delta=1E-2						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Union[str, Any]      =					self.get_image_processor()
       UpperCAmelCase_      :      Tuple      =					self.get_tokenizer()
  
       UpperCAmelCase_      :      int      =					GitProcessor(tokenizer=lowercase_       ,     image_processor=lowercase_						)
  
       UpperCAmelCase_      :      Optional[Any]      =					"lower newer"
  
       UpperCAmelCase_      :      Any      =					processor(text=lowercase_						)
  
       UpperCAmelCase_      :      int      =					tokenizer(lowercase_       ,     return_token_type_ids=lowercase_						)
  
       for key in encoded_tok.keys():
          self.assertListEqual(encoded_tok[key]       ,     encoded_processor[key]						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Optional[int]      =					self.get_image_processor()
       UpperCAmelCase_      :      Union[str, Any]      =					self.get_tokenizer()
  
       UpperCAmelCase_      :      Optional[int]      =					GitProcessor(tokenizer=lowercase_       ,     image_processor=lowercase_						)
  
       UpperCAmelCase_      :      List[str]      =					"lower newer"
       UpperCAmelCase_      :      Dict      =					self.prepare_image_inputs()
  
       UpperCAmelCase_      :      Any      =					processor(text=lowercase_       ,     images=lowercase_						)
  
       self.assertListEqual(list(inputs.keys()						)       ,     ["input_ids", "attention_mask", "pixel_values"]						)
  
       # test if it raises when no input is passed
       with pytest.raises(lowercase_						):
          processor()
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Optional[Any]      =					self.get_image_processor()
       UpperCAmelCase_      :      str      =					self.get_tokenizer()
  
       UpperCAmelCase_      :      int      =					GitProcessor(tokenizer=lowercase_       ,     image_processor=lowercase_						)
  
       UpperCAmelCase_      :      Tuple      =					[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]
  
       UpperCAmelCase_      :      Any      =					processor.batch_decode(lowercase_						)
       UpperCAmelCase_      :      Optional[Any]      =					tokenizer.batch_decode(lowercase_						)
  
       self.assertListEqual(lowercase_       ,     lowercase_						)
  
  
  
  
  
  
  
    def  UpperCamelCase__      (	self						):
  
       """simple docstring"""
       UpperCAmelCase_      :      Union[str, Any]      =					self.get_image_processor()
       UpperCAmelCase_      :      Optional[Any]      =					self.get_tokenizer()
  
       UpperCAmelCase_      :      str      =					GitProcessor(tokenizer=lowercase_       ,     image_processor=lowercase_						)
  
       UpperCAmelCase_      :      int      =					"lower newer"
       UpperCAmelCase_      :      Tuple      =					self.prepare_image_inputs()
  
       UpperCAmelCase_      :      Optional[Any]      =					processor(text=lowercase_       ,     images=lowercase_						)
  
       # For now the processor supports only ['input_ids', 'attention_mask', 'pixel_values']
       self.assertListEqual(list(inputs.keys()						)       ,     ["input_ids", "attention_mask", "pixel_values"]						)
  
  
  