






import inspect
import unittest

from huggingface_hub import hf_hub_download

from transformers import ConvNextConfig, UperNetConfig
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import UperNetForSemanticSegmentation
							from transformers.models.upernet.modeling_upernet import UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
							from PIL import Image

							from transformers import AutoImageProcessor




class 				__A     :





				"""simple docstring"""







				def __init__( self							,  lowerCamelCase__							,  lowerCamelCase__=13							,  lowerCamelCase__=32							,  lowerCamelCase__=3							,  lowerCamelCase__=4							,  lowerCamelCase__=[10, 20, 30, 40]							,  lowerCamelCase__=[2, 2, 3, 2]							,  lowerCamelCase__=True							,  lowerCamelCase__=True							,  lowerCamelCase__=37							,  lowerCamelCase__="gelu"							,  lowerCamelCase__=10							,  lowerCamelCase__=0.02							,  lowerCamelCase__=["stage2", "stage3", "stage4"]							,  lowerCamelCase__=3							,  lowerCamelCase__=None							,  ):




									"""simple docstring"""

									__UpperCamelCase      :					Optional[Any]       		=parent
									__UpperCamelCase      :					List[str]       		=batch_size
									__UpperCamelCase      :					int       		=image_size
									__UpperCamelCase      :					Tuple       		=num_channels
									__UpperCamelCase      :					List[str]       		=num_stages
									__UpperCamelCase      :					str       		=hidden_sizes
									__UpperCamelCase      :					Optional[int]       		=depths
									__UpperCamelCase      :					Union[str, Any]       		=is_training
									__UpperCamelCase      :					Optional[Any]       		=use_labels
									__UpperCamelCase      :					List[Any]       		=intermediate_size
									__UpperCamelCase      :					Optional[Any]       		=hidden_act
									__UpperCamelCase      :					str       		=type_sequence_label_size
									__UpperCamelCase      :					List[str]       		=initializer_range
									__UpperCamelCase      :					Tuple       		=out_features
									__UpperCamelCase      :					List[Any]       		=num_labels
									__UpperCamelCase      :					List[Any]       		=scope
									__UpperCamelCase      :					Optional[int]       		=num_stages


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					List[str]       		=floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]    )

									__UpperCamelCase      :					str       		=None
									if self.use_labels:
														__UpperCamelCase      :					Dict       		=ids_tensor([self.batch_size]							,  self.type_sequence_label_size    )

									__UpperCamelCase      :					str       		=self.get_config()

									return config, pixel_values, labels


				def       __lowercase							( self    ):




									"""simple docstring"""

									return ConvNextConfig(
									    num_channels=self.num_channels							,  num_stages=self.num_stages							,  hidden_sizes=self.hidden_sizes							,  depths=self.depths							,  is_training=self.is_training							,  intermediate_size=self.intermediate_size							,  hidden_act=self.hidden_act							,  out_features=self.out_features							,  )


				def       __lowercase							( self    ):




									"""simple docstring"""

									return UperNetConfig(
									    backbone_config=self.get_backbone_config()							,  hidden_size=512							,  pool_scales=[1, 2, 3, 6]							,  use_auxiliary_head=lowerCamelCase__							,  auxiliary_loss_weight=0.4							,  auxiliary_in_channels=40							,  auxiliary_channels=256							,  auxiliary_num_convs=1							,  auxiliary_concat_input=lowerCamelCase__							,  loss_ignore_index=255							,  num_labels=self.num_labels							,  )


				def       __lowercase							( self							,  lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    ):




									"""simple docstring"""

									__UpperCamelCase      :					str       		=UperNetForSemanticSegmentation(config=lowerCamelCase__    )
									model.to(lowerCamelCase__    )
									model.eval()
									__UpperCamelCase      :					Tuple       		=model(lowerCamelCase__    )
									self.parent.assertEqual(
									    result.logits.shape							,  (self.batch_size, self.num_labels, self.image_size, self.image_size)    )







				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Tuple       		=self.prepare_config_and_inputs()
									(
									    (
									    __UpperCamelCase    
									)		,				(
									    __UpperCamelCase    
									)		,				(
									    __UpperCamelCase    
									)		,				    
									)      :					List[Any]       		=config_and_inputs
									__UpperCamelCase      :					Dict       		={'pixel_values': pixel_values}
									return config, inputs_dict




@require_torch
class 				__A     (			snake_case_      ,     snake_case_      ,     unittest.TestCase ):





				"""simple docstring"""







				UpperCamelCase__ :      str			 =(UperNetForSemanticSegmentation,) if is_torch_available() else ()
				UpperCamelCase__ :      Dict			 ={"""image-segmentation""": UperNetForSemanticSegmentation} if is_torch_available() else {}
				UpperCamelCase__ :      int			 =False
				UpperCamelCase__ :      List[str]			 =False
				UpperCamelCase__ :      Union[str, Any]			 =False
				UpperCamelCase__ :      str			 =False
				UpperCamelCase__ :      List[Any]			 =False
				UpperCamelCase__ :      Optional[Any]			 =False


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					List[Any]       		=UperNetModelTester(self    )
									__UpperCamelCase      :					Tuple       		=ConfigTester(self							,  config_class=lowerCamelCase__							,  has_text_modality=lowerCamelCase__							,  hidden_size=37    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									self.create_and_test_config_common_properties()
									self.config_tester.create_and_test_config_to_json_string()
									self.config_tester.create_and_test_config_to_json_file()
									self.config_tester.create_and_test_config_from_and_save_pretrained()
									self.config_tester.create_and_test_config_with_num_labels()
									self.config_tester.check_config_can_be_init_without_params()
									self.config_tester.check_config_arguments_init()


				def       __lowercase							( self    ):




									"""simple docstring"""

									return


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase		,				__UpperCamelCase      :					Union[str, Any]       		=self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
														__UpperCamelCase      :					List[Any]       		=model_class(lowerCamelCase__    )
														__UpperCamelCase      :					List[str]       		=inspect.signature(model.forward    )
														# signature.parameters is an OrderedDict => so arg_names order is deterministic
														__UpperCamelCase      :					Dict       		=[*signature.parameters.keys()]

														__UpperCamelCase      :					int       		=['pixel_values']
														self.assertListEqual(arg_names[:1]							,  lowerCamelCase__    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					Dict       		=self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_semantic_segmentation(*lowerCamelCase__    )


				@unittest.skip(reason='UperNet does not use inputs_embeds'    )
				def       __lowercase							( self    ):




									"""simple docstring"""

									pass


				@unittest.skip(reason='UperNet does not support input and output embeddings'    )
				def       __lowercase							( self    ):




									"""simple docstring"""

									pass


				@unittest.skip(reason='UperNet does not have a base model'    )
				def       __lowercase							( self    ):




									"""simple docstring"""

									pass


				@unittest.skip(reason='UperNet does not have a base model'    )
				def       __lowercase							( self    ):




									"""simple docstring"""

									pass


				@require_torch_multi_gpu
				@unittest.skip(reason='UperNet has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'    )
				def       __lowercase							( self    ):




									"""simple docstring"""

									pass


				@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'    )
				def       __lowercase							( self    ):




									"""simple docstring"""

									pass


				def       __lowercase							( self    ):




									"""simple docstring"""

									def check_hidden_states_output(lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    ):
														__UpperCamelCase      :					Optional[int]       		=model_class(lowerCamelCase__    )
														model.to(lowerCamelCase__    )
														model.eval()

														with torch.no_grad():
																			__UpperCamelCase      :					str       		=model(**self._prepare_for_class(lowerCamelCase__							,  lowerCamelCase__    )    )

														__UpperCamelCase      :					Optional[int]       		=outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

														__UpperCamelCase      :					Any       		=self.model_tester.num_stages
														self.assertEqual(len(lowerCamelCase__    )							,  expected_num_stages + 1    )

														# ConvNext's feature maps are of shape (batch_size, num_channels, height, width)
														self.assertListEqual(
														    list(hidden_states[0].shape[-2:]    )							,  [self.model_tester.image_size // 4, self.model_tester.image_size // 4]							,  )

									__UpperCamelCase		,				__UpperCamelCase      :					Union[str, Any]       		=self.model_tester.prepare_config_and_inputs_for_common()

									for model_class in self.all_model_classes:
														__UpperCamelCase      :					Dict       		=True
														check_hidden_states_output(lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    )

														# check that output_hidden_states also work using config
														del inputs_dict["output_hidden_states"]
														__UpperCamelCase      :					List[str]       		=True

														check_hidden_states_output(lowerCamelCase__							,  lowerCamelCase__							,  lowerCamelCase__    )


				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase		,				__UpperCamelCase      :					Tuple       		=self.model_tester.prepare_config_and_inputs_for_common()

									__UpperCamelCase      :					Union[str, Any]       		=_config_zero_init(lowerCamelCase__    )
									__UpperCamelCase      :					Optional[int]       		=_config_zero_init(configs_no_init.backbone_config    )
									for model_class in self.all_model_classes:
														__UpperCamelCase      :					str       		=model_class(config=lowerCamelCase__    )
														for name, param in model.named_parameters():
																			if param.requires_grad:
																								self.assertIn(
																								    ((param.data.mean() * 1E9).round() / 1E9).item()							,  [0.0, 1.0]							,  msg=f'Parameter {name} of model {model_class} seems not properly initialized'							,  )


				@unittest.skip(reason='UperNet does not have tied weights'    )
				def       __lowercase							( self    ):




									"""simple docstring"""

									pass







				@slow
				def       __lowercase							( self    ):




									"""simple docstring"""

									for model_name in UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														__UpperCamelCase      :					Optional[int]       		=UperNetForSemanticSegmentation.from_pretrained(lowerCamelCase__    )
														self.assertIsNotNone(lowerCamelCase__    )






def 							A     (       )     ->						Dict:
					__UpperCamelCase      :					Optional[int]       		=hf_hub_download(
					    repo_id='hf-internal-testing/fixtures_ade20k'							,repo_type='dataset'							,filename='ADE_val_00000001.jpg'					)
					__UpperCamelCase      :					Optional[int]       		=Image.open(lowerCamelCase__					).convert('RGB'					)
					return image




@require_torch
@require_vision
@slow
class 				__A     (			unittest.TestCase ):





				"""simple docstring"""







				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					str       		=AutoImageProcessor.from_pretrained('openmmlab/upernet-swin-tiny'    )
									__UpperCamelCase      :					Union[str, Any]       		=UperNetForSemanticSegmentation.from_pretrained('openmmlab/upernet-swin-tiny'    ).to(lowerCamelCase__    )

									__UpperCamelCase      :					Union[str, Any]       		=prepare_img()
									__UpperCamelCase      :					Tuple       		=processor(images=lowerCamelCase__							,  return_tensors='pt'    ).to(lowerCamelCase__    )

									with torch.no_grad():
														__UpperCamelCase      :					List[Any]       		=model(**lowerCamelCase__    )

									__UpperCamelCase      :					List[Any]       		=torch.Size((1, model.config.num_labels, 512, 512)    )
									self.assertEqual(outputs.logits.shape							,  lowerCamelCase__    )

									__UpperCamelCase      :					List[Any]       		=torch.tensor(
									    [[-7.5_958, -7.5_958, -7.4_302], [-7.5_958, -7.5_958, -7.4_302], [-7.4_797, -7.4_797, -7.3_068]]    ).to(lowerCamelCase__    )
									self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3]							,  lowerCamelCase__							,  atol=1E-4    )    )







				def       __lowercase							( self    ):




									"""simple docstring"""

									__UpperCamelCase      :					int       		=AutoImageProcessor.from_pretrained('openmmlab/upernet-convnext-tiny'    )
									__UpperCamelCase      :					int       		=UperNetForSemanticSegmentation.from_pretrained('openmmlab/upernet-convnext-tiny'    ).to(lowerCamelCase__    )

									__UpperCamelCase      :					Dict       		=prepare_img()
									__UpperCamelCase      :					Union[str, Any]       		=processor(images=lowerCamelCase__							,  return_tensors='pt'    ).to(lowerCamelCase__    )

									with torch.no_grad():
														__UpperCamelCase      :					Any       		=model(**lowerCamelCase__    )

									__UpperCamelCase      :					Optional[Any]       		=torch.Size((1, model.config.num_labels, 512, 512)    )
									self.assertEqual(outputs.logits.shape							,  lowerCamelCase__    )

									__UpperCamelCase      :					List[str]       		=torch.tensor(
									    [[-8.8_110, -8.8_110, -8.6_521], [-8.8_110, -8.8_110, -8.6_521], [-8.7_746, -8.7_746, -8.6_130]]    ).to(lowerCamelCase__    )
									self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3]							,  lowerCamelCase__							,  atol=1E-4    )    )



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



	def __init__(    self						,  lowercase						,  lowercase=13						,  lowercase=7						,  lowercase=True						,  lowercase=True						,  lowercase=True						,  lowercase=99						,  lowercase=32						,  lowercase=5						,  lowercase=4						,  lowercase=37						,  lowercase="gelu"						,  lowercase=0.1						,  lowercase=0.1						,  lowercase=512						,  lowercase=16						,  lowercase=2						,  lowercase=0.0_2						,  lowercase=3						,  lowercase=4						,  lowercase=None						,  )				->       List[str]:
					lowerCamelCase_						=			parent
					lowerCamelCase_						=			batch_size
					lowerCamelCase_						=			seq_length
					lowerCamelCase_						=			is_training
					lowerCamelCase_						=			use_token_type_ids
					lowerCamelCase_						=			use_labels
					lowerCamelCase_						=			vocab_size
					lowerCamelCase_						=			hidden_size
					lowerCamelCase_						=			num_hidden_layers
					lowerCamelCase_						=			num_attention_heads
					lowerCamelCase_						=			intermediate_size
					lowerCamelCase_						=			hidden_act
					lowerCamelCase_						=			hidden_dropout_prob
					lowerCamelCase_						=			attention_probs_dropout_prob
					lowerCamelCase_						=			max_position_embeddings
					lowerCamelCase_						=			type_vocab_size
					lowerCamelCase_						=			type_sequence_label_size
					lowerCamelCase_						=			initializer_range
					lowerCamelCase_						=			num_labels
					lowerCamelCase_						=			num_choices
					lowerCamelCase_						=			scope
					lowerCamelCase_						=			self.vocab_size - 1



	def     SCREAMING_SNAKE_CASE_(    self )				->       Any:
					lowerCamelCase_						=			ids_tensor([self.batch_size, self.seq_length]						,  self.vocab_size )

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

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

					lowerCamelCase_						=			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						,  )

					lowerCamelCase_						=			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     SCREAMING_SNAKE_CASE_(    self						,  lowercase						,  lowercase						,  lowercase						,  lowercase						,  *lowercase )				->       Dict:
					lowerCamelCase_						=			OpenAIGPTModel(config=lowercase )
					model.to(lowercase )
					model.eval()

					lowerCamelCase_						=			model(lowercase						,  token_type_ids=lowercase						,  head_mask=lowercase )
					lowerCamelCase_						=			model(lowercase						,  token_type_ids=lowercase )
					lowerCamelCase_						=			model(lowercase )

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



	def     SCREAMING_SNAKE_CASE_(    self						,  lowercase						,  lowercase						,  lowercase						,  lowercase						,  *lowercase )				->       int:
					lowerCamelCase_						=			OpenAIGPTLMHeadModel(lowercase )
					model.to(lowercase )
					model.eval()

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



	def     SCREAMING_SNAKE_CASE_(    self						,  lowercase						,  lowercase						,  lowercase						,  lowercase						,  *lowercase )				->       Dict:
					lowerCamelCase_						=			OpenAIGPTDoubleHeadsModel(lowercase )
					model.to(lowercase )
					model.eval()

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



	def     SCREAMING_SNAKE_CASE_(    self						,  lowercase						,  lowercase						,  lowercase						,  lowercase						,  *lowercase )				->       int:
					lowerCamelCase_						=			self.num_labels
					lowerCamelCase_						=			OpenAIGPTForSequenceClassification(lowercase )
					model.to(lowercase )
					model.eval()

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



	def     SCREAMING_SNAKE_CASE_(    self )				->       Union[str, Any]:
					lowerCamelCase_						=			self.prepare_config_and_inputs()
					(
					    (
					    lowerCamelCase_
					)	,    (
					    lowerCamelCase_
					)	,    (
					    lowerCamelCase_
					)	,    (
					    lowerCamelCase_
					)	,    (
					    lowerCamelCase_
					)	,    (
					    lowerCamelCase_
					)	,    (
					    lowerCamelCase_
					)	,    
					)						=			config_and_inputs
					lowerCamelCase_						=			{
					    "input_ids": input_ids,
					    "token_type_ids": token_type_ids,
					    "head_mask": head_mask,
					}

					return config, inputs_dict




@require_torch
class     _SCREAMING_SNAKE_CASE     (      snake_case_			,       snake_case_			,       snake_case_			,       unittest.TestCase						):
	lowerCAmelCase__         = (
	    (OpenAIGPTModel, OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel, OpenAIGPTForSequenceClassification)
	    if is_torch_available()
	    else ()
	)
	lowerCAmelCase__         = (
	    (OpenAIGPTLMHeadModel,) if is_torch_available() else ()
	)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
	lowerCAmelCase__         = (
	    {
	        'feature-extraction': OpenAIGPTModel,
	        'text-classification': OpenAIGPTForSequenceClassification,
	        'text-generation': OpenAIGPTLMHeadModel,
	        'zero-shot': OpenAIGPTForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)



	def     SCREAMING_SNAKE_CASE_(    self						,  lowercase						,  lowercase						,  lowercase						,  lowercase						,  lowercase )				->       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     SCREAMING_SNAKE_CASE_(    self						,  lowercase						,  lowercase						,  lowercase=False )				->       Any:
					lowerCamelCase_						=			super()._prepare_for_class(lowercase						,  lowercase						,  return_labels=lowercase )

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



	def     SCREAMING_SNAKE_CASE_(    self )				->       Dict:
					lowerCamelCase_						=			OpenAIGPTModelTester(self )
					lowerCamelCase_						=			ConfigTester(self						,  config_class=lowercase						,  n_embd=37 )



	def     SCREAMING_SNAKE_CASE_(    self )				->       Any:
					self.config_tester.run_common_tests()



	def     SCREAMING_SNAKE_CASE_(    self )				->       Union[str, Any]:
					lowerCamelCase_						=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_openai_gpt_model(*lowercase )



	def     SCREAMING_SNAKE_CASE_(    self )				->       str:
					lowerCamelCase_						=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_lm_head_model(*lowercase )



	def     SCREAMING_SNAKE_CASE_(    self )				->       Tuple:
					lowerCamelCase_						=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_double_lm_head_model(*lowercase )



	def     SCREAMING_SNAKE_CASE_(    self )				->       Optional[Any]:
					lowerCamelCase_						=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*lowercase )



	@slow
	def     SCREAMING_SNAKE_CASE_(    self )				->       Any:
					for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									lowerCamelCase_						=			OpenAIGPTModel.from_pretrained(lowercase )
									self.assertIsNotNone(lowercase )




@require_torch
class     _SCREAMING_SNAKE_CASE     (      unittest.TestCase						):



	@slow
	def     SCREAMING_SNAKE_CASE_(    self )				->       str:
					lowerCamelCase_						=			OpenAIGPTLMHeadModel.from_pretrained("openai-gpt" )
					model.to(lowercase )
					lowerCamelCase_						=			torch.tensor([[481, 4735, 544]]						,  dtype=torch.long						,  device=lowercase )  # the president is
					lowerCamelCase_						=			[
					    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

					lowerCamelCase_						=			model.generate(lowercase						,  do_sample=lowercase )
					self.assertListEqual(output_ids[0].tolist()						,  lowercase )


