






import random
import unittest

import torch

from diffusers import IFInpaintingSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import (
    TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin




@skip_mps
class 					UpperCamelCase_ (     snake_case_			,   snake_case_			,   unittest.TestCase							):



	'''simple docstring'''




	lowerCAmelCase						=					IFInpaintingSuperResolutionPipeline
	lowerCAmelCase						=					TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {'''width''', '''height'''}
	lowerCAmelCase						=					TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({'''original_image'''}							)
	lowerCAmelCase						=					PipelineTesterMixin.required_optional_params - {'''latents'''}




	def 				_UpperCamelCase     (			self   )			->       List[str]:
								return self._get_superresolution_dummy_components()




	def 				_UpperCamelCase     (			self			,     a			,     a=0   )			->       Dict:
								if str(a   ).startswith('mps'   ):
															snake_case_           =				torch.manual_seed(a   )
								else:
															snake_case_           =				torch.Generator(device=a   ).manual_seed(a   )

								snake_case_           =				floats_tensor((1, 3, 16, 16)			,     rng=random.Random(a   )   ).to(a   )
								snake_case_           =				floats_tensor((1, 3, 32, 32)			,     rng=random.Random(a   )   ).to(a   )
								snake_case_           =				floats_tensor((1, 3, 32, 32)			,     rng=random.Random(a   )   ).to(a   )

								snake_case_           =				{
								    'prompt': 'A painting of a squirrel eating a burger',
								    'image': image,
								    'original_image': original_image,
								    'mask_image': mask_image,
								    'generator': generator,
								    'num_inference_steps': 2,
								    'output_type': 'numpy',
								}

								return inputs




	@unittest.skipIf(
	    torch_device != 'cuda' or not is_xformers_available()			,     reason='XFormers attention is only available with CUDA and `xformers` installed'			,     )
	def 				_UpperCamelCase     (			self   )			->       Union[str, Any]:
								self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3   )




	def 				_UpperCamelCase     (			self   )			->       str:
								self._test_save_load_optional_components()




	@unittest.skipIf(torch_device != 'cuda'			,     reason='float16 requires CUDA'   )
	def 				_UpperCamelCase     (			self   )			->       Optional[int]:
								# Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
								super().test_save_load_floataa(expected_max_diff=1E-1   )




	def 				_UpperCamelCase     (			self   )			->       Dict:
								self._test_attention_slicing_forward_pass(expected_max_diff=1E-2   )




	def 				_UpperCamelCase     (			self   )			->       Union[str, Any]:
								self._test_save_load_local()






	def 				_UpperCamelCase     (			self   )			->       Union[str, Any]:
								self._test_inference_batch_single_identical(
								    expected_max_diff=1E-2			,     )













from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase    				=   logging.get_logger(__name__)

lowercase    				=   {
    "transfo-xl-wt103": "https://huggingface.co/transfo-xl-wt103/resolve/main/config.json",
}




class 					UpperCamelCase_ (     snake_case_							):



	'''simple docstring'''




	lowerCAmelCase						=					'''transfo-xl'''
	lowerCAmelCase						=					['''mems''']
	lowerCAmelCase						=					{
	    '''n_token''': '''vocab_size''',
	    '''hidden_size''': '''d_model''',
	    '''num_attention_heads''': '''n_head''',
	    '''num_hidden_layers''': '''n_layer''',
	}




	def __init__(			self			,     a=26_77_35			,     a=[2_00_00, 4_00_00, 20_00_00]			,     a=10_24			,     a=10_24			,     a=16			,     a=64			,     a=40_96			,     a=4			,     a=False			,     a=18			,     a=16_00			,     a=10_00			,     a=True			,     a=True			,     a=0			,     a=-1			,     a=True			,     a=0.1			,     a=0.0			,     a=True			,     a="normal"			,     a=0.01			,     a=0.01			,     a=0.02			,     a=1E-5			,     a=0			,     **a			,     )			->       Union[str, Any]:
								snake_case_           =				vocab_size
								snake_case_           =				[]
								self.cutoffs.extend(a   )
								if proj_share_all_but_first:
															snake_case_           =				[False] + [True] * len(self.cutoffs   )
								else:
															snake_case_           =				[False] + [False] * len(self.cutoffs   )
								snake_case_           =				d_model
								snake_case_           =				d_embed
								snake_case_           =				d_head
								snake_case_           =				d_inner
								snake_case_           =				div_val
								snake_case_           =				pre_lnorm
								snake_case_           =				n_layer
								snake_case_           =				n_head
								snake_case_           =				mem_len
								snake_case_           =				same_length
								snake_case_           =				attn_type
								snake_case_           =				clamp_len
								snake_case_           =				sample_softmax
								snake_case_           =				adaptive
								snake_case_           =				dropout
								snake_case_           =				dropatt
								snake_case_           =				untie_r
								snake_case_           =				init
								snake_case_           =				init_range
								snake_case_           =				proj_init_std
								snake_case_           =				init_std
								snake_case_           =				layer_norm_epsilon
								super().__init__(eos_token_id=a			,     **a   )




	@property
	def 				_UpperCamelCase     (			self   )			->       int:
								# Message copied from Transformer-XL documentation
								logger.info(F'''The model {self.model_type} is one of the few models that has no sequence length limit.'''   )
								return -1






	@max_position_embeddings.setter
	def 				_UpperCamelCase     (			self			,     a   )			->       List[str]:
								# Message copied from Transformer-XL documentation
								raise NotImplementedError(
								    F'''The model {self.model_type} is one of the few models that has no sequence length limit.'''   )





