


'''simple docstring'''







import gc
import unittest

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

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    PNDMScheduler,
    StableDiffusionLDMaDPipeline,
    UNetaDConditionModel,
)
from diffusers.utils import nightly, 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


enable_full_determinism()


class 		__UpperCAmelCase   (      unittest.TestCase		):
							__lowercase   	= StableDiffusionLDMaDPipeline
							__lowercase   	= TEXT_TO_IMAGE_PARAMS
							__lowercase   	= TEXT_TO_IMAGE_BATCH_PARAMS
							__lowercase   	= TEXT_TO_IMAGE_IMAGE_PARAMS


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								torch.manual_seed(0						)
								_snake_case     		=	UNetaDConditionModel(
								    block_out_channels=(32, 64)					,     layers_per_block=2					,     sample_size=32					,     in_channels=4					,     out_channels=4					,     down_block_types=('DownBlock2D', 'CrossAttnDownBlock2D')					,     up_block_types=('CrossAttnUpBlock2D', 'UpBlock2D')					,     cross_attention_dim=32					,     )
								_snake_case     		=	DDIMScheduler(
								    beta_start=0.00085					,     beta_end=0.012					,     beta_schedule='scaled_linear'					,     clip_sample=_UpperCAmelCase					,     set_alpha_to_one=_UpperCAmelCase					,     )
								torch.manual_seed(0						)
								_snake_case     		=	AutoencoderKL(
								    block_out_channels=[32, 64]					,     in_channels=6					,     out_channels=6					,     down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D']					,     up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D']					,     latent_channels=4					,     )
								torch.manual_seed(0						)
								_snake_case     		=	CLIPTextConfig(
								    bos_token_id=0					,     eos_token_id=2					,     hidden_size=32					,     intermediate_size=37					,     layer_norm_eps=1E-05					,     num_attention_heads=4					,     num_hidden_layers=5					,     pad_token_id=1					,     vocab_size=10_00					,     )
								_snake_case     		=	CLIPTextModel(_UpperCAmelCase						)
								_snake_case     		=	CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'						)

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


							def 				lowerCamelCase       ( self					,     lowerCAmelCase_					,     lowerCAmelCase_=0						):





								"""simple docstring"""






								if str(_UpperCAmelCase						).startswith('mps'						):
									_snake_case     		=	torch.manual_seed(_UpperCAmelCase						)
								else:
									_snake_case     		=	torch.Generator(device=_UpperCAmelCase						).manual_seed(_UpperCAmelCase						)
								_snake_case     		=	{
								    '''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 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	'''cpu'''  # ensure determinism for the device-dependent torch.Generator

								_snake_case     		=	self.get_dummy_components()
								_snake_case     		=	StableDiffusionLDMaDPipeline(**_UpperCAmelCase						)
								_snake_case     		=	ldmad_pipe.to(_UpperCAmelCase						)
								ldmad_pipe.set_progress_bar_config(disable=_UpperCAmelCase						)

								_snake_case     		=	self.get_dummy_inputs(_UpperCAmelCase						)
								_snake_case     		=	ldmad_pipe(**_UpperCAmelCase						)
								_snake_case     		=	output.rgb, output.depth

								_snake_case     		=	rgb[0, -3:, -3:, -1]
								_snake_case     		=	depth[0, -3:, -1]

								assert rgb.shape == (1, 64, 64, 3)
								assert depth.shape == (1, 64, 64)

								_snake_case     		=	np.array(
								    [0.37338176, 0.70247, 0.74203193, 0.51643604, 0.58256793, 0.60932136, 0.4181095, 0.48355877, 0.46535262]						)
								_snake_case     		=	np.array([1_03.4_67_27, 85.81_20_04, 87.84_92_36]						)

								assert np.abs(image_slice_rgb.flatten() - expected_slice_rgb						).max() < 1E-2
								assert np.abs(image_slice_depth.flatten() - expected_slice_depth						).max() < 1E-2


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	self.get_dummy_components()
								_snake_case     		=	StableDiffusionLDMaDPipeline(**_UpperCAmelCase						)
								_snake_case     		=	ldmad_pipe.to(_UpperCAmelCase						)
								ldmad_pipe.set_progress_bar_config(disable=_UpperCAmelCase						)

								_snake_case     		=	self.get_dummy_inputs(_UpperCAmelCase						)
								_snake_case     		=	3 * [inputs['''prompt''']]

								# forward
								_snake_case     		=	ldmad_pipe(**_UpperCAmelCase						)
								_snake_case     		=	output.rgb, output.depth
								_snake_case     		=	rgb_slice_a[0, -3:, -3:, -1]
								_snake_case     		=	depth_slice_a[0, -3:, -1]

								_snake_case     		=	self.get_dummy_inputs(_UpperCAmelCase						)
								_snake_case     		=	3 * [inputs.pop('prompt'						)]

								_snake_case     		=	ldmad_pipe.tokenizer(
								    _UpperCAmelCase					,     padding='max_length'					,     max_length=ldmad_pipe.tokenizer.model_max_length					,     truncation=_UpperCAmelCase					,     return_tensors='pt'					,     )
								_snake_case     		=	text_inputs['''input_ids'''].to(_UpperCAmelCase						)

								_snake_case     		=	ldmad_pipe.text_encoder(_UpperCAmelCase						)[0]

								_snake_case     		=	prompt_embeds

								# forward
								_snake_case     		=	ldmad_pipe(**_UpperCAmelCase						)
								_snake_case     		=	output.rgb, output.depth
								_snake_case     		=	rgb_slice_a[0, -3:, -3:, -1]
								_snake_case     		=	depth_slice_a[0, -3:, -1]

								assert np.abs(rgb_slice_a.flatten() - rgb_slice_a.flatten()						).max() < 1E-4
								assert np.abs(depth_slice_a.flatten() - depth_slice_a.flatten()						).max() < 1E-4




							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	'''cpu'''  # ensure determinism for the device-dependent torch.Generator
								_snake_case     		=	self.get_dummy_components()
								_snake_case     		=	PNDMScheduler(skip_prk_steps=_UpperCAmelCase						)
								_snake_case     		=	StableDiffusionLDMaDPipeline(**_UpperCAmelCase						)
								_snake_case     		=	ldmad_pipe.to(_UpperCAmelCase						)
								ldmad_pipe.set_progress_bar_config(disable=_UpperCAmelCase						)

								_snake_case     		=	self.get_dummy_inputs(_UpperCAmelCase						)
								_snake_case     		=	'''french fries'''
								_snake_case     		=	ldmad_pipe(**_UpperCAmelCase					,     negative_prompt=_UpperCAmelCase						)

								_snake_case     		=	output.rgb, output.depth
								_snake_case     		=	rgb[0, -3:, -3:, -1]
								_snake_case     		=	depth[0, -3:, -1]

								assert rgb.shape == (1, 64, 64, 3)
								assert depth.shape == (1, 64, 64)

								_snake_case     		=	np.array(
								    [0.37044, 0.71811503, 0.7223251, 0.48603675, 0.5638391, 0.6364948, 0.42833704, 0.4901315, 0.47926217]						)
								_snake_case     		=	np.array([1_07.8_47_38, 84.6_28_02, 89.96_21_35]						)
								assert np.abs(rgb_slice.flatten() - expected_slice_rgb						).max() < 1E-2
								assert np.abs(depth_slice.flatten() - expected_slice_depth						).max() < 1E-2


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


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






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


							def 				lowerCamelCase       ( self					,     lowerCAmelCase_					,     lowerCAmelCase_="cpu"					,     lowerCAmelCase_=torch.floataa					,     lowerCAmelCase_=0						):





								"""simple docstring"""






								_snake_case     		=	torch.Generator(device=_UpperCAmelCase						).manual_seed(_UpperCAmelCase						)
								_snake_case     		=	np.random.RandomState(_UpperCAmelCase						).standard_normal((1, 4, 64, 64)						)
								_snake_case     		=	torch.from_numpy(_UpperCAmelCase						).to(device=_UpperCAmelCase					,     dtype=_UpperCAmelCase						)
								_snake_case     		=	{
								    '''prompt''': '''a photograph of an astronaut riding a horse''',
								    '''latents''': latents,
								    '''generator''': generator,
								    '''num_inference_steps''': 3,
								    '''guidance_scale''': 7.5,
								    '''output_type''': '''numpy''',
								}
								return inputs




							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	StableDiffusionLDMaDPipeline.from_pretrained('Intel/ldm3d'						)
								_snake_case     		=	ldmad_pipe.to(_UpperCAmelCase						)
								ldmad_pipe.set_progress_bar_config(disable=_UpperCAmelCase						)

								_snake_case     		=	self.get_inputs(_UpperCAmelCase						)
								_snake_case     		=	ldmad_pipe(**_UpperCAmelCase						)
								_snake_case     		=	output.rgb, output.depth
								_snake_case     		=	rgb[0, -3:, -3:, -1].flatten()
								_snake_case     		=	rgb[0, -3:, -1].flatten()

								assert rgb.shape == (1, 5_12, 5_12, 3)
								assert depth.shape == (1, 5_12, 5_12)

								_snake_case     		=	np.array(
								    [0.53805465, 0.56707305, 0.5486515, 0.57012236, 0.5814511, 0.56253487, 0.54843014, 0.55092263, 0.6459706]						)
								_snake_case     		=	np.array(
								    [0.9263781, 0.6678672, 0.5486515, 0.92202145, 0.67831135, 0.56253487, 0.9241694, 0.7551478, 0.6459706]						)
								assert np.abs(rgb_slice - expected_slice_rgb						).max() < 3E-3
								assert np.abs(depth_slice - expected_slice_depth						).max() < 3E-3


@nightly
@require_torch_gpu
class 		__UpperCAmelCase   (      unittest.TestCase		):


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






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


							def 				lowerCamelCase       ( self					,     lowerCAmelCase_					,     lowerCAmelCase_="cpu"					,     lowerCAmelCase_=torch.floataa					,     lowerCAmelCase_=0						):





								"""simple docstring"""






								_snake_case     		=	torch.Generator(device=_UpperCAmelCase						).manual_seed(_UpperCAmelCase						)
								_snake_case     		=	np.random.RandomState(_UpperCAmelCase						).standard_normal((1, 4, 64, 64)						)
								_snake_case     		=	torch.from_numpy(_UpperCAmelCase						).to(device=_UpperCAmelCase					,     dtype=_UpperCAmelCase						)
								_snake_case     		=	{
								    '''prompt''': '''a photograph of an astronaut riding a horse''',
								    '''latents''': latents,
								    '''generator''': generator,
								    '''num_inference_steps''': 50,
								    '''guidance_scale''': 7.5,
								    '''output_type''': '''numpy''',
								}
								return inputs


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	StableDiffusionLDMaDPipeline.from_pretrained('Intel/ldm3d'						).to(_UpperCAmelCase						)
								ldmad_pipe.set_progress_bar_config(disable=_UpperCAmelCase						)

								_snake_case     		=	self.get_inputs(_UpperCAmelCase						)
								_snake_case     		=	ldmad_pipe(**_UpperCAmelCase						)
								_snake_case     		=	output.rgb, output.depth

								_snake_case     		=	0.495586
								_snake_case     		=	0.33795515
								_snake_case     		=	1_12.4_85_18
								_snake_case     		=	98.48_97_46
								assert np.abs(expected_rgb_mean - rgb.mean()						) < 1E-3
								assert np.abs(expected_rgb_std - rgb.std()						) < 1E-3
								assert np.abs(expected_depth_mean - depth.mean()						) < 1E-3
								assert np.abs(expected_depth_std - depth.std()						) < 1E-3




							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	StableDiffusionLDMaDPipeline.from_pretrained('Intel/ldm3d-4c'						).to(_UpperCAmelCase						)
								ldmad_pipe.set_progress_bar_config(disable=_UpperCAmelCase						)

								_snake_case     		=	self.get_inputs(_UpperCAmelCase						)
								_snake_case     		=	ldmad_pipe(**_UpperCAmelCase						)
								_snake_case     		=	output.rgb, output.depth

								_snake_case     		=	0.4194127
								_snake_case     		=	0.35375586
								_snake_case     		=	0.5638502
								_snake_case     		=	0.34686103

								assert rgb.shape == (1, 5_12, 5_12, 3)
								assert depth.shape == (1, 5_12, 5_12, 1)
								assert np.abs(expected_rgb_mean - rgb.mean()						) < 1E-3
								assert np.abs(expected_rgb_std - rgb.std()						) < 1E-3
								assert np.abs(expected_depth_mean - depth.mean()						) < 1E-3
								assert np.abs(expected_depth_std - depth.std()						) < 1E-3



'''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 		__UpperCAmelCase   :


							def __init__( self					,     lowerCAmelCase_					,     lowerCAmelCase_=13					,     lowerCAmelCase_=7					,     lowerCAmelCase_=True					,     lowerCAmelCase_=True					,     lowerCAmelCase_=True					,     lowerCAmelCase_=99					,     lowerCAmelCase_=32					,     lowerCAmelCase_=5					,     lowerCAmelCase_=4					,     lowerCAmelCase_=37					,     lowerCAmelCase_="gelu"					,     lowerCAmelCase_=0.1					,     lowerCAmelCase_=0.1					,     lowerCAmelCase_=5_12					,     lowerCAmelCase_=16					,     lowerCAmelCase_=2					,     lowerCAmelCase_=0.02					,     lowerCAmelCase_=3					,     lowerCAmelCase_=4					,     lowerCAmelCase_=None					,     ):





								"""simple docstring"""






								_snake_case     		=	parent
								_snake_case     		=	batch_size
								_snake_case     		=	seq_length
								_snake_case     		=	is_training
								_snake_case     		=	use_token_type_ids
								_snake_case     		=	use_labels
								_snake_case     		=	vocab_size
								_snake_case     		=	hidden_size
								_snake_case     		=	num_hidden_layers
								_snake_case     		=	num_attention_heads
								_snake_case     		=	intermediate_size
								_snake_case     		=	hidden_act
								_snake_case     		=	hidden_dropout_prob
								_snake_case     		=	attention_probs_dropout_prob
								_snake_case     		=	max_position_embeddings
								_snake_case     		=	type_vocab_size
								_snake_case     		=	type_sequence_label_size
								_snake_case     		=	initializer_range
								_snake_case     		=	num_labels
								_snake_case     		=	num_choices
								_snake_case     		=	scope
								_snake_case     		=	self.vocab_size - 1


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	ids_tensor([self.batch_size, self.seq_length]					,     self.vocab_size						)

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

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

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

								_snake_case     		=	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 				lowerCamelCase       ( self					,     lowerCAmelCase_					,     lowerCAmelCase_					,     lowerCAmelCase_					,     lowerCAmelCase_					,     *lowerCAmelCase_						):





								"""simple docstring"""






								_snake_case     		=	OpenAIGPTModel(config=lowerCAmelCase_						)
								model.to(lowerCAmelCase_						)
								model.eval()

								_snake_case     		=	model(lowerCAmelCase_					,     token_type_ids=lowerCAmelCase_					,     head_mask=lowerCAmelCase_						)
								_snake_case     		=	model(lowerCAmelCase_					,     token_type_ids=lowerCAmelCase_						)
								_snake_case     		=	model(lowerCAmelCase_						)

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


							def 				lowerCamelCase       ( self					,     lowerCAmelCase_					,     lowerCAmelCase_					,     lowerCAmelCase_					,     lowerCAmelCase_					,     *lowerCAmelCase_						):





								"""simple docstring"""






								_snake_case     		=	OpenAIGPTLMHeadModel(lowerCAmelCase_						)
								model.to(lowerCAmelCase_						)
								model.eval()

								_snake_case     		=	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 				lowerCamelCase       ( self					,     lowerCAmelCase_					,     lowerCAmelCase_					,     lowerCAmelCase_					,     lowerCAmelCase_					,     *lowerCAmelCase_						):





								"""simple docstring"""






								_snake_case     		=	OpenAIGPTDoubleHeadsModel(lowerCAmelCase_						)
								model.to(lowerCAmelCase_						)
								model.eval()

								_snake_case     		=	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 				lowerCamelCase       ( self					,     lowerCAmelCase_					,     lowerCAmelCase_					,     lowerCAmelCase_					,     lowerCAmelCase_					,     *lowerCAmelCase_						):





								"""simple docstring"""






								_snake_case     		=	self.num_labels
								_snake_case     		=	OpenAIGPTForSequenceClassification(lowerCAmelCase_						)
								model.to(lowerCAmelCase_						)
								model.eval()

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




							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	self.prepare_config_and_inputs()
								(
								    (
								    _snake_case
								)		,				(
								    _snake_case
								)		,				(
								    _snake_case
								)		,				(
								    _snake_case
								)		,				(
								    _snake_case
								)		,				(
								    _snake_case
								)		,				(
								    _snake_case
								)		,				
								)     		=	config_and_inputs
								_snake_case     		=	{
								    'input_ids': input_ids,
								    'token_type_ids': token_type_ids,
								    'head_mask': head_mask,
								}

								return config, inputs_dict


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


							def 				lowerCamelCase       ( self					,     lowerCAmelCase_					,     lowerCAmelCase_					,     lowerCAmelCase_					,     lowerCAmelCase_					,     lowerCAmelCase_						):





								"""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 				lowerCamelCase       ( self					,     lowerCAmelCase_					,     lowerCAmelCase_					,     lowerCAmelCase_=False						):





								"""simple docstring"""






								_snake_case     		=	super()._prepare_for_class(lowerCAmelCase_					,     lowerCAmelCase_					,     return_labels=lowerCAmelCase_						)

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


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	OpenAIGPTModelTester(self						)
								_snake_case     		=	ConfigTester(self					,     config_class=lowerCAmelCase_					,     n_embd=37						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								self.config_tester.run_common_tests()


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_openai_gpt_model(*lowerCAmelCase_						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_lm_head_model(*lowerCAmelCase_						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_double_lm_head_model(*lowerCAmelCase_						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*lowerCAmelCase_						)




							@slow
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									_snake_case     		=	OpenAIGPTModel.from_pretrained(lowerCAmelCase_						)
									self.assertIsNotNone(lowerCAmelCase_						)


@require_torch
class 		__UpperCAmelCase   (      unittest.TestCase		):


							@slow
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	OpenAIGPTLMHeadModel.from_pretrained('openai-gpt'						)
								model.to(lowerCAmelCase_						)
								_snake_case     		=	torch.tensor([[4_81, 47_35, 5_44]]					,     dtype=torch.long					,     device=lowerCAmelCase_						)  # the president is
								_snake_case     		=	[
								    4_81,
								    47_35,
								    5_44,
								    2_46,
								    9_63,
								    8_70,
								    7_62,
								    2_39,
								    2_44,
								    4_04_77,
								    2_44,
								    2_49,
								    7_19,
								    8_81,
								    4_87,
								    5_44,
								    2_40,
								    2_44,
								    6_03,
								    4_81,
								]  # the president is a very good man. " \n " i\'m sure he is, " said the

								_snake_case     		=	model.generate(lowerCAmelCase_					,     do_sample=lowerCAmelCase_						)
								self.assertListEqual(output_ids[0].tolist()					,     lowerCAmelCase_						)

