
import json
import pathlib
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision, slow
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
			import torch

if is_vision_available():
			from PIL import Image

			from transformers import YolosImageProcessor




class     _SCREAMING_SNAKE_CASE     (      unittest.TestCase						):



	def __init__(    self						,  lowercase						,  lowercase=7						,  lowercase=3						,  lowercase=30						,  lowercase=400						,  lowercase=True						,  lowercase=None						,  lowercase=True						,  lowercase=[0.5, 0.5, 0.5]						,  lowercase=[0.5, 0.5, 0.5]						,  lowercase=True						,  lowercase=1 / 255						,  lowercase=True						,  )				->       Optional[int]:
					# by setting size["longest_edge"] > max_resolution we're effectively not testing this :p
					lowerCamelCase_						=			size if size is not None else {"shortest_edge": 18, "longest_edge": 1333}
					lowerCamelCase_						=			parent
					lowerCamelCase_						=			batch_size
					lowerCamelCase_						=			num_channels
					lowerCamelCase_						=			min_resolution
					lowerCamelCase_						=			max_resolution
					lowerCamelCase_						=			do_resize
					lowerCamelCase_						=			size
					lowerCamelCase_						=			do_normalize
					lowerCamelCase_						=			image_mean
					lowerCamelCase_						=			image_std
					lowerCamelCase_						=			do_rescale
					lowerCamelCase_						=			rescale_factor
					lowerCamelCase_						=			do_pad



	def     SCREAMING_SNAKE_CASE_(    self )				->       Any:
					return {
					    "do_resize": self.do_resize,
					    "size": self.size,
					    "do_normalize": self.do_normalize,
					    "image_mean": self.image_mean,
					    "image_std": self.image_std,
					    "do_rescale": self.do_rescale,
					    "rescale_factor": self.rescale_factor,
					    "do_pad": self.do_pad,
					}



	def     SCREAMING_SNAKE_CASE_(    self						,  lowercase						,  lowercase=False )				->       Optional[Any]:
					if not batched:
									lowerCamelCase_						=			image_inputs[0]
									if isinstance(lowercase						,  Image.Image ):
													lowerCamelCase_	,    lowerCamelCase_						=			image.size
									else:
													lowerCamelCase_	,    lowerCamelCase_						=			image.shape[1], image.shape[2]
									if w < h:
													lowerCamelCase_						=			int(self.size["shortest_edge"] * h / w )
													lowerCamelCase_						=			self.size["shortest_edge"]
									elif w > h:
													lowerCamelCase_						=			self.size["shortest_edge"]
													lowerCamelCase_						=			int(self.size["shortest_edge"] * w / h )
									else:
													lowerCamelCase_						=			self.size["shortest_edge"]
													lowerCamelCase_						=			self.size["shortest_edge"]

					else:
									lowerCamelCase_						=			[]
									for image in image_inputs:
													lowerCamelCase_	,    lowerCamelCase_						=			self.get_expected_values([image] )
													expected_values.append((expected_height, expected_width) )
									lowerCamelCase_						=			max(lowercase						,  key=lambda lowercase : item[0] )[0]
									lowerCamelCase_						=			max(lowercase						,  key=lambda lowercase : item[1] )[1]

					return expected_height, expected_width




@require_torch
@require_vision
class     _SCREAMING_SNAKE_CASE     (      snake_case_			,       unittest.TestCase						):
	lowerCAmelCase__         = YolosImageProcessor if is_vision_available() else None



	def     SCREAMING_SNAKE_CASE_(    self )				->       int:
					lowerCamelCase_						=			YolosImageProcessingTester(self )



	@property
	def     SCREAMING_SNAKE_CASE_(    self )				->       Any:
					return self.image_processor_tester.prepare_image_processor_dict()



	def     SCREAMING_SNAKE_CASE_(    self )				->       int:
					lowerCamelCase_						=			self.image_processing_class(**self.image_processor_dict )
					self.assertTrue(hasattr(lowercase						,  "image_mean" ) )
					self.assertTrue(hasattr(lowercase						,  "image_std" ) )
					self.assertTrue(hasattr(lowercase						,  "do_normalize" ) )
					self.assertTrue(hasattr(lowercase						,  "do_resize" ) )
					self.assertTrue(hasattr(lowercase						,  "size" ) )



	def     SCREAMING_SNAKE_CASE_(    self )				->       Optional[int]:
					lowerCamelCase_						=			self.image_processing_class.from_dict(self.image_processor_dict )
					self.assertEqual(image_processor.size						,  {"shortest_edge": 18, "longest_edge": 1333} )
					self.assertEqual(image_processor.do_pad						,  lowercase )

					lowerCamelCase_						=			self.image_processing_class.from_dict(
					    self.image_processor_dict						,  size=42						,  max_size=84						,  pad_and_return_pixel_mask=lowercase )
					self.assertEqual(image_processor.size						,  {"shortest_edge": 42, "longest_edge": 84} )
					self.assertEqual(image_processor.do_pad						,  lowercase )



	def     SCREAMING_SNAKE_CASE_(    self )				->       Optional[Any]:
					pass



	def     SCREAMING_SNAKE_CASE_(    self )				->       Union[str, Any]:
					# Initialize image_processing
					lowerCamelCase_						=			self.image_processing_class(**self.image_processor_dict )
					# create random PIL images
					lowerCamelCase_						=			prepare_image_inputs(self.image_processor_tester						,  equal_resolution=lowercase )
					for image in image_inputs:
									self.assertIsInstance(lowercase						,  Image.Image )

					# Test not batched input
					lowerCamelCase_						=			image_processing(image_inputs[0]						,  return_tensors="pt" ).pixel_values

					lowerCamelCase_	,    lowerCamelCase_						=			self.image_processor_tester.get_expected_values(lowercase )

					self.assertEqual(
					    encoded_images.shape						,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)						,  )

					# Test batched
					lowerCamelCase_	,    lowerCamelCase_						=			self.image_processor_tester.get_expected_values(lowercase						,  batched=lowercase )

					lowerCamelCase_						=			image_processing(lowercase						,  return_tensors="pt" ).pixel_values
					self.assertEqual(
					    encoded_images.shape						,  (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        expected_height,
					        expected_width,
					    )						,  )



	def     SCREAMING_SNAKE_CASE_(    self )				->       Any:
					# Initialize image_processing
					lowerCamelCase_						=			self.image_processing_class(**self.image_processor_dict )
					# create random numpy tensors
					lowerCamelCase_						=			prepare_image_inputs(self.image_processor_tester						,  equal_resolution=lowercase						,  numpify=lowercase )
					for image in image_inputs:
									self.assertIsInstance(lowercase						,  np.ndarray )

					# Test not batched input
					lowerCamelCase_						=			image_processing(image_inputs[0]						,  return_tensors="pt" ).pixel_values

					lowerCamelCase_	,    lowerCamelCase_						=			self.image_processor_tester.get_expected_values(lowercase )

					self.assertEqual(
					    encoded_images.shape						,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)						,  )

					# Test batched
					lowerCamelCase_						=			image_processing(lowercase						,  return_tensors="pt" ).pixel_values

					lowerCamelCase_	,    lowerCamelCase_						=			self.image_processor_tester.get_expected_values(lowercase						,  batched=lowercase )

					self.assertEqual(
					    encoded_images.shape						,  (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        expected_height,
					        expected_width,
					    )						,  )



	def     SCREAMING_SNAKE_CASE_(    self )				->       Dict:
					# Initialize image_processing
					lowerCamelCase_						=			self.image_processing_class(**self.image_processor_dict )
					# create random PyTorch tensors
					lowerCamelCase_						=			prepare_image_inputs(self.image_processor_tester						,  equal_resolution=lowercase						,  torchify=lowercase )
					for image in image_inputs:
									self.assertIsInstance(lowercase						,  torch.Tensor )

					# Test not batched input
					lowerCamelCase_						=			image_processing(image_inputs[0]						,  return_tensors="pt" ).pixel_values

					lowerCamelCase_	,    lowerCamelCase_						=			self.image_processor_tester.get_expected_values(lowercase )

					self.assertEqual(
					    encoded_images.shape						,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)						,  )

					# Test batched
					lowerCamelCase_						=			image_processing(lowercase						,  return_tensors="pt" ).pixel_values

					lowerCamelCase_	,    lowerCamelCase_						=			self.image_processor_tester.get_expected_values(lowercase						,  batched=lowercase )

					self.assertEqual(
					    encoded_images.shape						,  (
					        self.image_processor_tester.batch_size,
					        self.image_processor_tester.num_channels,
					        expected_height,
					        expected_width,
					    )						,  )



	def     SCREAMING_SNAKE_CASE_(    self )				->       Optional[int]:
					# Initialize image_processings
					lowerCamelCase_						=			self.image_processing_class(**self.image_processor_dict )
					lowerCamelCase_						=			self.image_processing_class(do_resize=lowercase						,  do_normalize=lowercase						,  do_rescale=lowercase )
					# create random PyTorch tensors
					lowerCamelCase_						=			prepare_image_inputs(self.image_processor_tester						,  equal_resolution=lowercase						,  torchify=lowercase )
					for image in image_inputs:
									self.assertIsInstance(lowercase						,  torch.Tensor )

					# Test whether the method "pad" and calling the image processor return the same tensors
					lowerCamelCase_						=			image_processing_a.pad(lowercase						,  return_tensors="pt" )
					lowerCamelCase_						=			image_processing_a(lowercase						,  return_tensors="pt" )

					self.assertTrue(
					    torch.allclose(encoded_images_with_method["pixel_values"]						,  encoded_images["pixel_values"]						,  atol=1e-4 ) )



	@slow
	def     SCREAMING_SNAKE_CASE_(    self )				->       int:
					# prepare image and target
					lowerCamelCase_						=			Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png" )
					with open("./tests/fixtures/tests_samples/COCO/coco_annotations.txt"						,  "r" ) as f:
									lowerCamelCase_						=			json.loads(f.read() )

					lowerCamelCase_						=			{"image_id": 39769, "annotations": target}

					# encode them
					lowerCamelCase_						=			YolosImageProcessor.from_pretrained("hustvl/yolos-small" )
					lowerCamelCase_						=			image_processing(images=lowercase						,  annotations=lowercase						,  return_tensors="pt" )

					# verify pixel values
					lowerCamelCase_						=			torch.Size([1, 3, 800, 1066] )
					self.assertEqual(encoding["pixel_values"].shape						,  lowercase )

					lowerCamelCase_						=			torch.tensor([0.2_7_9_6, 0.3_1_3_8, 0.3_4_8_1] )
					self.assertTrue(torch.allclose(encoding["pixel_values"][0, 0, 0, :3]						,  lowercase						,  atol=1e-4 ) )

					# verify area
					lowerCamelCase_						=			torch.tensor([5_8_8_7.9_6_0_0, 1_1_2_5_0.2_0_6_1, 4_8_9_3_5_3.8_4_3_8, 8_3_7_1_2_2.7_5_0_0, 1_4_7_9_6_7.5_1_5_6, 1_6_5_7_3_2.3_4_3_8] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["area"]						,  lowercase ) )
					# verify boxes
					lowerCamelCase_						=			torch.Size([6, 4] )
					self.assertEqual(encoding["labels"][0]["boxes"].shape						,  lowercase )
					lowerCamelCase_						=			torch.tensor([0.5_5_0_3, 0.2_7_6_5, 0.0_6_0_4, 0.2_2_1_5] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["boxes"][0]						,  lowercase						,  atol=1e-3 ) )
					# verify image_id
					lowerCamelCase_						=			torch.tensor([39769] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["image_id"]						,  lowercase ) )
					# verify is_crowd
					lowerCamelCase_						=			torch.tensor([0, 0, 0, 0, 0, 0] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["iscrowd"]						,  lowercase ) )
					# verify class_labels
					lowerCamelCase_						=			torch.tensor([75, 75, 63, 65, 17, 17] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["class_labels"]						,  lowercase ) )
					# verify orig_size
					lowerCamelCase_						=			torch.tensor([480, 640] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["orig_size"]						,  lowercase ) )
					# verify size
					lowerCamelCase_						=			torch.tensor([800, 1066] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["size"]						,  lowercase ) )



	@slow
	def     SCREAMING_SNAKE_CASE_(    self )				->       Optional[int]:
					# prepare image, target and masks_path
					lowerCamelCase_						=			Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png" )
					with open("./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt"						,  "r" ) as f:
									lowerCamelCase_						=			json.loads(f.read() )

					lowerCamelCase_						=			{"file_name": "000000039769.png", "image_id": 39769, "segments_info": target}

					lowerCamelCase_						=			pathlib.Path("./tests/fixtures/tests_samples/COCO/coco_panoptic" )

					# encode them
					lowerCamelCase_						=			YolosImageProcessor(format="coco_panoptic" )
					lowerCamelCase_						=			image_processing(images=lowercase						,  annotations=lowercase						,  masks_path=lowercase						,  return_tensors="pt" )

					# verify pixel values
					lowerCamelCase_						=			torch.Size([1, 3, 800, 1066] )
					self.assertEqual(encoding["pixel_values"].shape						,  lowercase )

					lowerCamelCase_						=			torch.tensor([0.2_7_9_6, 0.3_1_3_8, 0.3_4_8_1] )
					self.assertTrue(torch.allclose(encoding["pixel_values"][0, 0, 0, :3]						,  lowercase						,  atol=1e-4 ) )

					# verify area
					lowerCamelCase_						=			torch.tensor([1_4_7_9_7_9.6_8_7_5, 1_6_5_5_2_7.0_4_6_9, 4_8_4_6_3_8.5_9_3_8, 1_1_2_9_2.9_3_7_5, 5_8_7_9.6_5_6_2, 7_6_3_4.1_1_4_7] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["area"]						,  lowercase ) )
					# verify boxes
					lowerCamelCase_						=			torch.Size([6, 4] )
					self.assertEqual(encoding["labels"][0]["boxes"].shape						,  lowercase )
					lowerCamelCase_						=			torch.tensor([0.2_6_2_5, 0.5_4_3_7, 0.4_6_8_8, 0.8_6_2_5] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["boxes"][0]						,  lowercase						,  atol=1e-3 ) )
					# verify image_id
					lowerCamelCase_						=			torch.tensor([39769] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["image_id"]						,  lowercase ) )
					# verify is_crowd
					lowerCamelCase_						=			torch.tensor([0, 0, 0, 0, 0, 0] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["iscrowd"]						,  lowercase ) )
					# verify class_labels
					lowerCamelCase_						=			torch.tensor([17, 17, 63, 75, 75, 93] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["class_labels"]						,  lowercase ) )
					# verify masks
					lowerCamelCase_						=			822873
					self.assertEqual(encoding["labels"][0]["masks"].sum().item()						,  lowercase )
					# verify orig_size
					lowerCamelCase_						=			torch.tensor([480, 640] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["orig_size"]						,  lowercase ) )
					# verify size
					lowerCamelCase_						=			torch.tensor([800, 1066] )
					self.assertTrue(torch.allclose(encoding["labels"][0]["size"]						,  lowercase ) )




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 )


