



import unittest

from transformers import SPIECE_UNDERLINE
from transformers.models.speechta import SpeechTaTokenizer
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow
from transformers.tokenization_utils import AddedToken

from ...test_tokenization_common import TokenizerTesterMixin


a_      :      Any    =     get_tests_dir('fixtures/test_sentencepiece_bpe_char.model')
@require_sentencepiece
@require_tokenizers
class    __UpperCamelCase			(       _lowercase	,	unittest.TestCase				):

 """simple docstring"""



 _lowercase   :    Optional[int]      						=					SpeechTaTokenizer
 _lowercase   :    List[str]      						=					False
 _lowercase   :    List[str]      						=					True

 def 						_UpperCAmelCase       (	self      ) ->			Optional[Any]:
  super().setUp()

  # We have a SentencePiece fixture for testing
  a__												= SpeechTaTokenizer(SCREAMING_SNAKE_CASE      )

  a__												= AddedToken('''<mask>'''		,				lstrip=SCREAMING_SNAKE_CASE		,				rstrip=SCREAMING_SNAKE_CASE      )
  a__												= mask_token
  tokenizer.add_special_tokens({'''mask_token''': mask_token}      )
  tokenizer.add_tokens(['''<ctc_blank>''']      )

  tokenizer.save_pretrained(self.tmpdirname      )

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE      ) ->			Tuple:
  a__												= '''this is a test'''
  a__												= '''this is a test'''
  return input_text, output_text

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE=False		,				SCREAMING_SNAKE_CASE=2_0		,				SCREAMING_SNAKE_CASE=5      ) ->			str:
  a__							,			a__												= self.get_input_output_texts(SCREAMING_SNAKE_CASE      )
  a__												= tokenizer.encode(SCREAMING_SNAKE_CASE		,				add_special_tokens=SCREAMING_SNAKE_CASE      )
  a__												= tokenizer.decode(SCREAMING_SNAKE_CASE		,				clean_up_tokenization_spaces=SCREAMING_SNAKE_CASE      )
  return text, ids

 def 						_UpperCAmelCase       (	self      ) ->			Tuple:
  a__												= '''<pad>'''
  a__												= 1

  self.assertEqual(self.get_tokenizer()._convert_token_to_id(SCREAMING_SNAKE_CASE      )		,				SCREAMING_SNAKE_CASE      )
  self.assertEqual(self.get_tokenizer()._convert_id_to_token(SCREAMING_SNAKE_CASE      )		,				SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self      ) ->			List[str]:
  a__												= list(self.get_tokenizer().get_vocab().keys()      )

  self.assertEqual(vocab_keys[0]		,				'''<s>'''      )
  self.assertEqual(vocab_keys[1]		,				'''<pad>'''      )
  self.assertEqual(vocab_keys[-4]		,				'''œ'''      )
  self.assertEqual(vocab_keys[-2]		,				'''<mask>'''      )
  self.assertEqual(vocab_keys[-1]		,				'''<ctc_blank>'''      )
  self.assertEqual(len(SCREAMING_SNAKE_CASE      )		,				8_1      )

 def 						_UpperCAmelCase       (	self      ) ->			str:
  self.assertEqual(self.get_tokenizer().vocab_size		,				7_9      )

 def 						_UpperCAmelCase       (	self      ) ->			Union[str, Any]:
  a__												= self.get_tokenizers(do_lower_case=SCREAMING_SNAKE_CASE      )
  for tokenizer in tokenizers:
   with self.subTest(f"{tokenizer.__class__.__name__}"      ):
    a__												= tokenizer.vocab_size
    a__												= len(SCREAMING_SNAKE_CASE      )

    self.assertNotEqual(SCREAMING_SNAKE_CASE		,				0      )

    # We usually have added tokens from the start in tests because our vocab fixtures are
    # smaller than the original vocabs - let's not assert this
    # self.assertEqual(vocab_size, all_size)

    a__												= ['''aaaaa bbbbbb''', '''cccccccccdddddddd''']
    a__												= tokenizer.add_tokens(SCREAMING_SNAKE_CASE      )
    a__												= tokenizer.vocab_size
    a__												= len(SCREAMING_SNAKE_CASE      )

    self.assertNotEqual(SCREAMING_SNAKE_CASE		,				0      )
    self.assertEqual(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      )
    self.assertEqual(SCREAMING_SNAKE_CASE		,				len(SCREAMING_SNAKE_CASE      )      )
    self.assertEqual(SCREAMING_SNAKE_CASE		,				all_size + len(SCREAMING_SNAKE_CASE      )      )

    a__												= tokenizer.encode('''aaaaa bbbbbb low cccccccccdddddddd l'''		,				add_special_tokens=SCREAMING_SNAKE_CASE      )

    self.assertGreaterEqual(len(SCREAMING_SNAKE_CASE      )		,				4      )
    self.assertGreater(tokens[0]		,				tokenizer.vocab_size - 1      )
    self.assertGreater(tokens[-3]		,				tokenizer.vocab_size - 1      )

    a__												= {'''eos_token''': '''>>>>|||<||<<|<<''', '''pad_token''': '''<<<<<|||>|>>>>|>'''}
    a__												= tokenizer.add_special_tokens(SCREAMING_SNAKE_CASE      )
    a__												= tokenizer.vocab_size
    a__												= len(SCREAMING_SNAKE_CASE      )

    self.assertNotEqual(SCREAMING_SNAKE_CASE		,				0      )
    self.assertEqual(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      )
    self.assertEqual(SCREAMING_SNAKE_CASE		,				len(SCREAMING_SNAKE_CASE      )      )
    self.assertEqual(SCREAMING_SNAKE_CASE		,				all_size_a + len(SCREAMING_SNAKE_CASE      )      )

    a__												= tokenizer.encode(
        '''>>>>|||<||<<|<< aaaaabbbbbb low cccccccccdddddddd <<<<<|||>|>>>>|> l'''		,				add_special_tokens=SCREAMING_SNAKE_CASE      )

    self.assertGreaterEqual(len(SCREAMING_SNAKE_CASE      )		,				6      )
    self.assertGreater(tokens[0]		,				tokenizer.vocab_size - 1      )
    self.assertGreater(tokens[0]		,				tokens[1]      )
    self.assertGreater(tokens[-3]		,				tokenizer.vocab_size - 1      )
    self.assertGreater(tokens[-3]		,				tokens[-4]      )
    self.assertEqual(tokens[0]		,				tokenizer.eos_token_id      )
    self.assertEqual(tokens[-3]		,				tokenizer.pad_token_id      )

 def 						_UpperCAmelCase       (	self      ) ->			Optional[int]:
  pass

 def 						_UpperCAmelCase       (	self      ) ->			List[Any]:
  pass

 def 						_UpperCAmelCase       (	self      ) ->			Union[str, Any]:
  a__												= self.get_tokenizer()

  a__												= tokenizer.tokenize('''This is a test'''      )
  # fmt: off
  self.assertListEqual(SCREAMING_SNAKE_CASE		,				[SPIECE_UNDERLINE, '''T''', '''h''', '''i''', '''s''', SPIECE_UNDERLINE, '''i''', '''s''', SPIECE_UNDERLINE, '''a''', SPIECE_UNDERLINE, '''t''', '''e''', '''s''', '''t''']      )
  # fmt: on

  self.assertListEqual(
      tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE      )		,				[4, 3_2, 1_1, 1_0, 1_2, 4, 1_0, 1_2, 4, 7, 4, 6, 5, 1_2, 6]		,				)

  a__												= tokenizer.tokenize('''I was born in 92000, and this is falsé.'''      )
  self.assertListEqual(
      SCREAMING_SNAKE_CASE		,				[SPIECE_UNDERLINE, '''I''', SPIECE_UNDERLINE, '''w''', '''a''', '''s''', SPIECE_UNDERLINE, '''b''', '''o''', '''r''', '''n''', SPIECE_UNDERLINE, '''i''', '''n''', SPIECE_UNDERLINE, '''92000''', ''',''', SPIECE_UNDERLINE, '''a''', '''n''', '''d''', SPIECE_UNDERLINE, '''t''', '''h''', '''i''', '''s''', SPIECE_UNDERLINE, '''i''', '''s''', SPIECE_UNDERLINE, '''f''', '''a''', '''l''', '''s''', '''é''', '''.''']      )

  a__												= tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE      )
  # fmt: off
  self.assertListEqual(SCREAMING_SNAKE_CASE		,				[4, 3_0, 4, 2_0, 7, 1_2, 4, 2_5, 8, 1_3, 9, 4, 1_0, 9, 4, 3, 2_3, 4, 7, 9, 1_4, 4, 6, 1_1, 1_0, 1_2, 4, 1_0, 1_2, 4, 1_9, 7, 1_5, 1_2, 7_3, 2_6]      )
  # fmt: on

  a__												= tokenizer.convert_ids_to_tokens(SCREAMING_SNAKE_CASE      )
  self.assertListEqual(
      SCREAMING_SNAKE_CASE		,				[SPIECE_UNDERLINE, '''I''', SPIECE_UNDERLINE, '''w''', '''a''', '''s''', SPIECE_UNDERLINE, '''b''', '''o''', '''r''', '''n''', SPIECE_UNDERLINE, '''i''', '''n''', SPIECE_UNDERLINE, '''<unk>''', ''',''', SPIECE_UNDERLINE, '''a''', '''n''', '''d''', SPIECE_UNDERLINE, '''t''', '''h''', '''i''', '''s''', SPIECE_UNDERLINE, '''i''', '''s''', SPIECE_UNDERLINE, '''f''', '''a''', '''l''', '''s''', '''é''', '''.''']      )



 @slow
 def 						_UpperCAmelCase       (	self      ) ->			List[str]:
  # Use custom sequence because this tokenizer does not handle numbers.
  a__												= [
      '''Transformers (formerly known as pytorch-transformers and pytorch-pretrained-bert) provides '''
      '''general-purpose architectures (BERT, GPT, RoBERTa, XLM, DistilBert, XLNet...) for Natural '''
      '''Language Understanding (NLU) and Natural Language Generation (NLG) with over thirty-two pretrained '''
      '''models in one hundred plus languages and deep interoperability between Jax, PyTorch and TensorFlow.''',
      '''BERT is designed to pre-train deep bidirectional representations from unlabeled text by jointly '''
      '''conditioning on both left and right context in all layers.''',
      '''The quick brown fox jumps over the lazy dog.''',
  ]

  # fmt: off
  a__												= {
      '''input_ids''': [
          [4, 3_2, 1_3, 7, 9, 1_2, 1_9, 8, 1_3, 1_8, 5, 1_3, 1_2, 4, 6_4, 1_9, 8, 1_3, 1_8, 5, 1_3, 1_5, 2_2, 4, 2_8, 9, 8, 2_0, 9, 4, 7, 1_2, 4, 2_4, 2_2, 6, 8, 1_3, 1_7, 1_1, 3_9, 6, 1_3, 7, 9, 1_2, 1_9, 8, 1_3, 1_8, 5, 1_3, 1_2, 4, 7, 9, 1_4, 4, 2_4, 2_2, 6, 8, 1_3, 1_7, 1_1, 3_9, 2_4, 1_3, 5, 6, 1_3, 7, 1_0, 9, 5, 1_4, 3_9, 2_5, 5, 1_3, 6, 6_3, 4, 2_4, 1_3, 8, 2_7, 1_0, 1_4, 5, 1_2, 4, 2_1, 5, 9, 5, 1_3, 7, 1_5, 3_9, 2_4, 1_6, 1_3, 2_4, 8, 1_2, 5, 4, 7, 1_3, 1_7, 1_1, 1_0, 6, 5, 1_7, 6, 1_6, 1_3, 5, 1_2, 4, 6_4, 4_0, 4_7, 5_4, 3_2, 2_3, 4, 5_3, 4_9, 3_2, 2_3, 4, 5_4, 8, 4_0, 4_7, 5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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      ]
  }
  # fmt: on

  self.tokenizer_integration_test_util(
      expected_encoding=SCREAMING_SNAKE_CASE		,				model_name='''microsoft/speecht5_asr'''		,				revision='''c5ef64c71905caeccde0e4462ef3f9077224c524'''		,				sequences=SCREAMING_SNAKE_CASE		,				)










import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
     import torch

     from transformers import (
         OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
         OpenAIGPTConfig,
         OpenAIGPTDoubleHeadsModel,
         OpenAIGPTForSequenceClassification,
         OpenAIGPTLMHeadModel,
         OpenAIGPTModel,
     )
class    __UpperCamelCase			:

 """simple docstring"""



 def __init__(	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE=1_3		,				SCREAMING_SNAKE_CASE=7		,				SCREAMING_SNAKE_CASE=True		,				SCREAMING_SNAKE_CASE=True		,				SCREAMING_SNAKE_CASE=True		,				SCREAMING_SNAKE_CASE=9_9		,				SCREAMING_SNAKE_CASE=3_2		,				SCREAMING_SNAKE_CASE=5		,				SCREAMING_SNAKE_CASE=4		,				SCREAMING_SNAKE_CASE=3_7		,				SCREAMING_SNAKE_CASE="gelu"		,				SCREAMING_SNAKE_CASE=0.1		,				SCREAMING_SNAKE_CASE=0.1		,				SCREAMING_SNAKE_CASE=5_1_2		,				SCREAMING_SNAKE_CASE=1_6		,				SCREAMING_SNAKE_CASE=2		,				SCREAMING_SNAKE_CASE=0.02		,				SCREAMING_SNAKE_CASE=3		,				SCREAMING_SNAKE_CASE=4		,				SCREAMING_SNAKE_CASE=None		,				) ->			Union[str, Any]:
  a__												= parent
  a__												= batch_size
  a__												= seq_length
  a__												= is_training
  a__												= use_token_type_ids
  a__												= use_labels
  a__												= vocab_size
  a__												= hidden_size
  a__												= num_hidden_layers
  a__												= num_attention_heads
  a__												= intermediate_size
  a__												= hidden_act
  a__												= hidden_dropout_prob
  a__												= attention_probs_dropout_prob
  a__												= max_position_embeddings
  a__												= type_vocab_size
  a__												= type_sequence_label_size
  a__												= initializer_range
  a__												= num_labels
  a__												= num_choices
  a__												= scope
  a__												= self.vocab_size - 1

 def 						_UpperCAmelCase       (	self      ) ->			int:
  a__												= ids_tensor([self.batch_size, self.seq_length]		,				self.vocab_size      )

  a__												= None
  if self.use_token_type_ids:
   a__												= ids_tensor([self.batch_size, self.seq_length]		,				self.type_vocab_size      )

  a__												= None
  a__												= None
  a__												= None
  if self.use_labels:
   a__												= ids_tensor([self.batch_size]		,				self.type_sequence_label_size      )
   a__												= ids_tensor([self.batch_size, self.seq_length]		,				self.num_labels      )
   a__												= ids_tensor([self.batch_size]		,				self.num_choices      )

  a__												= 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__												= ids_tensor([self.num_hidden_layers, self.num_attention_heads]		,				2      )

  return (
      config,
      input_ids,
      head_mask,
      token_type_ids,
      sequence_labels,
      token_labels,
      choice_labels,
  )

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				*SCREAMING_SNAKE_CASE      ) ->			int:
  a__												= OpenAIGPTModel(config=SCREAMING_SNAKE_CASE      )
  model.to(SCREAMING_SNAKE_CASE      )
  model.eval()

  a__												= model(SCREAMING_SNAKE_CASE		,				token_type_ids=SCREAMING_SNAKE_CASE		,				head_mask=SCREAMING_SNAKE_CASE      )
  a__												= model(SCREAMING_SNAKE_CASE		,				token_type_ids=SCREAMING_SNAKE_CASE      )
  a__												= model(SCREAMING_SNAKE_CASE      )

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

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				*SCREAMING_SNAKE_CASE      ) ->			Tuple:
  a__												= OpenAIGPTLMHeadModel(SCREAMING_SNAKE_CASE      )
  model.to(SCREAMING_SNAKE_CASE      )
  model.eval()

  a__												= model(SCREAMING_SNAKE_CASE		,				token_type_ids=SCREAMING_SNAKE_CASE		,				labels=SCREAMING_SNAKE_CASE      )
  self.parent.assertEqual(result.loss.shape		,				()      )
  self.parent.assertEqual(result.logits.shape		,				(self.batch_size, self.seq_length, self.vocab_size)      )

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				*SCREAMING_SNAKE_CASE      ) ->			Dict:
  a__												= OpenAIGPTDoubleHeadsModel(SCREAMING_SNAKE_CASE      )
  model.to(SCREAMING_SNAKE_CASE      )
  model.eval()

  a__												= model(SCREAMING_SNAKE_CASE		,				token_type_ids=SCREAMING_SNAKE_CASE		,				labels=SCREAMING_SNAKE_CASE      )
  self.parent.assertEqual(result.loss.shape		,				()      )
  self.parent.assertEqual(result.logits.shape		,				(self.batch_size, self.seq_length, self.vocab_size)      )

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				*SCREAMING_SNAKE_CASE      ) ->			Optional[Any]:
  a__												= self.num_labels
  a__												= OpenAIGPTForSequenceClassification(SCREAMING_SNAKE_CASE      )
  model.to(SCREAMING_SNAKE_CASE      )
  model.eval()

  a__												= ids_tensor([self.batch_size]		,				self.type_sequence_label_size      )
  a__												= model(SCREAMING_SNAKE_CASE		,				token_type_ids=SCREAMING_SNAKE_CASE		,				labels=SCREAMING_SNAKE_CASE      )
  self.parent.assertEqual(result.logits.shape		,				(self.batch_size, self.num_labels)      )



 def 						_UpperCAmelCase       (	self      ) ->			str:
  a__												= self.prepare_config_and_inputs()
  (
      (
      a__
  )							,			(
      a__
  )							,			(
      a__
  )							,			(
      a__
  )							,			(
      a__
  )							,			(
      a__
  )							,			(
      a__
  )							,			
  )												= config_and_inputs
  a__												= {
      '''input_ids''': input_ids,
      '''token_type_ids''': token_type_ids,
      '''head_mask''': head_mask,
  }

  return config, inputs_dict





@require_torch
class    __UpperCamelCase			(       _lowercase	,	_lowercase	,	_lowercase	,	unittest.TestCase				):

 """simple docstring"""



 _lowercase   :    Dict      						=					(
     (OpenAIGPTModel, OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel, OpenAIGPTForSequenceClassification)
     if is_torch_available()
     else ()
 )
 _lowercase   :    Optional[Any]      						=					(
     (OpenAIGPTLMHeadModel,) if is_torch_available() else ()
 )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
 _lowercase   :    Dict      						=					(
     {
         '''feature-extraction''': OpenAIGPTModel,
         '''text-classification''': OpenAIGPTForSequenceClassification,
         '''text-generation''': OpenAIGPTLMHeadModel,
         '''zero-shot''': OpenAIGPTForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )

 def 						_UpperCAmelCase       (	self		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      ) ->			Optional[Any]:
  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		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE=False      ) ->			List[str]:
  a__												= super()._prepare_for_class(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE		,				return_labels=SCREAMING_SNAKE_CASE      )

  if return_labels:
   if model_class.__name__ == "OpenAIGPTDoubleHeadsModel":
    a__												= torch.zeros(
        (self.model_tester.batch_size, self.model_tester.num_choices, self.model_tester.seq_length)		,				dtype=torch.long		,				device=SCREAMING_SNAKE_CASE		,				)
    a__												= inputs_dict['''labels''']
    a__												= inputs_dict['''labels''']
    a__												= torch.zeros(
        (self.model_tester.batch_size, self.model_tester.num_choices)		,				dtype=torch.long		,				device=SCREAMING_SNAKE_CASE		,				)
    a__												= torch.zeros(
        self.model_tester.batch_size		,				dtype=torch.long		,				device=SCREAMING_SNAKE_CASE      )
  return inputs_dict

 def 						_UpperCAmelCase       (	self      ) ->			List[str]:
  a__												= OpenAIGPTModelTester(self      )
  a__												= ConfigTester(self		,				config_class=SCREAMING_SNAKE_CASE		,				n_embd=3_7      )

 def 						_UpperCAmelCase       (	self      ) ->			Optional[Any]:
  self.config_tester.run_common_tests()

 def 						_UpperCAmelCase       (	self      ) ->			Optional[int]:
  a__												= self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_openai_gpt_model(*SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self      ) ->			int:
  a__												= self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_lm_head_model(*SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self      ) ->			Optional[int]:
  a__												= self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_double_lm_head_model(*SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self      ) ->			Optional[int]:
  a__												= self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*SCREAMING_SNAKE_CASE      )



 @slow
 def 						_UpperCAmelCase       (	self      ) ->			Union[str, Any]:
  for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
   a__												= OpenAIGPTModel.from_pretrained(SCREAMING_SNAKE_CASE      )
   self.assertIsNotNone(SCREAMING_SNAKE_CASE      )





@require_torch
class    __UpperCamelCase			(       unittest.TestCase				):

 """simple docstring"""



 @slow
 def 						_UpperCAmelCase       (	self      ) ->			Optional[int]:
  a__												= OpenAIGPTLMHeadModel.from_pretrained('''openai-gpt'''      )
  model.to(SCREAMING_SNAKE_CASE      )
  a__												= torch.tensor([[4_8_1, 4_7_3_5, 5_4_4]]		,				dtype=torch.long		,				device=SCREAMING_SNAKE_CASE      )  # the president is
  a__												= [
      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__												= model.generate(SCREAMING_SNAKE_CASE		,				do_sample=SCREAMING_SNAKE_CASE      )
  self.assertListEqual(output_ids[0].tolist()		,				SCREAMING_SNAKE_CASE      )





