



import os
import sys
import tempfile
import unittest
import unittest.mock as mock
from pathlib import Path

from huggingface_hub import HfFolder, delete_repo
from huggingface_hub.file_download import http_get
from requests.exceptions import HTTPError

from transformers import (
    AlbertTokenizer,
    AutoTokenizer,
    BertTokenizer,
    BertTokenizerFast,
    GPTaTokenizerFast,
    is_tokenizers_available,
)
from transformers.testing_utils import TOKEN, USER, is_staging_test, require_tokenizers
from transformers.tokenization_utils import Trie


sys.path.append(str(Path(__file__).parent.parent / "utils"))

from test_module.custom_tokenization import CustomTokenizer  # noqa E402


if is_tokenizers_available():
 from test_module.custom_tokenization_fast import CustomTokenizerFast




class 					snake_case__						(       unittest.TestCase     ):






     """simple docstring"""


     def    lowercase_   (       self  :  Dict					)   ->Any:
            # A mock response for an HTTP head request to emulate server down
            snake_case__							:	List[str]   	=	mock.Mock()
            snake_case__							:	Tuple   	=	5_0_0
            snake_case__							:	Union[str, Any]   	=	{}
            snake_case__							:	List[Any]   	=	HTTPError
            snake_case__							:	Union[str, Any]   	=	{}

            # Download this model to make sure it's in the cache.
            snake_case__							:	Union[str, Any]   	=	BertTokenizer.from_pretrained('hf-internal-testing/tiny-random-bert'					)

            # Under the mock environment we get a 500 error when trying to reach the tokenizer.
            with mock.patch('requests.Session.request', return_value=_snake_case					) as mock_head:
                   snake_case__							:	Union[str, Any]   	=	BertTokenizer.from_pretrained('hf-internal-testing/tiny-random-bert'					)
                   # This check we did call the fake head request
                   mock_head.assert_called()






     @require_tokenizers
     def    lowercase_   (       self  :  Dict					)   ->Optional[int]:
            # A mock response for an HTTP head request to emulate server down
            snake_case__							:	int   	=	mock.Mock()
            snake_case__							:	Optional[Any]   	=	5_0_0
            snake_case__							:	Dict   	=	{}
            snake_case__							:	Tuple   	=	HTTPError
            snake_case__							:	Optional[Any]   	=	{}

            # Download this model to make sure it's in the cache.
            snake_case__							:	Tuple   	=	GPTaTokenizerFast.from_pretrained('gpt2'					)

            # Under the mock environment we get a 500 error when trying to reach the tokenizer.
            with mock.patch('requests.Session.request', return_value=_snake_case					) as mock_head:
                   snake_case__							:	Optional[Any]   	=	GPTaTokenizerFast.from_pretrained('gpt2'					)
                   # This check we did call the fake head request
                   mock_head.assert_called()






     def    lowercase_   (       self  :  List[Any]					)   ->Dict:
            # This test is for deprecated behavior and can be removed in v5
            try:
                   snake_case__							:	Optional[int]   	=	tempfile.mktemp()
                   with open(_snake_case, 'wb'					) as f:
                          http_get('https://huggingface.co/albert-base-v1/resolve/main/spiece.model', _snake_case					)

                   snake_case__							:	Dict   	=	AlbertTokenizer.from_pretrained(_snake_case					)
            finally:
                   os.remove(_snake_case					)

            # Supporting this legacy load introduced a weird bug where the tokenizer would load local files if they are in
            # the current folder and have the right name.
            if os.path.isfile('tokenizer.json'					):
                   # We skip the test if the user has a `tokenizer.json` in this folder to avoid deleting it.
                   return
            try:
                   with open('tokenizer.json', 'wb'					) as f:
                          http_get('https://huggingface.co/hf-internal-testing/tiny-random-bert/blob/main/tokenizer.json', _snake_case					)
                   snake_case__							:	Optional[Any]   	=	AutoTokenizer.from_pretrained('hf-internal-testing/tiny-random-gpt2'					)
                   # The tiny random BERT has a vocab size of 1024, tiny gpt2 as a vocab size of 1000
                   self.assertEqual(tokenizer.vocab_size, 1_0_0_0					)
                   # Tokenizer should depend on the remote checkpoint, not the local tokenizer.json file.

            finally:
                   os.remove('tokenizer.json'					)






     def    lowercase_   (       self  :  Union[str, Any]					)   ->Union[str, Any]:
            # This test is for deprecated behavior and can be removed in v5
            snake_case__							:	Optional[int]   	=	AlbertTokenizer.from_pretrained('https://huggingface.co/albert-base-v1/resolve/main/spiece.model'					)




@is_staging_test
class 					snake_case__						(       unittest.TestCase     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	["""[UNK]""", """[CLS]""", """[SEP]""", """[PAD]""", """[MASK]""", """bla""", """blou"""]






     @classmethod
     def    lowercase_   (       cls  :  Any					)   ->List[Any]:
            snake_case__							:	Optional[int]   	=	TOKEN
            HfFolder.save_token(_snake_case					)






     @classmethod
     def    lowercase_   (       cls  :  Any					)   ->int:
            try:
                   delete_repo(token=cls._token, repo_id='test-tokenizer'					)
            except HTTPError:
                   pass

            try:
                   delete_repo(token=cls._token, repo_id='valid_org/test-tokenizer-org'					)
            except HTTPError:
                   pass

            try:
                   delete_repo(token=cls._token, repo_id='test-dynamic-tokenizer'					)
            except HTTPError:
                   pass






     def    lowercase_   (       self  :  Optional[int]					)   ->Optional[int]:
            with tempfile.TemporaryDirectory() as tmp_dir:
                   snake_case__							:	List[Any]   	=	os.path.join(_snake_case, 'vocab.txt'					)
                   with open(_snake_case, 'w', encoding='utf-8'					) as vocab_writer:
                          vocab_writer.write(''.join([x + '\n' for x in self.vocab_tokens]					)					)
                   snake_case__							:	str   	=	BertTokenizer(_snake_case					)

            tokenizer.push_to_hub('test-tokenizer', use_auth_token=self._token					)
            snake_case__							:	int   	=	BertTokenizer.from_pretrained(F'''{USER}/test-tokenizer'''					)
            self.assertDictEqual(new_tokenizer.vocab, tokenizer.vocab					)

            # Reset repo
            delete_repo(token=self._token, repo_id='test-tokenizer'					)

            # Push to hub via save_pretrained
            with tempfile.TemporaryDirectory() as tmp_dir:
                   tokenizer.save_pretrained(_snake_case, repo_id='test-tokenizer', push_to_hub=_snake_case, use_auth_token=self._token					)

            snake_case__							:	Any   	=	BertTokenizer.from_pretrained(F'''{USER}/test-tokenizer'''					)
            self.assertDictEqual(new_tokenizer.vocab, tokenizer.vocab					)






     def    lowercase_   (       self  :  Tuple					)   ->Union[str, Any]:
            with tempfile.TemporaryDirectory() as tmp_dir:
                   snake_case__							:	Tuple   	=	os.path.join(_snake_case, 'vocab.txt'					)
                   with open(_snake_case, 'w', encoding='utf-8'					) as vocab_writer:
                          vocab_writer.write(''.join([x + '\n' for x in self.vocab_tokens]					)					)
                   snake_case__							:	Any   	=	BertTokenizer(_snake_case					)

            tokenizer.push_to_hub('valid_org/test-tokenizer-org', use_auth_token=self._token					)
            snake_case__							:	List[str]   	=	BertTokenizer.from_pretrained('valid_org/test-tokenizer-org'					)
            self.assertDictEqual(new_tokenizer.vocab, tokenizer.vocab					)

            # Reset repo
            delete_repo(token=self._token, repo_id='valid_org/test-tokenizer-org'					)

            # Push to hub via save_pretrained
            with tempfile.TemporaryDirectory() as tmp_dir:
                   tokenizer.save_pretrained(
                       _snake_case, repo_id='valid_org/test-tokenizer-org', push_to_hub=_snake_case, use_auth_token=self._token					)

            snake_case__							:	Any   	=	BertTokenizer.from_pretrained('valid_org/test-tokenizer-org'					)
            self.assertDictEqual(new_tokenizer.vocab, tokenizer.vocab					)






     @require_tokenizers
     def    lowercase_   (       self  :  Optional[int]					)   ->List[str]:
            CustomTokenizer.register_for_auto_class()
            with tempfile.TemporaryDirectory() as tmp_dir:
                   snake_case__							:	Any   	=	os.path.join(_snake_case, 'vocab.txt'					)
                   with open(_snake_case, 'w', encoding='utf-8'					) as vocab_writer:
                          vocab_writer.write(''.join([x + '\n' for x in self.vocab_tokens]					)					)
                   snake_case__							:	Union[str, Any]   	=	CustomTokenizer(_snake_case					)

            # No fast custom tokenizer
            tokenizer.push_to_hub('test-dynamic-tokenizer', use_auth_token=self._token					)

            snake_case__							:	Dict   	=	AutoTokenizer.from_pretrained(F'''{USER}/test-dynamic-tokenizer''', trust_remote_code=_snake_case					)
            # Can't make an isinstance check because the new_model.config is from the CustomTokenizer class of a dynamic module
            self.assertEqual(tokenizer.__class__.__name__, 'CustomTokenizer'					)

            # Fast and slow custom tokenizer
            CustomTokenizerFast.register_for_auto_class()
            with tempfile.TemporaryDirectory() as tmp_dir:
                   snake_case__							:	Optional[int]   	=	os.path.join(_snake_case, 'vocab.txt'					)
                   with open(_snake_case, 'w', encoding='utf-8'					) as vocab_writer:
                          vocab_writer.write(''.join([x + '\n' for x in self.vocab_tokens]					)					)

                   snake_case__							:	Union[str, Any]   	=	BertTokenizerFast.from_pretrained(_snake_case					)
                   bert_tokenizer.save_pretrained(_snake_case					)
                   snake_case__							:	Dict   	=	CustomTokenizerFast.from_pretrained(_snake_case					)

            tokenizer.push_to_hub('test-dynamic-tokenizer', use_auth_token=self._token					)

            snake_case__							:	List[Any]   	=	AutoTokenizer.from_pretrained(F'''{USER}/test-dynamic-tokenizer''', trust_remote_code=_snake_case					)
            # Can't make an isinstance check because the new_model.config is from the FakeConfig class of a dynamic module
            self.assertEqual(tokenizer.__class__.__name__, 'CustomTokenizerFast'					)
            snake_case__							:	int   	=	AutoTokenizer.from_pretrained(
                F'''{USER}/test-dynamic-tokenizer''', use_fast=_snake_case, trust_remote_code=_snake_case					)
            # Can't make an isinstance check because the new_model.config is from the FakeConfig class of a dynamic module
            self.assertEqual(tokenizer.__class__.__name__, 'CustomTokenizer'					)




class 					snake_case__						(       unittest.TestCase     ):






     """simple docstring"""


     def    lowercase_   (       self  :  Optional[Any]					)   ->Any:
            snake_case__							:	Any   	=	Trie()
            trie.add('Hello 友達'					)
            self.assertEqual(trie.data, {'H': {'e': {'l': {'l': {'o': {' ': {'友': {'達': {'': 1}}}}}}}}}					)
            trie.add('Hello'					)
            trie.data
            self.assertEqual(trie.data, {'H': {'e': {'l': {'l': {'o': {'': 1, ' ': {'友': {'達': {'': 1}}}}}}}}}					)






     def    lowercase_   (       self  :  Tuple					)   ->Any:
            snake_case__							:	int   	=	Trie()
            self.assertEqual(trie.split('[CLS] This is a extra_id_100'					), ['[CLS] This is a extra_id_100']					)
            trie.add('[CLS]'					)
            trie.add('extra_id_1'					)
            trie.add('extra_id_100'					)
            self.assertEqual(trie.split('[CLS] This is a extra_id_100'					), ['[CLS]', ' This is a ', 'extra_id_100']					)






     def    lowercase_   (       self  :  Optional[Any]					)   ->Union[str, Any]:
            snake_case__							:	Union[str, Any]   	=	Trie()
            trie.add('A'					)
            self.assertEqual(trie.split('ABC'					), ['A', 'BC']					)
            self.assertEqual(trie.split('BCA'					), ['BC', 'A']					)






     def    lowercase_   (       self  :  Union[str, Any]					)   ->Dict:
            snake_case__							:	Tuple   	=	Trie()
            trie.add('TOKEN]'					)
            trie.add('[SPECIAL_TOKEN]'					)
            self.assertEqual(trie.split('This is something [SPECIAL_TOKEN]'					), ['This is something ', '[SPECIAL_TOKEN]']					)






     def    lowercase_   (       self  :  Optional[int]					)   ->List[Any]:
            snake_case__							:	int   	=	Trie()
            trie.add('A'					)
            trie.add('P'					)
            trie.add('[SPECIAL_TOKEN]'					)
            self.assertEqual(trie.split('This is something [SPECIAL_TOKEN]'					), ['This is something ', '[SPECIAL_TOKEN]']					)






     def    lowercase_   (       self  :  List[str]					)   ->List[Any]:
            snake_case__							:	str   	=	Trie()
            trie.add('AB'					)
            trie.add('B'					)
            trie.add('C'					)
            self.assertEqual(trie.split('ABC'					), ['AB', 'C']					)






     def    lowercase_   (       self  :  int					)   ->Optional[Any]:
            snake_case__							:	Union[str, Any]   	=	Trie()
            trie.add('ABC'					)
            trie.add('B'					)
            trie.add('CD'					)
            self.assertEqual(trie.split('ABCD'					), ['ABC', 'D']					)






     def    lowercase_   (       self  :  str					)   ->Dict:
            # Even if the offsets are wrong, we necessarily output correct string
            # parts.
            snake_case__							:	Tuple   	=	Trie()
            snake_case__							:	Optional[int]   	=	trie.cut_text('ABC', [0, 0, 2, 1, 2, 3]					)
            self.assertEqual(_snake_case, ['AB', 'C']					)











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






     """simple docstring"""


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






     def    lowercase_   (       self  :  Union[str, Any]					)   ->Tuple:
            snake_case__							:	List[str]   	=	ids_tensor([self.batch_size, self.seq_length], self.vocab_size					)

            snake_case__							:	List[str]   	=	None
            if self.use_token_type_ids:
                   snake_case__							:	Optional[Any]   	=	ids_tensor([self.batch_size, self.seq_length], self.type_vocab_size					)

            snake_case__							:	Tuple   	=	None
            snake_case__							:	str   	=	None
            snake_case__							:	List[Any]   	=	None
            if self.use_labels:
                   snake_case__							:	Dict   	=	ids_tensor([self.batch_size], self.type_sequence_label_size					)
                   snake_case__							:	int   	=	ids_tensor([self.batch_size, self.seq_length], self.num_labels					)
                   snake_case__							:	List[str]   	=	ids_tensor([self.batch_size], self.num_choices					)

            snake_case__							:	Union[str, 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, )

            snake_case__							:	List[str]   	=	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    lowercase_   (       self  :  Any, _snake_case  :  List[str], _snake_case  :  Any, _snake_case  :  List[Any], _snake_case  :  Tuple, *_snake_case  :  Optional[Any]					)   ->Tuple:
            snake_case__							:	Union[str, Any]   	=	OpenAIGPTModel(config=_snake_case					)
            model.to(_snake_case					)
            model.eval()

            snake_case__							:	Optional[Any]   	=	model(_snake_case, token_type_ids=_snake_case, head_mask=_snake_case					)
            snake_case__							:	Union[str, Any]   	=	model(_snake_case, token_type_ids=_snake_case					)
            snake_case__							:	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  :  Optional[int], _snake_case  :  Optional[Any], _snake_case  :  Union[str, Any], _snake_case  :  Optional[int], _snake_case  :  List[Any], *_snake_case  :  Dict					)   ->Optional[int]:
            snake_case__							:	Optional[Any]   	=	OpenAIGPTLMHeadModel(_snake_case					)
            model.to(_snake_case					)
            model.eval()

            snake_case__							:	Tuple   	=	model(_snake_case, token_type_ids=_snake_case, labels=_snake_case					)
            self.parent.assertEqual(result.loss.shape, ()					)
            self.parent.assertEqual(result.logits.shape, (self.batch_size, self.seq_length, self.vocab_size)					)






     def    lowercase_   (       self  :  int, _snake_case  :  Tuple, _snake_case  :  List[str], _snake_case  :  List[Any], _snake_case  :  List[Any], *_snake_case  :  List[Any]					)   ->Optional[int]:
            snake_case__							:	List[str]   	=	OpenAIGPTDoubleHeadsModel(_snake_case					)
            model.to(_snake_case					)
            model.eval()

            snake_case__							:	Optional[Any]   	=	model(_snake_case, token_type_ids=_snake_case, labels=_snake_case					)
            self.parent.assertEqual(result.loss.shape, ()					)
            self.parent.assertEqual(result.logits.shape, (self.batch_size, self.seq_length, self.vocab_size)					)






     def    lowercase_   (       self  :  Optional[int], _snake_case  :  Tuple, _snake_case  :  Dict, _snake_case  :  List[str], _snake_case  :  Optional[Any], *_snake_case  :  Union[str, Any]					)   ->str:
            snake_case__							:	List[str]   	=	self.num_labels
            snake_case__							:	Dict   	=	OpenAIGPTForSequenceClassification(_snake_case					)
            model.to(_snake_case					)
            model.eval()

            snake_case__							:	List[str]   	=	ids_tensor([self.batch_size], self.type_sequence_label_size					)
            snake_case__							:	List[str]   	=	model(_snake_case, token_type_ids=_snake_case, labels=_snake_case					)
            self.parent.assertEqual(result.logits.shape, (self.batch_size, self.num_labels)					)






     def    lowercase_   (       self  :  Dict					)   ->int:
            snake_case__							:	List[Any]   	=	self.prepare_config_and_inputs()
            (
                (
                snake_case__
            )	,				(
                snake_case__
            )	,				(
                snake_case__
            )	,				(
                snake_case__
            )	,				(
                snake_case__
            )	,				(
                snake_case__
            )	,				(
                snake_case__
            )	,				
            )							:	Optional[Any]   	=	config_and_inputs
            snake_case__							:	str   	=	{
                'input_ids': input_ids,
                'token_type_ids': token_type_ids,
                'head_mask': head_mask,
            }

            return config, inputs_dict




@require_torch
class 					snake_case__						(       lowerCAmelCase_				,     lowerCAmelCase_				,     lowerCAmelCase_				,     unittest.TestCase     ):






     """simple docstring"""


     _SCREAMING_SNAKE_CASE						=	(
         (OpenAIGPTModel, OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel, OpenAIGPTForSequenceClassification)
         if is_torch_available()
         else ()
     )
     _SCREAMING_SNAKE_CASE						=	(
         (OpenAIGPTLMHeadModel,) if is_torch_available() else ()
     )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
     _SCREAMING_SNAKE_CASE						=	(
         {
             """feature-extraction""": OpenAIGPTModel,
             """text-classification""": OpenAIGPTForSequenceClassification,
             """text-generation""": OpenAIGPTLMHeadModel,
             """zero-shot""": OpenAIGPTForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )






     def    lowercase_   (       self  :  Optional[int], _snake_case  :  Union[str, Any], _snake_case  :  int, _snake_case  :  Tuple, _snake_case  :  Tuple, _snake_case  :  List[str]					)   ->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    lowercase_   (       self  :  Optional[Any], _snake_case  :  Union[str, Any], _snake_case  :  List[str], _snake_case  :  Any=False					)   ->Tuple:
            snake_case__							:	Optional[int]   	=	super()._prepare_for_class(_snake_case, _snake_case, return_labels=_snake_case					)

            if return_labels:
                   if model_class.__name__ == "OpenAIGPTDoubleHeadsModel":
                          snake_case__							:	Union[str, Any]   	=	torch.zeros(
                              (self.model_tester.batch_size, self.model_tester.num_choices, self.model_tester.seq_length), dtype=torch.long, device=_snake_case, )
                          snake_case__							:	List[Any]   	=	inputs_dict['labels']
                          snake_case__							:	List[Any]   	=	inputs_dict['labels']
                          snake_case__							:	Any   	=	torch.zeros(
                              (self.model_tester.batch_size, self.model_tester.num_choices), dtype=torch.long, device=_snake_case, )
                          snake_case__							:	Tuple   	=	torch.zeros(
                              self.model_tester.batch_size, dtype=torch.long, device=_snake_case					)
            return inputs_dict






     def    lowercase_   (       self  :  Union[str, Any]					)   ->List[str]:
            snake_case__							:	List[str]   	=	OpenAIGPTModelTester(self					)
            snake_case__							:	Any   	=	ConfigTester(self, config_class=_snake_case, n_embd=3_7					)






     def    lowercase_   (       self  :  Optional[int]					)   ->str:
            self.config_tester.run_common_tests()






     def    lowercase_   (       self  :  int					)   ->Tuple:
            snake_case__							:	str   	=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_openai_gpt_model(*_snake_case					)






     def    lowercase_   (       self  :  Tuple					)   ->List[str]:
            snake_case__							:	Optional[int]   	=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_lm_head_model(*_snake_case					)






     def    lowercase_   (       self  :  Dict					)   ->int:
            snake_case__							:	Optional[Any]   	=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_double_lm_head_model(*_snake_case					)






     def    lowercase_   (       self  :  int					)   ->str:
            snake_case__							:	List[Any]   	=	self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*_snake_case					)






     @slow
     def    lowercase_   (       self  :  Optional[Any]					)   ->str:
            for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   snake_case__							:	Optional[int]   	=	OpenAIGPTModel.from_pretrained(_snake_case					)
                   self.assertIsNotNone(_snake_case					)




@require_torch
class 					snake_case__						(       unittest.TestCase     ):






     """simple docstring"""


     @slow
     def    lowercase_   (       self  :  Tuple					)   ->Optional[int]:
            snake_case__							:	Union[str, Any]   	=	OpenAIGPTLMHeadModel.from_pretrained('openai-gpt'					)
            model.to(_snake_case					)
            snake_case__							:	Tuple   	=	torch.tensor([[4_8_1, 4_7_3_5, 5_4_4]], dtype=torch.long, device=_snake_case					)  # the president is
            snake_case__							:	int   	=	[
                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

            snake_case__							:	Optional[int]   	=	model.generate(_snake_case, do_sample=_snake_case					)
            self.assertListEqual(output_ids[0].tolist(), _snake_case					)






