






# Lint as: python3
import os
import re
import urllib.parse
from pathlib import Path
from typing import Callable, List, Optional, Union
from zipfile import ZipFile

from ..utils.file_utils import cached_path, hf_github_url
from ..utils.logging import get_logger
from ..utils.version import Version


__magic_name__   :  Tuple        =							get_logger(__name__)





class 					A__     :

     '''simple docstring'''






     snake_case__					=					'''dummy_data'''
     snake_case__					=					'''datasets'''
     snake_case__					=					False







     def __init__( self      :    Tuple   ,						_SCREAMING_SNAKE_CASE      :    Dict   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]   ,						_SCREAMING_SNAKE_CASE      :    List[Any]   ,						_SCREAMING_SNAKE_CASE      :    int = None   ,						_SCREAMING_SNAKE_CASE      :    Tuple = False   ,						_SCREAMING_SNAKE_CASE      :    Any = True   ,						_SCREAMING_SNAKE_CASE      :    Tuple = None   ,						):






           """simple docstring"""




           UpperCamelCase					       =  0
           UpperCamelCase					       =  dataset_name
           UpperCamelCase					       =  cache_dir
           UpperCamelCase					       =  use_local_dummy_data
           UpperCamelCase					       =  config
           # download_callbacks take a single url as input
           UpperCamelCase					       =  download_callbacks or []
           # if False, it doesn't load existing files and it returns the paths of the dummy files relative
           # to the dummy_data zip file root
           UpperCamelCase					       =  load_existing_dummy_data

           # TODO(PVP, QL) might need to make this more general
           UpperCamelCase					       =  str(_SCREAMING_SNAKE_CASE )
           # to be downloaded
           UpperCamelCase					       =  None
           UpperCamelCase					       =  None







     @property
     def   _SCREAMING_SNAKE_CASE     ( self      :    List[Any] ):






           """simple docstring"""




           if self._dummy_file is None:
                 UpperCamelCase					       =  self.download_dummy_data()
           return self._dummy_file







     @property
     def   _SCREAMING_SNAKE_CASE     ( self      :    Optional[int] ):






           """simple docstring"""




           if self.config is not None:
                 # structure is dummy / config_name / version_name
                 return os.path.join('dummy'   ,						self.config.name   ,						self.version_name )
           # structure is dummy / version_name
           return os.path.join('dummy'   ,						self.version_name )







     @property
     def   _SCREAMING_SNAKE_CASE     ( self      :    Union[str, Any] ):






           """simple docstring"""




           return os.path.join(self.dummy_data_folder   ,						'dummy_data.zip' )







     def   _SCREAMING_SNAKE_CASE     ( self      :    List[str] ):






           """simple docstring"""




           UpperCamelCase					       =  (
               self.local_path_to_dummy_data if self.use_local_dummy_data is True else self.github_path_to_dummy_data
           )

           UpperCamelCase					       =  cached_path(
               _SCREAMING_SNAKE_CASE   ,						cache_dir=self.cache_dir   ,						extract_compressed_file=_SCREAMING_SNAKE_CASE   ,						force_extract=_SCREAMING_SNAKE_CASE )

           return os.path.join(_SCREAMING_SNAKE_CASE   ,						self.dummy_file_name )







     @property
     def   _SCREAMING_SNAKE_CASE     ( self      :    Optional[Any] ):






           """simple docstring"""




           return os.path.join(self.datasets_scripts_dir   ,						self.dataset_name   ,						self.dummy_zip_file )







     @property
     def   _SCREAMING_SNAKE_CASE     ( self      :    Optional[int] ):






           """simple docstring"""




           if self._bucket_url is None:
                 UpperCamelCase					       =  hf_github_url(self.dataset_name   ,						self.dummy_zip_file.replace(os.sep   ,						'/' ) )
           return self._bucket_url







     @property
     def   _SCREAMING_SNAKE_CASE     ( self      :    List[str] ):






           """simple docstring"""




           if os.path.isdir(self.dummy_file ):
                 return self.dummy_file
           # else cut off path to file -> example `xsum`.
           return "/".join(self.dummy_file.replace(os.sep   ,						'/' ).split('/' )[:-1] )







     def   _SCREAMING_SNAKE_CASE     ( self      :    int   ,						_SCREAMING_SNAKE_CASE      :    Union[str, Any]   ,						*_SCREAMING_SNAKE_CASE      :    Any ):






           """simple docstring"""




           if self.load_existing_dummy_data:
                 # dummy data is downloaded and tested
                 UpperCamelCase					       =  self.dummy_file
           else:
                 # dummy data cannot be downloaded and only the path to dummy file is returned
                 UpperCamelCase					       =  self.dummy_file_name

           # special case when data_url is a dict
           if isinstance(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE ):
                 return self.create_dummy_data_dict(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE )
           elif isinstance(_SCREAMING_SNAKE_CASE   ,						(list, tuple) ):
                 return self.create_dummy_data_list(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE )
           else:
                 return self.create_dummy_data_single(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE )







     def   _SCREAMING_SNAKE_CASE     ( self      :    Optional[Any]   ,						_SCREAMING_SNAKE_CASE      :    Tuple   ,						*_SCREAMING_SNAKE_CASE      :    Any ):






           """simple docstring"""




           return self.download_and_extract(_SCREAMING_SNAKE_CASE )







     def   _SCREAMING_SNAKE_CASE     ( self      :    int   ,						_SCREAMING_SNAKE_CASE      :    List[str]   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any] ):






           """simple docstring"""




           return self.download_and_extract(_SCREAMING_SNAKE_CASE )







     def   _SCREAMING_SNAKE_CASE     ( self      :    Optional[int]   ,						_SCREAMING_SNAKE_CASE      :    List[str]   ,						*_SCREAMING_SNAKE_CASE      :    Optional[int]   ,						**_SCREAMING_SNAKE_CASE      :    Tuple ):






           """simple docstring"""




           return path







     def   _SCREAMING_SNAKE_CASE     ( self      :    List[str] ):






           """simple docstring"""




           return {}







     def   _SCREAMING_SNAKE_CASE     ( self      :    int   ,						_SCREAMING_SNAKE_CASE      :    str   ,						_SCREAMING_SNAKE_CASE      :    str ):






           """simple docstring"""




           UpperCamelCase					       =  {}
           for key, single_urls in data_url.items():
                 for download_callback in self.download_callbacks:
                       if isinstance(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE ):
                             for single_url in single_urls:
                                   download_callback(_SCREAMING_SNAKE_CASE )
                       else:
                             UpperCamelCase					       =  single_urls
                             download_callback(_SCREAMING_SNAKE_CASE )
                                    # we force the name of each key to be the last file / folder name of the url path
                                    # if the url has arguments, we need to encode them with urllib.parse.quote_plus
                 if isinstance(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE ):
                       UpperCamelCase					       =  [os.path.join(_SCREAMING_SNAKE_CASE   ,						urllib.parse.quote_plus(Path(_SCREAMING_SNAKE_CASE ).name ) ) for x in single_urls]
                 else:
                       UpperCamelCase					       =  single_urls
                       UpperCamelCase					       =  os.path.join(_SCREAMING_SNAKE_CASE   ,						urllib.parse.quote_plus(Path(_SCREAMING_SNAKE_CASE ).name ) )
                 UpperCamelCase					       =  value

           # make sure that values are unique
           if all(isinstance(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE ) for i in dummy_data_dict.values() ) and len(set(dummy_data_dict.values() ) ) < len(
               dummy_data_dict.values() ):
                 # append key to value to make its name unique
                 UpperCamelCase					       =  {key: value + key for key, value in dummy_data_dict.items()}

           return dummy_data_dict







     def   _SCREAMING_SNAKE_CASE     ( self      :    Any   ,						_SCREAMING_SNAKE_CASE      :    List[str]   ,						_SCREAMING_SNAKE_CASE      :    Optional[int] ):






           """simple docstring"""




           UpperCamelCase					       =  []
           # trick: if there are many shards named like `data.txt-000001-of-00300`, only use the first one
           UpperCamelCase					       =  all(bool(re.findall('[0-9]{3,}-of-[0-9]{3,}'   ,						_SCREAMING_SNAKE_CASE ) ) for url in data_url )
           UpperCamelCase					       =  all(
               url.startswith('https://ftp.ncbi.nlm.nih.gov/pubmed/baseline/pubmed' ) for url in data_url )
           if data_url and (is_tf_records or is_pubmed_records):
                 UpperCamelCase					       =  [data_url[0]] * len(_SCREAMING_SNAKE_CASE )
           for single_url in data_url:
                 for download_callback in self.download_callbacks:
                       download_callback(_SCREAMING_SNAKE_CASE )
                 # we force the name of each key to be the last file / folder name of the url path
                 # if the url has arguments, we need to encode them with urllib.parse.quote_plus
                 UpperCamelCase					       =  os.path.join(_SCREAMING_SNAKE_CASE   ,						urllib.parse.quote_plus(single_url.split('/' )[-1] ) )
                 dummy_data_list.append(_SCREAMING_SNAKE_CASE )
           return dummy_data_list







     def   _SCREAMING_SNAKE_CASE     ( self      :    str   ,						_SCREAMING_SNAKE_CASE      :    int   ,						_SCREAMING_SNAKE_CASE      :    Union[str, Any] ):






           """simple docstring"""




           for download_callback in self.download_callbacks:
                 download_callback(_SCREAMING_SNAKE_CASE )
           # we force the name of each key to be the last file / folder name of the url path
           # if the url has arguments, we need to encode them with urllib.parse.quote_plus
           UpperCamelCase					       =  os.path.join(_SCREAMING_SNAKE_CASE   ,						urllib.parse.quote_plus(data_url.split('/' )[-1] ) )
           if os.path.exists(_SCREAMING_SNAKE_CASE ) or not self.load_existing_dummy_data:
                 return value
           else:
                 # Backward compatibility, maybe deprecate at one point.
                 # For many datasets with single url calls to dl_manager.download_and_extract,
                 # the dummy_data.zip file is actually the zipped downloaded file
                 # while now we expected the dummy_data.zip file to be a directory containing
                 # the downloaded file.
                 return path_to_dummy_data







     def   _SCREAMING_SNAKE_CASE     ( self      :    List[str] ):






           """simple docstring"""




           pass







     def   _SCREAMING_SNAKE_CASE     ( self      :    str ):






           """simple docstring"""




           pass







     def   _SCREAMING_SNAKE_CASE     ( self      :    Union[str, Any]   ,						_SCREAMING_SNAKE_CASE      :    Any ):






           """simple docstring"""




           def _iter_archive_members(_SCREAMING_SNAKE_CASE      :    Dict ):
                 # this preserves the order of the members inside the ZIP archive
                 UpperCamelCase					       =  Path(self.dummy_file ).parent
                 UpperCamelCase					       =  path.relative_to(_SCREAMING_SNAKE_CASE )
                 with ZipFile(self.local_path_to_dummy_data ) as zip_file:
                       UpperCamelCase					       =  zip_file.namelist()
                 for member in members:
                       if member.startswith(relative_path.as_posix() ):
                             yield dummy_parent_path.joinpath(_SCREAMING_SNAKE_CASE )

           UpperCamelCase					       =  Path(_SCREAMING_SNAKE_CASE )
           UpperCamelCase					       =  _iter_archive_members(_SCREAMING_SNAKE_CASE ) if self.use_local_dummy_data else path.rglob('*' )
           for file_path in file_paths:
                 if file_path.is_file() and not file_path.name.startswith(('.', '__') ):
                       yield file_path.relative_to(_SCREAMING_SNAKE_CASE ).as_posix(), file_path.open('rb' )







     def   _SCREAMING_SNAKE_CASE     ( self      :    Optional[Any]   ,						_SCREAMING_SNAKE_CASE      :    Tuple ):






           """simple docstring"""




           if not isinstance(_SCREAMING_SNAKE_CASE   ,						_SCREAMING_SNAKE_CASE ):
                 UpperCamelCase					       =  [paths]
           for path in paths:
                 if os.path.isfile(_SCREAMING_SNAKE_CASE ):
                       if os.path.basename(_SCREAMING_SNAKE_CASE ).startswith(('.', '__') ):
                             return
                       yield path
                 else:
                       for dirpath, dirnames, filenames in os.walk(_SCREAMING_SNAKE_CASE ):
                             if os.path.basename(_SCREAMING_SNAKE_CASE ).startswith(('.', '__') ):
                                   continue
                             dirnames.sort()
                             for filename in sorted(_SCREAMING_SNAKE_CASE ):
                                   if filename.startswith(('.', '__') ):
                                         continue
                                   yield os.path.join(_SCREAMING_SNAKE_CASE   ,						_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      )





