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				:
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		def __init__(    self  ,					_snake_case  ,					)				->    int:
  				_UpperCamelCase       : Any    =      parent
  				_UpperCamelCase       : Dict    =      13
  				_UpperCamelCase       : Union[str, Any]    =      7
  				_UpperCamelCase       : str    =      True
  				_UpperCamelCase       : int    =      True
  				_UpperCamelCase       : Tuple    =      True
  				_UpperCamelCase       : Optional[Any]    =      True
  				_UpperCamelCase       : Any    =      True
  				_UpperCamelCase       : Any    =      99
  				_UpperCamelCase       : Tuple    =      32
  				_UpperCamelCase       : List[Any]    =      2
  				_UpperCamelCase       : int    =      4
  				_UpperCamelCase       : Dict    =      37
  				_UpperCamelCase       : Optional[Any]    =      '''gelu'''
  				_UpperCamelCase       : str    =      0.1
  				_UpperCamelCase       : List[str]    =      0.1
  				_UpperCamelCase       : Optional[Any]    =      512
  				_UpperCamelCase       : Tuple    =      16
  				_UpperCamelCase       : List[str]    =      2
  				_UpperCamelCase       : Dict    =      0.02
  				_UpperCamelCase       : List[str]    =      3
  				_UpperCamelCase       : Optional[Any]    =      4
  				_UpperCamelCase       : int    =      None
  				_UpperCamelCase       : List[Any]    =      self.vocab_size - 1
  		def _lowercase  (    self     )				->    Any:
  				_UpperCamelCase       : Tuple    =      ids_tensor([self.batch_size, self.seq_length]  ,					self.vocab_size     )
  
  				_UpperCamelCase       : Tuple    =      None
  				if self.use_input_mask:
  						_UpperCamelCase       : Any    =      random_attention_mask([self.batch_size, self.seq_length]     )
  
  				_UpperCamelCase       : Any    =      None
  				if self.use_token_type_ids:
  						_UpperCamelCase       : List[str]    =      ids_tensor([self.batch_size, self.seq_length]  ,					self.type_vocab_size     )
  
  				_UpperCamelCase       : Any    =      None
  				if self.use_mc_token_ids:
  						_UpperCamelCase       : List[Any]    =      ids_tensor([self.batch_size, self.num_choices]  ,					self.seq_length     )
  
  				_UpperCamelCase       : List[Any]    =      None
  				_UpperCamelCase       : Union[str, Any]    =      None
  				_UpperCamelCase       : Tuple    =      None
  				if self.use_labels:
  						_UpperCamelCase       : Optional[int]    =      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       : str    =      ids_tensor([self.batch_size]  ,					self.num_choices     )
  
  				_UpperCamelCase       : 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  ,					)
  
  				_UpperCamelCase       : 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 _lowercase  (    self  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					*_snake_case     )				->    List[str]:
  				_UpperCamelCase       : List[Any]    =      TFOpenAIGPTModel(config=_snake_case     )
  				_UpperCamelCase       : Union[str, Any]    =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
  				_UpperCamelCase       : List[str]    =      model(_snake_case     )
  
  				_UpperCamelCase       : List[str]    =      [input_ids, input_mask]
  				_UpperCamelCase       : Dict    =      model(_snake_case     )
  
  				_UpperCamelCase       : Optional[Any]    =      model(_snake_case     )
  
  				self.parent.assertEqual(result.last_hidden_state.shape  ,					(self.batch_size, self.seq_length, self.hidden_size)     )
  		def _lowercase  (    self  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					*_snake_case     )				->    Any:
  				_UpperCamelCase       : Optional[int]    =      TFOpenAIGPTLMHeadModel(config=_snake_case     )
  				_UpperCamelCase       : Tuple    =      {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
  				_UpperCamelCase       : Union[str, Any]    =      model(_snake_case     )
  				self.parent.assertEqual(result.logits.shape  ,					(self.batch_size, self.seq_length, self.vocab_size)     )
  		def _lowercase  (    self  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					*_snake_case     )				->    Optional[int]:
  				_UpperCamelCase       : List[Any]    =      TFOpenAIGPTDoubleHeadsModel(config=_snake_case     )
  
  				_UpperCamelCase       : List[Any]    =      tf.tile(tf.expand_dims(_snake_case  ,					1     )  ,					(1, self.num_choices, 1)     )
  				_UpperCamelCase       : str    =      tf.tile(tf.expand_dims(_snake_case  ,					1     )  ,					(1, self.num_choices, 1)     )
  				_UpperCamelCase       : int    =      tf.tile(tf.expand_dims(_snake_case  ,					1     )  ,					(1, self.num_choices, 1)     )
  
  				_UpperCamelCase       : List[str]    =      {
  				    '''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(_snake_case     )
  				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  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					*_snake_case     )				->    str:
  				_UpperCamelCase       : List[str]    =      self.num_labels
  				_UpperCamelCase       : Dict    =      ids_tensor([self.batch_size]  ,					self.type_sequence_label_size     )
  				_UpperCamelCase       : str    =      {
  				    '''input_ids''': input_ids,
  				    '''attention_mask''': input_mask,
  				    '''token_type_ids''': token_type_ids,
  				    '''labels''': sequence_labels,
  				}
  				_UpperCamelCase       : Dict    =      TFOpenAIGPTForSequenceClassification(_snake_case     )
  				_UpperCamelCase       : str    =      model(_snake_case     )
  				self.parent.assertEqual(result.logits.shape  ,					(self.batch_size, self.num_labels)     )
  
  
  
  
  		def _lowercase  (    self     )				->    Optional[int]:
  				_UpperCamelCase       : Tuple    =      self.prepare_config_and_inputs()
  
  				(
  				    _UpperCamelCase							
  				)       : List[str]    =      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 			UpperCAmelCase				(					a_  ,		a_  ,		unittest.TestCase ):
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		A__  :   Union[str, Any]          =    (
  		    (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
  		    if is_tf_available()
  		    else ()
  		)
  		A__  :   Tuple          =    (
  		    (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
  		)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
  		A__  :   Tuple          =    (
  		    {
  		        'feature-extraction': TFOpenAIGPTModel,
  		        'text-classification': TFOpenAIGPTForSequenceClassification,
  		        'text-generation': TFOpenAIGPTLMHeadModel,
  		        'zero-shot': TFOpenAIGPTForSequenceClassification,
  		    }
  		    if is_tf_available()
  		    else {}
  		)
  		A__  :   Optional[Any]          =    False
  		A__  :   Optional[Any]          =    False
  		def _lowercase  (    self  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case  ,					_snake_case     )				->    Optional[int]:
  				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     )				->    Optional[Any]:
  				_UpperCamelCase       : Dict    =      TFOpenAIGPTModelTester(self     )
  				_UpperCamelCase       : Optional[int]    =      ConfigTester(self  ,					config_class=_snake_case  ,					n_embd=37     )
  		def _lowercase  (    self     )				->    int:
  				self.config_tester.run_common_tests()
  		def _lowercase  (    self     )				->    List[str]:
  				_UpperCamelCase       : int    =      self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_openai_gpt_model(*_snake_case     )
  		def _lowercase  (    self     )				->    List[Any]:
  				_UpperCamelCase       : Optional[int]    =      self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_openai_gpt_lm_head(*_snake_case     )
  		def _lowercase  (    self     )				->    int:
  				_UpperCamelCase       : Dict    =      self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_openai_gpt_double_head(*_snake_case     )
  		def _lowercase  (    self     )				->    Optional[int]:
  				_UpperCamelCase       : Optional[int]    =      self.model_tester.prepare_config_and_inputs()
  				self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*_snake_case     )
  
  
  
  
  		@slow
  		def _lowercase  (    self     )				->    int:
  				for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
  						_UpperCamelCase       : int    =      TFOpenAIGPTModel.from_pretrained(_snake_case     )
  						self.assertIsNotNone(_snake_case     )
  
  
  
  
  
  
  
  @require_tf
  class 			UpperCAmelCase				(					unittest.TestCase ):
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		@slow
  		def _lowercase  (    self     )				->    List[Any]:
  				_UpperCamelCase       : Union[str, Any]    =      TFOpenAIGPTLMHeadModel.from_pretrained('''openai-gpt'''     )
  				_UpperCamelCase       : Optional[Any]    =      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,
  				    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
  
  				_UpperCamelCase       : Union[str, Any]    =      model.generate(_snake_case  ,					do_sample=_snake_case     )
  				self.assertListEqual(output_ids[0].numpy().tolist()  ,					_snake_case     )
  
  
  
  
  
  
style_context: 
  '''simple docstring'''
  
  from __future__ import annotations
  
  from collections.abc import Iterable
  from dataclasses import dataclass
  from typing import Any
  
  class 			UpperCAmelCase				:
  
  
  
  
  
  		"""simple docstring"""
  
  
  
  
  
  		A__  :   List[str]          =    ('_front', '_back', '_len')
  
  		@dataclass
  		class 			UpperCAmelCase				:
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  				A__  :   Any          =    None
  				A__  :   Deque._Node | None          =    None
  				A__  :   Deque._Node | None          =    None
  
  
  
  
  
  
  
  		class 			UpperCAmelCase				:
  
  
  
  
  
  				"""simple docstring"""
  
  
  
  
  
  				A__  :   Any          =    ('_cur',)
  				def __init__(    self  ,					_snake_case     )				->    None:
  						_UpperCamelCase       : Any    =      cur
  				def __iter__(    self     )				->    Deque._Iterator:
  						return self
  
  
  
  
  				def _lowercase  (    self     )				->    Any:
  						if self._cur is None:
  								# finished iterating
  								raise StopIteration
  						_UpperCamelCase       : List[Any]    =      self._cur.val
  						_UpperCamelCase       : List[Any]    =      self._cur.next_node
  
  						return val
  
  
  
  
  
  
  
  		def __init__(    self  ,					_snake_case = None     )				->    None:
  				_UpperCamelCase       : Any    =      None
  				_UpperCamelCase       : Any    =      None
  				_UpperCamelCase       : int    =      0
  
  				if iterable is not None:
  						# append every value to the deque
  						for val in iterable:
  								self.append(_snake_case     )
  		def _lowercase  (    self  ,					_snake_case     )				->    None:
  				_UpperCamelCase       : List[str]    =      self._Node(_snake_case  ,					_snake_case  ,					_snake_case     )
  				if self.is_empty():
  						# front = back
  						_UpperCamelCase       : Union[str, Any]    =      node
  						_UpperCamelCase       : Tuple    =      1
  				else:
  						# connect nodes
  						_UpperCamelCase       : Union[str, Any]    =      node
  						_UpperCamelCase       : int    =      self._back
  						_UpperCamelCase       : List[Any]    =      node  # assign new back to the new node
  
  						self._len += 1
  
  						# make sure there were no errors
  						assert not self.is_empty(), "Error on appending value."
  		def _lowercase  (    self  ,					_snake_case     )				->    None:
  				_UpperCamelCase       : Optional[Any]    =      self._Node(_snake_case  ,					_snake_case  ,					_snake_case     )
  				if self.is_empty():
  						# front = back
  						_UpperCamelCase       : Union[str, Any]    =      node
  						_UpperCamelCase       : Optional[int]    =      1
  				else:
  						# connect nodes
  						_UpperCamelCase       : Tuple    =      self._front
  						_UpperCamelCase       : Optional[int]    =      node
  						_UpperCamelCase       : List[str]    =      node  # assign new front to the new node
  
  						self._len += 1
  
  						# make sure there were no errors
  						assert not self.is_empty(), "Error on appending value."
  		def _lowercase  (    self  ,					_snake_case     )				->    None:
  				for val in iterable:
  						self.append(_snake_case     )
  		def _lowercase  (    self  ,					_snake_case     )				->    None:
  				for val in iterable:
  						self.appendleft(_snake_case     )
  		def _lowercase  (    self     )				->    Any:
  				assert not self.is_empty(), "Deque is empty."
  
  				_UpperCamelCase       : int    =      self._back
  				_UpperCamelCase       : List[Any]    =      self._back.prev_node  # set new back
  				# drop the last node - python will deallocate memory automatically
  				_UpperCamelCase       : Union[str, Any]    =      None
  
  				self._len -= 1
  
  				return topop.val
  		def _lowercase  (    self     )				->    Any:
  				assert not self.is_empty(), "Deque is empty."
  
  				_UpperCamelCase       : List[Any]    =      self._front
  				_UpperCamelCase       : str    =      self._front.next_node  # set new front and drop the first node
  				_UpperCamelCase       : Union[str, Any]    =      None
  
  				self._len -= 1
  
  				return topop.val
  		def _lowercase  (    self     )				->    bool:
  				return self._front is None
  		def __len__(    self     )				->    int:
  				return self._len
  		def __eq__(    self  ,					_snake_case     )				->    bool:
  
  				if not isinstance(_snake_case  ,					_snake_case     ):
  						return NotImplemented
  
  				_UpperCamelCase       : Optional[int]    =      self._front
  				_UpperCamelCase       : List[Any]    =      other._front
  
  				# if the length of the dequeues are not the same, they are not equal
  				if len(self     ) != len(_snake_case     ):
  						return False
  
  				while me is not None and oth is not None:
  						# compare every value
  						if me.val != oth.val:
  								return False
  						_UpperCamelCase       : str    =      me.next_node
  						_UpperCamelCase       : List[str]    =      oth.next_node
  
  				return True
  		def __iter__(    self     )				->    Deque._Iterator:
  				return Deque._Iterator(self._front     )
  
  
  
  
  		def __repr__(    self     )				->    str:
  				_UpperCamelCase       : str    =      []
  				_UpperCamelCase       : Tuple    =      self._front
  				while aux is not None:
  						# append the values in a list to display
  						values_list.append(aux.val     )
  						_UpperCamelCase       : List[str]    =      aux.next_node
  
  				return F'''[{', '.join(repr(_snake_case     ) for val in values_list     )}]'''
  
  
  if __name__ == "__main__":
  	import doctest
  
  	doctest.testmod()
  
  
  
  
  
  