





"""simple docstring"""




import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, XLMRobertaTokenizer

from diffusers import AltDiffusionPipeline, AutoencoderKL, DDIMScheduler, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.alt_diffusion.modeling_roberta_series import (
    RobertaSeriesConfig,
    RobertaSeriesModelWithTransformation,
)
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import TEXT_TO_IMAGE_BATCH_PARAMS, TEXT_TO_IMAGE_IMAGE_PARAMS, TEXT_TO_IMAGE_PARAMS
from ..test_pipelines_common import PipelineKarrasSchedulerTesterMixin, PipelineLatentTesterMixin, PipelineTesterMixin


enable_full_determinism()




class 			_a						(				_lowerCAmelCase     ,    _lowerCAmelCase     ,    _lowerCAmelCase     ,    unittest.TestCase    ):
				UpperCamelCase								=   AltDiffusionPipeline
				UpperCamelCase								=   TEXT_TO_IMAGE_PARAMS
				UpperCamelCase								=   TEXT_TO_IMAGE_BATCH_PARAMS
				UpperCamelCase								=   TEXT_TO_IMAGE_IMAGE_PARAMS
				UpperCamelCase								=   TEXT_TO_IMAGE_IMAGE_PARAMS






				def     snake_case     (			self		:   int							)     ->				int:




										'''simple docstring'''



										torch.manual_seed(0							)
										_UpperCamelCase      : Dict         =   UNetaDConditionModel(
										    block_out_channels=(3_2, 6_4),			layers_per_block=2,			sample_size=3_2,			in_channels=4,			out_channels=4,			down_block_types=('''DownBlock2D''', '''CrossAttnDownBlock2D'''),			up_block_types=('''CrossAttnUpBlock2D''', '''UpBlock2D'''),			cross_attention_dim=3_2,			)
										_UpperCamelCase      : Union[str, Any]         =   DDIMScheduler(
										    beta_start=0.00_085,			beta_end=0.012,			beta_schedule='''scaled_linear''',			clip_sample=lowerCAmelCase__,			set_alpha_to_one=lowerCAmelCase__,			)
										torch.manual_seed(0							)
										_UpperCamelCase      : List[str]         =   AutoencoderKL(
										    block_out_channels=[3_2, 6_4],			in_channels=3,			out_channels=3,			down_block_types=['''DownEncoderBlock2D''', '''DownEncoderBlock2D'''],			up_block_types=['''UpDecoderBlock2D''', '''UpDecoderBlock2D'''],			latent_channels=4,			)

										# TODO: address the non-deterministic text encoder (fails for save-load tests)
										# torch.manual_seed(0)
										# text_encoder_config = RobertaSeriesConfig(
										#     hidden_size=32,
										#     project_dim=32,
										#     intermediate_size=37,
										#     layer_norm_eps=1e-05,
										#     num_attention_heads=4,
										#     num_hidden_layers=5,
										#     vocab_size=5002,
										# )
										# text_encoder = RobertaSeriesModelWithTransformation(text_encoder_config)

										torch.manual_seed(0							)
										_UpperCamelCase      : str         =   CLIPTextConfig(
										    bos_token_id=0,			eos_token_id=2,			hidden_size=3_2,			projection_dim=3_2,			intermediate_size=3_7,			layer_norm_eps=1e-0_5,			num_attention_heads=4,			num_hidden_layers=5,			pad_token_id=1,			vocab_size=5_0_0_2,			)
										_UpperCamelCase      : List[Any]         =   CLIPTextModel(lowerCAmelCase__							)

										_UpperCamelCase      : Dict         =   XLMRobertaTokenizer.from_pretrained('''hf-internal-testing/tiny-xlm-roberta'''							)
										_UpperCamelCase      : str         =   7_7

										_UpperCamelCase      : int         =   {
										    '''unet''': unet,
										    '''scheduler''': scheduler,
										    '''vae''': vae,
										    '''text_encoder''': text_encoder,
										    '''tokenizer''': tokenizer,
										    '''safety_checker''': None,
										    '''feature_extractor''': None,
										}
										return components






				def     snake_case     (			self		:   Dict,			lowerCAmelCase__		:   Any,			lowerCAmelCase__		:   int=0							)     ->				Optional[int]:




										'''simple docstring'''



										if str(lowerCAmelCase__							).startswith('''mps'''							):
																_UpperCamelCase      : Any         =   torch.manual_seed(lowerCAmelCase__							)
										else:
																_UpperCamelCase      : Dict         =   torch.Generator(device=lowerCAmelCase__							).manual_seed(lowerCAmelCase__							)
										_UpperCamelCase      : str         =   {
										    '''prompt''': '''A painting of a squirrel eating a burger''',
										    '''generator''': generator,
										    '''num_inference_steps''': 2,
										    '''guidance_scale''': 6.0,
										    '''output_type''': '''numpy''',
										}
										return inputs






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




										'''simple docstring'''



										super().test_attention_slicing_forward_pass(expected_max_diff=3e-3							)






				def     snake_case     (			self		:   List[Any]							)     ->				Tuple:




										'''simple docstring'''



										super().test_inference_batch_single_identical(expected_max_diff=3e-3							)






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




										'''simple docstring'''



										_UpperCamelCase      : Any         =   '''cpu'''  # ensure determinism for the device-dependent torch.Generator

										_UpperCamelCase      : int         =   self.get_dummy_components()
										torch.manual_seed(0							)
										_UpperCamelCase      : Any         =   RobertaSeriesConfig(
										    hidden_size=3_2,			project_dim=3_2,			intermediate_size=3_7,			layer_norm_eps=1e-0_5,			num_attention_heads=4,			num_hidden_layers=5,			vocab_size=5_0_0_2,			)
										# TODO: remove after fixing the non-deterministic text encoder
										_UpperCamelCase      : Tuple         =   RobertaSeriesModelWithTransformation(lowerCAmelCase__							)
										_UpperCamelCase      : str         =   text_encoder

										_UpperCamelCase      : List[Any]         =   AltDiffusionPipeline(**lowerCAmelCase__							)
										_UpperCamelCase      : List[Any]         =   alt_pipe.to(lowerCAmelCase__							)
										alt_pipe.set_progress_bar_config(disable=lowerCAmelCase__							)

										_UpperCamelCase      : Optional[int]         =   self.get_dummy_inputs(lowerCAmelCase__							)
										_UpperCamelCase      : Optional[Any]         =   '''A photo of an astronaut'''
										_UpperCamelCase      : Any         =   alt_pipe(**lowerCAmelCase__							)
										_UpperCamelCase      : Any         =   output.images
										_UpperCamelCase      : Union[str, Any]         =   image[0, -3:, -3:, -1]

										assert image.shape == (1, 6_4, 6_4, 3)
										_UpperCamelCase      : List[Any]         =   np.array(
										    [0.5_748_162, 0.60_447_145, 0.48_821_217, 0.50_100_636, 0.5_431_185, 0.45_763_683, 0.49_657_696, 0.48_132_733, 0.47_573_093]							)

										assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-2






				def     snake_case     (			self		:   int							)     ->				Optional[Any]:




										'''simple docstring'''



										_UpperCamelCase      : List[Any]         =   '''cpu'''  # ensure determinism for the device-dependent torch.Generator

										_UpperCamelCase      : Optional[Any]         =   self.get_dummy_components()
										_UpperCamelCase      : str         =   PNDMScheduler(skip_prk_steps=lowerCAmelCase__							)
										torch.manual_seed(0							)
										_UpperCamelCase      : int         =   RobertaSeriesConfig(
										    hidden_size=3_2,			project_dim=3_2,			intermediate_size=3_7,			layer_norm_eps=1e-0_5,			num_attention_heads=4,			num_hidden_layers=5,			vocab_size=5_0_0_2,			)
										# TODO: remove after fixing the non-deterministic text encoder
										_UpperCamelCase      : Tuple         =   RobertaSeriesModelWithTransformation(lowerCAmelCase__							)
										_UpperCamelCase      : int         =   text_encoder
										_UpperCamelCase      : str         =   AltDiffusionPipeline(**lowerCAmelCase__							)
										_UpperCamelCase      : List[str]         =   alt_pipe.to(lowerCAmelCase__							)
										alt_pipe.set_progress_bar_config(disable=lowerCAmelCase__							)

										_UpperCamelCase      : Union[str, Any]         =   self.get_dummy_inputs(lowerCAmelCase__							)
										_UpperCamelCase      : Optional[int]         =   alt_pipe(**lowerCAmelCase__							)
										_UpperCamelCase      : List[str]         =   output.images
										_UpperCamelCase      : Optional[int]         =   image[0, -3:, -3:, -1]

										assert image.shape == (1, 6_4, 6_4, 3)
										_UpperCamelCase      : List[Any]         =   np.array(
										    [0.51_605_093, 0.5_707_241, 0.47_365_507, 0.50_578_886, 0.5_633_877, 0.4_642_503, 0.5_182_081, 0.48_763_484, 0.49_084_237]							)

										assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-2




@slow
@require_torch_gpu
class 			_a						(				unittest.TestCase    ):






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




										'''simple docstring'''



										super().tearDown()
										gc.collect()
										torch.cuda.empty_cache()






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




										'''simple docstring'''



										_UpperCamelCase      : str         =   AltDiffusionPipeline.from_pretrained('''BAAI/AltDiffusion''',			safety_checker=lowerCAmelCase__							)
										_UpperCamelCase      : List[Any]         =   alt_pipe.to(lowerCAmelCase__							)
										alt_pipe.set_progress_bar_config(disable=lowerCAmelCase__							)

										_UpperCamelCase      : int         =   '''A painting of a squirrel eating a burger'''
										_UpperCamelCase      : int         =   torch.manual_seed(0							)
										_UpperCamelCase      : Dict         =   alt_pipe([prompt],			generator=lowerCAmelCase__,			guidance_scale=6.0,			num_inference_steps=2_0,			output_type='''np'''							)

										_UpperCamelCase      : Optional[int]         =   output.images

										_UpperCamelCase      : Optional[int]         =   image[0, -3:, -3:, -1]

										assert image.shape == (1, 5_1_2, 5_1_2, 3)
										_UpperCamelCase      : List[str]         =   np.array([0.1_010, 0.0_800, 0.0_794, 0.0_885, 0.0_843, 0.0_762, 0.0_769, 0.0_729, 0.0_586]							)

										assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-2






				def     snake_case     (			self		:   str							)     ->				str:




										'''simple docstring'''



										_UpperCamelCase      : Any         =   DDIMScheduler.from_pretrained('''BAAI/AltDiffusion''',			subfolder='''scheduler'''							)

										_UpperCamelCase      : Dict         =   AltDiffusionPipeline.from_pretrained('''BAAI/AltDiffusion''',			scheduler=lowerCAmelCase__,			safety_checker=lowerCAmelCase__							)
										_UpperCamelCase      : Dict         =   alt_pipe.to(lowerCAmelCase__							)
										alt_pipe.set_progress_bar_config(disable=lowerCAmelCase__							)

										_UpperCamelCase      : Optional[Any]         =   '''A painting of a squirrel eating a burger'''
										_UpperCamelCase      : Optional[Any]         =   torch.manual_seed(0							)

										_UpperCamelCase      : Union[str, Any]         =   alt_pipe([prompt],			generator=lowerCAmelCase__,			num_inference_steps=2,			output_type='''numpy'''							)
										_UpperCamelCase      : Tuple         =   output.images

										_UpperCamelCase      : Dict         =   image[0, -3:, -3:, -1]

										assert image.shape == (1, 5_1_2, 5_1_2, 3)
										_UpperCamelCase      : str         =   np.array([0.4_019, 0.4_052, 0.3_810, 0.4_119, 0.3_916, 0.3_982, 0.4_651, 0.4_195, 0.5_323]							)

										assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-2










"""simple docstring"""




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






				def __init__(			self		:   Dict,			lowerCAmelCase__		:   Optional[Any],			lowerCAmelCase__		:   Optional[int]=1_3,			lowerCAmelCase__		:   Optional[Any]=7,			lowerCAmelCase__		:   Optional[Any]=True,			lowerCAmelCase__		:   Any=True,			lowerCAmelCase__		:   str=True,			lowerCAmelCase__		:   Any=9_9,			lowerCAmelCase__		:   Dict=3_2,			lowerCAmelCase__		:   List[Any]=5,			lowerCAmelCase__		:   Tuple=4,			lowerCAmelCase__		:   List[Any]=3_7,			lowerCAmelCase__		:   Tuple="gelu",			lowerCAmelCase__		:   Any=0.1,			lowerCAmelCase__		:   Optional[Any]=0.1,			lowerCAmelCase__		:   Dict=5_1_2,			lowerCAmelCase__		:   List[str]=1_6,			lowerCAmelCase__		:   Tuple=2,			lowerCAmelCase__		:   int=0.02,			lowerCAmelCase__		:   int=3,			lowerCAmelCase__		:   Optional[Any]=4,			lowerCAmelCase__		:   Dict=None,			)     ->				int:




										'''simple docstring'''



										_UpperCamelCase      : Tuple         =   parent
										_UpperCamelCase      : Union[str, Any]         =   batch_size
										_UpperCamelCase      : Union[str, Any]         =   seq_length
										_UpperCamelCase      : Tuple         =   is_training
										_UpperCamelCase      : Tuple         =   use_token_type_ids
										_UpperCamelCase      : Optional[int]         =   use_labels
										_UpperCamelCase      : Dict         =   vocab_size
										_UpperCamelCase      : int         =   hidden_size
										_UpperCamelCase      : Optional[Any]         =   num_hidden_layers
										_UpperCamelCase      : str         =   num_attention_heads
										_UpperCamelCase      : Union[str, Any]         =   intermediate_size
										_UpperCamelCase      : List[str]         =   hidden_act
										_UpperCamelCase      : Optional[Any]         =   hidden_dropout_prob
										_UpperCamelCase      : int         =   attention_probs_dropout_prob
										_UpperCamelCase      : Union[str, Any]         =   max_position_embeddings
										_UpperCamelCase      : int         =   type_vocab_size
										_UpperCamelCase      : List[str]         =   type_sequence_label_size
										_UpperCamelCase      : List[str]         =   initializer_range
										_UpperCamelCase      : int         =   num_labels
										_UpperCamelCase      : List[str]         =   num_choices
										_UpperCamelCase      : str         =   scope
										_UpperCamelCase      : Optional[int]         =   self.vocab_size - 1






				def     snake_case     (			self		:   int							)     ->				Optional[Any]:




										'''simple docstring'''



										_UpperCamelCase      : Dict         =   ids_tensor([self.batch_size, self.seq_length],			self.vocab_size							)

										_UpperCamelCase      : List[str]         =   None
										if self.use_token_type_ids:
																_UpperCamelCase      : Tuple         =   ids_tensor([self.batch_size, self.seq_length],			self.type_vocab_size							)

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

										_UpperCamelCase      : str         =   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,			)

										_UpperCamelCase      : List[Any]         =   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     snake_case     (			self		:   Union[str, Any],			lowerCAmelCase__		:   Optional[int],			lowerCAmelCase__		:   List[str],			lowerCAmelCase__		:   List[str],			lowerCAmelCase__		:   List[str],			*lowerCAmelCase__		:   List[Any]							)     ->				Optional[Any]:




										'''simple docstring'''



										_UpperCamelCase      : Dict         =   OpenAIGPTModel(config=lowerCAmelCase__							)
										model.to(lowerCAmelCase__							)
										model.eval()

										_UpperCamelCase      : List[str]         =   model(lowerCAmelCase__,			token_type_ids=lowerCAmelCase__,			head_mask=lowerCAmelCase__							)
										_UpperCamelCase      : Any         =   model(lowerCAmelCase__,			token_type_ids=lowerCAmelCase__							)
										_UpperCamelCase      : List[str]         =   model(lowerCAmelCase__							)

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






				def     snake_case     (			self		:   Any,			lowerCAmelCase__		:   Tuple,			lowerCAmelCase__		:   Union[str, Any],			lowerCAmelCase__		:   Any,			lowerCAmelCase__		:   Optional[Any],			*lowerCAmelCase__		:   Union[str, Any]							)     ->				Any:




										'''simple docstring'''



										_UpperCamelCase      : Any         =   OpenAIGPTLMHeadModel(lowerCAmelCase__							)
										model.to(lowerCAmelCase__							)
										model.eval()

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






				def     snake_case     (			self		:   Optional[int],			lowerCAmelCase__		:   str,			lowerCAmelCase__		:   List[str],			lowerCAmelCase__		:   Any,			lowerCAmelCase__		:   List[Any],			*lowerCAmelCase__		:   Any							)     ->				int:




										'''simple docstring'''



										_UpperCamelCase      : Tuple         =   OpenAIGPTDoubleHeadsModel(lowerCAmelCase__							)
										model.to(lowerCAmelCase__							)
										model.eval()

										_UpperCamelCase      : Optional[int]         =   model(lowerCAmelCase__,			token_type_ids=lowerCAmelCase__,			labels=lowerCAmelCase__							)
										self.parent.assertEqual(result.loss.shape,			()							)
										self.parent.assertEqual(result.logits.shape,			(self.batch_size, self.seq_length, self.vocab_size)							)






				def     snake_case     (			self		:   List[str],			lowerCAmelCase__		:   Dict,			lowerCAmelCase__		:   Dict,			lowerCAmelCase__		:   List[str],			lowerCAmelCase__		:   Optional[Any],			*lowerCAmelCase__		:   List[str]							)     ->				int:




										'''simple docstring'''



										_UpperCamelCase      : List[Any]         =   self.num_labels
										_UpperCamelCase      : Optional[int]         =   OpenAIGPTForSequenceClassification(lowerCAmelCase__							)
										model.to(lowerCAmelCase__							)
										model.eval()

										_UpperCamelCase      : str         =   ids_tensor([self.batch_size],			self.type_sequence_label_size							)
										_UpperCamelCase      : Union[str, Any]         =   model(lowerCAmelCase__,			token_type_ids=lowerCAmelCase__,			labels=lowerCAmelCase__							)
										self.parent.assertEqual(result.logits.shape,			(self.batch_size, self.num_labels)							)






				def     snake_case     (			self		:   str							)     ->				Optional[Any]:




										'''simple docstring'''



										_UpperCamelCase      : Any         =   self.prepare_config_and_inputs()
										(
										    (
										    _UpperCamelCase
										)       ,							(
										    _UpperCamelCase
										)       ,							(
										    _UpperCamelCase
										)       ,							(
										    _UpperCamelCase
										)       ,							(
										    _UpperCamelCase
										)       ,							(
										    _UpperCamelCase
										)       ,							(
										    _UpperCamelCase
										)       ,							
										)      : Tuple         =   config_and_inputs
										_UpperCamelCase      : Tuple         =   {
										    '''input_ids''': input_ids,
										    '''token_type_ids''': token_type_ids,
										    '''head_mask''': head_mask,
										}

										return config, inputs_dict




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






				def     snake_case     (			self		:   Union[str, Any],			lowerCAmelCase__		:   Any,			lowerCAmelCase__		:   List[str],			lowerCAmelCase__		:   str,			lowerCAmelCase__		:   List[str],			lowerCAmelCase__		:   List[str]							)     ->				List[str]:




										'''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     snake_case     (			self		:   str,			lowerCAmelCase__		:   Optional[int],			lowerCAmelCase__		:   List[str],			lowerCAmelCase__		:   Optional[int]=False							)     ->				Tuple:




										'''simple docstring'''



										_UpperCamelCase      : Optional[Any]         =   super()._prepare_for_class(lowerCAmelCase__,			lowerCAmelCase__,			return_labels=lowerCAmelCase__							)

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






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




										'''simple docstring'''



										_UpperCamelCase      : Optional[Any]         =   OpenAIGPTModelTester(self							)
										_UpperCamelCase      : int         =   ConfigTester(self,			config_class=lowerCAmelCase__,			n_embd=3_7							)






				def     snake_case     (			self		:   Optional[int]							)     ->				str:




										'''simple docstring'''



										self.config_tester.run_common_tests()






				def     snake_case     (			self		:   Optional[int]							)     ->				Any:




										'''simple docstring'''



										_UpperCamelCase      : List[Any]         =   self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_model(*lowerCAmelCase__							)






				def     snake_case     (			self		:   Any							)     ->				Dict:




										'''simple docstring'''



										_UpperCamelCase      : Union[str, Any]         =   self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_lm_head_model(*lowerCAmelCase__							)






				def     snake_case     (			self		:   int							)     ->				Dict:




										'''simple docstring'''



										_UpperCamelCase      : Union[str, Any]         =   self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_double_lm_head_model(*lowerCAmelCase__							)






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




										'''simple docstring'''



										_UpperCamelCase      : List[Any]         =   self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*lowerCAmelCase__							)






				@slow
				def     snake_case     (			self		:   Optional[Any]							)     ->				Optional[Any]:




										'''simple docstring'''



										for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																_UpperCamelCase      : int         =   OpenAIGPTModel.from_pretrained(lowerCAmelCase__							)
																self.assertIsNotNone(lowerCAmelCase__							)




@require_torch
class 			_a						(				unittest.TestCase    ):






				@slow
				def     snake_case     (			self		:   Union[str, Any]							)     ->				Optional[Any]:




										'''simple docstring'''



										_UpperCamelCase      : int         =   OpenAIGPTLMHeadModel.from_pretrained('''openai-gpt'''							)
										model.to(lowerCAmelCase__							)
										_UpperCamelCase      : str         =   torch.tensor([[4_8_1, 4_7_3_5, 5_4_4]],			dtype=torch.long,			device=lowerCAmelCase__							)  # the president is
										_UpperCamelCase      : Optional[int]         =   [
										    4_8_1,
										    4_7_3_5,
										    5_4_4,
										    2_4_6,
										    9_6_3,
										    8_7_0,
										    7_6_2,
										    2_3_9,
										    2_4_4,
										    4_0_4_7_7,
										    2_4_4,
										    2_4_9,
										    7_1_9,
										    8_8_1,
										    4_8_7,
										    5_4_4,
										    2_4_0,
										    2_4_4,
										    6_0_3,
										    4_8_1,
										]  # the president is a very good man. " \n " i\'m sure he is, " said the

										_UpperCamelCase      : Union[str, Any]         =   model.generate(lowerCAmelCase__,			do_sample=lowerCAmelCase__							)
										self.assertListEqual(output_ids[0].tolist(),			lowerCAmelCase__							)



