

"""simple docstring"""


import inspect
import unittest

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

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


if is_torch_available():
			import torch
			from torch import nn

			from transformers import ResNetBackbone, ResNetForImageClassification, ResNetModel
			from transformers.models.resnet.modeling_resnet import RESNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
			from PIL import Image

			from transformers import AutoImageProcessor





class 					snake_case			:

				def __init__(			self							:       Any  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       Optional[Any]=3  ,						UpperCamelCase__							:       Optional[Any]=3_2  ,						UpperCamelCase__							:       int=3  ,						UpperCamelCase__							:       Tuple=1_0  ,						UpperCamelCase__							:       Optional[Any]=[1_0, 2_0, 3_0, 4_0]  ,						UpperCamelCase__							:       List[Any]=[1, 1, 2, 1]  ,						UpperCamelCase__							:       List[str]=True  ,						UpperCamelCase__							:       Union[str, Any]=True  ,						UpperCamelCase__							:       str="relu"  ,						UpperCamelCase__							:       List[Any]=3  ,						UpperCamelCase__							:       str=None  ,						UpperCamelCase__							:       Optional[Any]=["stage2", "stage3", "stage4"]  ,						UpperCamelCase__							:       Union[str, Any]=[2, 3, 4]  ,						)->     Union[str, Any]:



						'''simple docstring'''


						__lowerCAmelCase: int					   =    parent
						__lowerCAmelCase: List[str]					   =    batch_size
						__lowerCAmelCase: Dict					   =    image_size
						__lowerCAmelCase: List[Any]					   =    num_channels
						__lowerCAmelCase: Optional[int]					   =    embeddings_size
						__lowerCAmelCase: Union[str, Any]					   =    hidden_sizes
						__lowerCAmelCase: Dict					   =    depths
						__lowerCAmelCase: Optional[Any]					   =    is_training
						__lowerCAmelCase: Optional[Any]					   =    use_labels
						__lowerCAmelCase: List[str]					   =    hidden_act
						__lowerCAmelCase: Tuple					   =    num_labels
						__lowerCAmelCase: str					   =    scope
						__lowerCAmelCase: Optional[int]					   =    len(a_)
						__lowerCAmelCase: str					   =    out_features
						__lowerCAmelCase: Union[str, Any]					   =    out_indices

				def 							lowercase_  (			self							:       Dict)->     Optional[int]:



						'''simple docstring'''


						__lowerCAmelCase: Any					   =    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

						__lowerCAmelCase: List[Any]					   =    None
						if self.use_labels:
								__lowerCAmelCase: List[Any]					   =    ids_tensor([self.batch_size]  ,						self.num_labels)

						__lowerCAmelCase: Dict					   =    self.get_config()

						return config, pixel_values, labels

				def 							lowercase_  (			self							:       Optional[Any])->     Optional[Any]:



						'''simple docstring'''


						return ResNetConfig(
						    num_channels=self.num_channels  ,						embeddings_size=self.embeddings_size  ,						hidden_sizes=self.hidden_sizes  ,						depths=self.depths  ,						hidden_act=self.hidden_act  ,						num_labels=self.num_labels  ,						out_features=self.out_features  ,						out_indices=self.out_indices  ,						)

				def 							lowercase_  (			self							:       Union[str, Any]  ,						UpperCamelCase__							:       Tuple  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       str)->     Optional[Any]:



						'''simple docstring'''


						__lowerCAmelCase: List[str]					   =    ResNetModel(config=a_)
						model.to(a_)
						model.eval()
						__lowerCAmelCase: int					   =    model(a_)
						# expected last hidden states: B, C, H // 32, W // 32
						self.parent.assertEqual(
						    result.last_hidden_state.shape  ,						(self.batch_size, self.hidden_sizes[-1], self.image_size // 3_2, self.image_size // 3_2)  ,						)

				def 							lowercase_  (			self							:       Optional[int]  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       str  ,						UpperCamelCase__							:       int)->     Any:



						'''simple docstring'''


						__lowerCAmelCase: Optional[int]					   =    self.num_labels
						__lowerCAmelCase: int					   =    ResNetForImageClassification(a_)
						model.to(a_)
						model.eval()
						__lowerCAmelCase: Tuple					   =    model(a_  ,						labels=a_)
						self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.num_labels))

				def 							lowercase_  (			self							:       List[Any]  ,						UpperCamelCase__							:       Dict  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       Any)->     Any:



						'''simple docstring'''


						__lowerCAmelCase: Dict					   =    ResNetBackbone(config=a_)
						model.to(a_)
						model.eval()
						__lowerCAmelCase: Any					   =    model(a_)

						# verify feature maps
						self.parent.assertEqual(len(result.feature_maps)  ,						len(config.out_features))
						self.parent.assertListEqual(list(result.feature_maps[0].shape)  ,						[self.batch_size, self.hidden_sizes[1], 4, 4])

						# verify channels
						self.parent.assertEqual(len(model.channels)  ,						len(config.out_features))
						self.parent.assertListEqual(model.channels  ,						config.hidden_sizes[1:])

						# verify backbone works with out_features=None
						__lowerCAmelCase: Any					   =    None
						__lowerCAmelCase: Tuple					   =    ResNetBackbone(config=a_)
						model.to(a_)
						model.eval()
						__lowerCAmelCase: int					   =    model(a_)

						# verify feature maps
						self.parent.assertEqual(len(result.feature_maps)  ,						1)
						self.parent.assertListEqual(list(result.feature_maps[0].shape)  ,						[self.batch_size, self.hidden_sizes[-1], 1, 1])

						# verify channels
						self.parent.assertEqual(len(model.channels)  ,						1)
						self.parent.assertListEqual(model.channels  ,						[config.hidden_sizes[-1]])




				def 							lowercase_  (			self							:       int)->     Tuple:



						'''simple docstring'''


						__lowerCAmelCase: Optional[Any]					   =    self.prepare_config_and_inputs()
						__lowerCAmelCase   ,				__lowerCAmelCase   ,				__lowerCAmelCase: List[str]					   =    config_and_inputs
						__lowerCAmelCase: str					   =    {"pixel_values": pixel_values}
						return config, inputs_dict





@require_torch
class 					snake_case			(       __snake_case,							__snake_case,							unittest.TestCase						):
				SCREAMING_SNAKE_CASE_     :   Any        =						(
				    (
				        ResNetModel,
				        ResNetForImageClassification,
				        ResNetBackbone,
				    )
				    if is_torch_available()
				    else ()
				)
				SCREAMING_SNAKE_CASE_     :   List[str]        =						(
				    {'''feature-extraction''': ResNetModel, '''image-classification''': ResNetForImageClassification}
				    if is_torch_available()
				    else {}
				)

				SCREAMING_SNAKE_CASE_     :   Any        =						True
				SCREAMING_SNAKE_CASE_     :   str        =						False
				SCREAMING_SNAKE_CASE_     :   List[Any]        =						False
				SCREAMING_SNAKE_CASE_     :   Optional[Any]        =						False
				SCREAMING_SNAKE_CASE_     :   Tuple        =						False

				def 							lowercase_  (			self							:       Tuple)->     int:



						'''simple docstring'''


						__lowerCAmelCase: str					   =    ResNetModelTester(self)
						__lowerCAmelCase: int					   =    ConfigTester(self  ,						config_class=a_  ,						has_text_modality=a_)

				def 							lowercase_  (			self							:       List[str])->     str:



						'''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							:       List[Any])->     Optional[int]:



						'''simple docstring'''


						return

				@unittest.skip(reason="ResNet does not use inputs_embeds")
				def 							lowercase_  (			self							:       List[str])->     Dict:



						'''simple docstring'''


						pass

				@unittest.skip(reason="ResNet does not support input and output embeddings")
				def 							lowercase_  (			self							:       Any)->     List[Any]:



						'''simple docstring'''


						pass

				def 							lowercase_  (			self							:       int)->     Optional[int]:



						'''simple docstring'''


						__lowerCAmelCase   ,				__lowerCAmelCase: List[str]					   =    self.model_tester.prepare_config_and_inputs_for_common()

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

								__lowerCAmelCase: List[Any]					   =    ["pixel_values"]
								self.assertListEqual(arg_names[:1]  ,						a_)

				def 							lowercase_  (			self							:       List[str])->     List[Any]:



						'''simple docstring'''


						__lowerCAmelCase: Optional[Any]					   =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*a_)

				def 							lowercase_  (			self							:       List[str])->     int:



						'''simple docstring'''


						__lowerCAmelCase: str					   =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_backbone(*a_)

				def 							lowercase_  (			self							:       str)->     List[Any]:



						'''simple docstring'''


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

						for model_class in self.all_model_classes:
								__lowerCAmelCase: Optional[Any]					   =    model_class(config=a_)
								for name, module in model.named_modules():
										if isinstance(a_  ,						(nn.BatchNormad, nn.GroupNorm)):
												self.assertTrue(
												    torch.all(module.weight == 1)  ,						msg=f"Parameter {name} of model {model_class} seems not properly initialized"  ,						)
												self.assertTrue(
												    torch.all(module.bias == 0)  ,						msg=f"Parameter {name} of model {model_class} seems not properly initialized"  ,						)

				def 							lowercase_  (			self							:       List[Any])->     Optional[Any]:



						'''simple docstring'''


						def check_hidden_states_output(UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       List[str]):
								__lowerCAmelCase: Optional[Any]					   =    model_class(a_)
								model.to(a_)
								model.eval()

								with torch.no_grad():
										__lowerCAmelCase: Optional[Any]					   =    model(**self._prepare_for_class(a_  ,						a_))

								__lowerCAmelCase: Union[str, Any]					   =    outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

								__lowerCAmelCase: List[Any]					   =    self.model_tester.num_stages
								self.assertEqual(len(a_)  ,						expected_num_stages + 1)

								# ResNet'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]  ,						)

						__lowerCAmelCase   ,				__lowerCAmelCase: Union[str, Any]					   =    self.model_tester.prepare_config_and_inputs_for_common()
						__lowerCAmelCase: List[str]					   =    ["basic", "bottleneck"]
						for model_class in self.all_model_classes:
								for layer_type in layers_type:
										__lowerCAmelCase: List[str]					   =    layer_type
										__lowerCAmelCase: int					   =    True
										check_hidden_states_output(a_  ,						a_  ,						a_)

										# check that output_hidden_states also work using config
										del inputs_dict["output_hidden_states"]
										__lowerCAmelCase: Any					   =    True

										check_hidden_states_output(a_  ,						a_  ,						a_)

				@unittest.skip(reason="ResNet does not use feedforward chunking")
				def 							lowercase_  (			self							:       Optional[int])->     List[str]:



						'''simple docstring'''


						pass

				def 							lowercase_  (			self							:       List[Any])->     List[Any]:



						'''simple docstring'''


						__lowerCAmelCase: Dict					   =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_image_classification(*a_)




				@slow
				def 							lowercase_  (			self							:       List[Any])->     int:



						'''simple docstring'''


						for model_name in RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								__lowerCAmelCase: Any					   =    ResNetModel.from_pretrained(a_)
								self.assertIsNotNone(a_)






def 					a__					(					):
		__lowerCAmelCase: Dict					   =    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"				)
		return image





@require_torch
@require_vision
class 					snake_case			(       unittest.TestCase						):

				@cached_property
				def 							lowercase_  (			self							:       Optional[Any])->     str:



						'''simple docstring'''


						return (
						    AutoImageProcessor.from_pretrained(RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0])
						    if is_vision_available()
						    else None
						)




				@slow
				def 							lowercase_  (			self							:       str)->     Tuple:



						'''simple docstring'''


						__lowerCAmelCase: List[str]					   =    ResNetForImageClassification.from_pretrained(RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]).to(a_)

						__lowerCAmelCase: List[Any]					   =    self.default_image_processor
						__lowerCAmelCase: Any					   =    prepare_img()
						__lowerCAmelCase: Optional[int]					   =    image_processor(images=a_  ,						return_tensors="pt").to(a_)

						# forward pass
						with torch.no_grad():
								__lowerCAmelCase: Union[str, Any]					   =    model(**a_)

						# verify the logits
						__lowerCAmelCase: Optional[int]					   =    torch.Size((1, 1_0_0_0))
						self.assertEqual(outputs.logits.shape  ,						a_)

						__lowerCAmelCase: Optional[Any]					   =    torch.tensor([-11.1069, -9.7877, -8.3777]).to(a_)

						self.assertTrue(torch.allclose(outputs.logits[0, :3]  ,						a_  ,						atol=1e-4))





@require_torch
class 					snake_case			(       __snake_case,							unittest.TestCase						):
				SCREAMING_SNAKE_CASE_     :   Union[str, Any]        =						(ResNetBackbone,) if is_torch_available() else ()
				SCREAMING_SNAKE_CASE_     :   int        =						False
				SCREAMING_SNAKE_CASE_     :   str        =						ResNetConfig

				def 							lowercase_  (			self							:       List[Any])->     List[Any]:



						'''simple docstring'''


						__lowerCAmelCase: List[str]					   =    ResNetModelTester(self)





"""simple docstring"""


from __future__ import annotations

import unittest

from transformers import OpenAIGPTConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
			import tensorflow as tf

			from transformers.models.openai.modeling_tf_openai import (
			    TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
			    TFOpenAIGPTDoubleHeadsModel,
			    TFOpenAIGPTForSequenceClassification,
			    TFOpenAIGPTLMHeadModel,
			    TFOpenAIGPTModel,
			)





class 					snake_case			:

				def __init__(			self							:       str  ,						UpperCamelCase__							:       Optional[int]  ,						)->     Optional[Any]:



						'''simple docstring'''


						__lowerCAmelCase: str					   =    parent
						__lowerCAmelCase: Union[str, Any]					   =    1_3
						__lowerCAmelCase: Union[str, Any]					   =    7
						__lowerCAmelCase: List[Any]					   =    True
						__lowerCAmelCase: Any					   =    True
						__lowerCAmelCase: List[Any]					   =    True
						__lowerCAmelCase: str					   =    True
						__lowerCAmelCase: List[Any]					   =    True
						__lowerCAmelCase: Tuple					   =    9_9
						__lowerCAmelCase: Dict					   =    3_2
						__lowerCAmelCase: Optional[Any]					   =    2
						__lowerCAmelCase: Union[str, Any]					   =    4
						__lowerCAmelCase: Union[str, Any]					   =    3_7
						__lowerCAmelCase: List[str]					   =    "gelu"
						__lowerCAmelCase: List[str]					   =    0.1
						__lowerCAmelCase: List[str]					   =    0.1
						__lowerCAmelCase: Union[str, Any]					   =    5_1_2
						__lowerCAmelCase: int					   =    1_6
						__lowerCAmelCase: int					   =    2
						__lowerCAmelCase: str					   =    0.02
						__lowerCAmelCase: Union[str, Any]					   =    3
						__lowerCAmelCase: str					   =    4
						__lowerCAmelCase: List[Any]					   =    None
						__lowerCAmelCase: int					   =    self.vocab_size - 1

				def 							lowercase_  (			self							:       Union[str, Any])->     Optional[Any]:



						'''simple docstring'''


						__lowerCAmelCase: Any					   =    ids_tensor([self.batch_size, self.seq_length]  ,						self.vocab_size)

						__lowerCAmelCase: str					   =    None
						if self.use_input_mask:
								__lowerCAmelCase: List[Any]					   =    random_attention_mask([self.batch_size, self.seq_length])

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

						__lowerCAmelCase: Dict					   =    None
						if self.use_mc_token_ids:
								__lowerCAmelCase: Union[str, Any]					   =    ids_tensor([self.batch_size, self.num_choices]  ,						self.seq_length)

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

						__lowerCAmelCase: int					   =    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: Union[str, Any]					   =    ids_tensor([self.num_hidden_layers, self.num_attention_heads]  ,						2)

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

				def 							lowercase_  (			self							:       Optional[int]  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       Any  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       Dict  ,						*UpperCamelCase__							:       Dict)->     Union[str, Any]:



						'''simple docstring'''


						__lowerCAmelCase: List[str]					   =    TFOpenAIGPTModel(config=UpperCamelCase__)
						__lowerCAmelCase: Tuple					   =    {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
						__lowerCAmelCase: List[Any]					   =    model(UpperCamelCase__)

						__lowerCAmelCase: List[Any]					   =    [input_ids, input_mask]
						__lowerCAmelCase: Tuple					   =    model(UpperCamelCase__)

						__lowerCAmelCase: List[Any]					   =    model(UpperCamelCase__)

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

				def 							lowercase_  (			self							:       Dict  ,						UpperCamelCase__							:       List[str]  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       int  ,						*UpperCamelCase__							:       Optional[Any])->     Union[str, Any]:



						'''simple docstring'''


						__lowerCAmelCase: Any					   =    TFOpenAIGPTLMHeadModel(config=UpperCamelCase__)
						__lowerCAmelCase: int					   =    {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
						__lowerCAmelCase: Any					   =    model(UpperCamelCase__)
						self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.seq_length, self.vocab_size))

				def 							lowercase_  (			self							:       Tuple  ,						UpperCamelCase__							:       str  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       Tuple  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       List[str]  ,						UpperCamelCase__							:       Optional[Any]  ,						*UpperCamelCase__							:       Optional[Any])->     Optional[int]:



						'''simple docstring'''


						__lowerCAmelCase: Union[str, Any]					   =    TFOpenAIGPTDoubleHeadsModel(config=UpperCamelCase__)

						__lowerCAmelCase: List[str]					   =    tf.tile(tf.expand_dims(UpperCamelCase__  ,						1)  ,						(1, self.num_choices, 1))
						__lowerCAmelCase: Union[str, Any]					   =    tf.tile(tf.expand_dims(UpperCamelCase__  ,						1)  ,						(1, self.num_choices, 1))
						__lowerCAmelCase: Optional[Any]					   =    tf.tile(tf.expand_dims(UpperCamelCase__  ,						1)  ,						(1, self.num_choices, 1))

						__lowerCAmelCase: str					   =    {
						    "input_ids": multiple_choice_inputs_ids,
						    "mc_token_ids": mc_token_ids,
						    "attention_mask": multiple_choice_input_mask,
						    "token_type_ids": multiple_choice_token_type_ids,
						}
						__lowerCAmelCase: Optional[int]					   =    model(UpperCamelCase__)
						self.parent.assertEqual(
						    result.logits.shape  ,						(self.batch_size, self.num_choices, self.seq_length, self.vocab_size))
						self.parent.assertEqual(result.mc_logits.shape  ,						(self.batch_size, self.num_choices))

				def 							lowercase_  (			self							:       List[str]  ,						UpperCamelCase__							:       List[Any]  ,						UpperCamelCase__							:       Optional[Any]  ,						UpperCamelCase__							:       Any  ,						UpperCamelCase__							:       str  ,						UpperCamelCase__							:       Optional[Any]  ,						*UpperCamelCase__							:       List[str])->     Any:



						'''simple docstring'''


						__lowerCAmelCase: str					   =    self.num_labels
						__lowerCAmelCase: Dict					   =    ids_tensor([self.batch_size]  ,						self.type_sequence_label_size)
						__lowerCAmelCase: List[str]					   =    {
						    "input_ids": input_ids,
						    "attention_mask": input_mask,
						    "token_type_ids": token_type_ids,
						    "labels": sequence_labels,
						}
						__lowerCAmelCase: str					   =    TFOpenAIGPTForSequenceClassification(UpperCamelCase__)
						__lowerCAmelCase: Optional[int]					   =    model(UpperCamelCase__)
						self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.num_labels))




				def 							lowercase_  (			self							:       Any)->     List[str]:



						'''simple docstring'''


						__lowerCAmelCase: List[str]					   =    self.prepare_config_and_inputs()

						(
						    (
						    __lowerCAmelCase
						)   ,				(
						    __lowerCAmelCase
						)   ,				(
						    __lowerCAmelCase
						)   ,				(
						    __lowerCAmelCase
						)   ,				(
						    __lowerCAmelCase
						)   ,				(
						    __lowerCAmelCase
						)   ,				(
						    __lowerCAmelCase
						)   ,				(
						    __lowerCAmelCase
						)   ,				(
						    __lowerCAmelCase
						)   ,				
						): List[Any]					   =    config_and_inputs

						__lowerCAmelCase: List[Any]					   =    {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
						return config, inputs_dict





@require_tf
class 					snake_case			(       __snake_case,							__snake_case,							unittest.TestCase						):
				SCREAMING_SNAKE_CASE_     :   Dict        =						(
				    (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
				    if is_tf_available()
				    else ()
				)
				SCREAMING_SNAKE_CASE_     :   List[str]        =						(
				    (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
				)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
				SCREAMING_SNAKE_CASE_     :   int        =						(
				    {
				        """feature-extraction""": TFOpenAIGPTModel,
				        """text-classification""": TFOpenAIGPTForSequenceClassification,
				        """text-generation""": TFOpenAIGPTLMHeadModel,
				        """zero-shot""": TFOpenAIGPTForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				SCREAMING_SNAKE_CASE_     :   List[Any]        =						False
				SCREAMING_SNAKE_CASE_     :   Tuple        =						False

				def 							lowercase_  (			self							:       List[str]  ,						UpperCamelCase__							:       int  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       Optional[int]  ,						UpperCamelCase__							:       Union[str, Any]  ,						UpperCamelCase__							:       Optional[Any])->     Union[str, Any]:



						'''simple docstring'''


						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							:       str)->     Tuple:



						'''simple docstring'''


						__lowerCAmelCase: Optional[int]					   =    TFOpenAIGPTModelTester(self)
						__lowerCAmelCase: List[Any]					   =    ConfigTester(self  ,						config_class=UpperCamelCase__  ,						n_embd=3_7)

				def 							lowercase_  (			self							:       List[Any])->     List[Any]:



						'''simple docstring'''


						self.config_tester.run_common_tests()

				def 							lowercase_  (			self							:       Tuple)->     Optional[int]:



						'''simple docstring'''


						__lowerCAmelCase: Optional[Any]					   =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_openai_gpt_model(*UpperCamelCase__)

				def 							lowercase_  (			self							:       Union[str, Any])->     Optional[int]:



						'''simple docstring'''


						__lowerCAmelCase: Optional[Any]					   =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_openai_gpt_lm_head(*UpperCamelCase__)

				def 							lowercase_  (			self							:       Optional[Any])->     Dict:



						'''simple docstring'''


						__lowerCAmelCase: List[Any]					   =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_openai_gpt_double_head(*UpperCamelCase__)

				def 							lowercase_  (			self							:       List[str])->     Tuple:



						'''simple docstring'''


						__lowerCAmelCase: Optional[int]					   =    self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*UpperCamelCase__)




				@slow
				def 							lowercase_  (			self							:       str)->     Dict:



						'''simple docstring'''


						for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
								__lowerCAmelCase: str					   =    TFOpenAIGPTModel.from_pretrained(UpperCamelCase__)
								self.assertIsNotNone(UpperCamelCase__)





@require_tf
class 					snake_case			(       unittest.TestCase						):

				@slow
				def 							lowercase_  (			self							:       Union[str, Any])->     List[str]:



						'''simple docstring'''


						__lowerCAmelCase: Optional[Any]					   =    TFOpenAIGPTLMHeadModel.from_pretrained("openai-gpt")
						__lowerCAmelCase: List[str]					   =    tf.convert_to_tensor([[4_8_1, 4_7_3_5, 5_4_4]]  ,						dtype=tf.intaa)  # the president is
						__lowerCAmelCase: Union[str, Any]					   =    [
						    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

						__lowerCAmelCase: str					   =    model.generate(UpperCamelCase__  ,						do_sample=UpperCamelCase__)
						self.assertListEqual(output_ids[0].numpy().tolist()  ,						UpperCamelCase__)


