






import random
import unittest

import torch

from diffusers import IFImgaImgSuperResolutionPipeline
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_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin







@skip_mps
class    A_	(a_						,					a_						,					unittest.TestCase							):
							"""simple docstring"""




							a__   		=	IFImgaImgSuperResolutionPipeline
							a__   		=	TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''width''', '''height'''}
							a__   		=	TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({'''original_image'''}							)
							a__   		=	PipelineTesterMixin.required_optional_params - {'''latents'''}

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


										'''simple docstring'''




										return self._get_superresolution_dummy_components()

							def 							_A	(		self			:Union[str, Any]       ,							lowerCAmelCase__			:Optional[Any]       ,							lowerCAmelCase__			:List[Any]=0				)				->  str:


										'''simple docstring'''




										if str(lowerCAmelCase__				).startswith("mps"				):
													snake_case_				:					Union[str, Any]   =       torch.manual_seed(lowerCAmelCase__				)
										else:
													snake_case_				:					Optional[Any]   =       torch.Generator(device=lowerCAmelCase__				).manual_seed(lowerCAmelCase__				)

										snake_case_				:					Tuple   =       floats_tensor((1, 3, 32, 32)       ,							rng=random.Random(lowerCAmelCase__				)				).to(lowerCAmelCase__				)
										snake_case_				:					List[Any]   =       floats_tensor((1, 3, 16, 16)       ,							rng=random.Random(lowerCAmelCase__				)				).to(lowerCAmelCase__				)

										snake_case_				:					str   =       {
										    "prompt": "A painting of a squirrel eating a burger",
										    "image": image,
										    "original_image": original_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 							_A	(		self			:Tuple				)				->  List[Any]:


										'''simple docstring'''




										self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3				)

							def 							_A	(		self			:str				)				->  Tuple:


										'''simple docstring'''




										self._test_save_load_optional_components()

							@unittest.skipIf(torch_device != "cuda"       ,							reason="float16 requires CUDA"				)
							def 							_A	(		self			:Optional[Any]				)				->  Optional[Any]:


										'''simple docstring'''




										super().test_save_load_floataa(expected_max_diff=1E-1				)

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


										'''simple docstring'''




										self._test_attention_slicing_forward_pass(expected_max_diff=1E-2				)

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


										'''simple docstring'''




										self._test_save_load_local()






							def 							_A	(		self			:Dict				)				->  Tuple:


										'''simple docstring'''




										self._test_inference_batch_single_identical(
										    expected_max_diff=1E-2       ,							)












'''simple docstring'''




import inspect
import re

from transformers.utils import direct_transformers_import


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
__lowerCamelCase   :					Any   							=					'''src/transformers'''


# This is to make sure the transformers module imported is the one in the repo.
__lowerCamelCase   :					List[str]   							=					direct_transformers_import(PATH_TO_TRANSFORMERS)

__lowerCamelCase   :					Optional[Any]   							=					transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
__lowerCamelCase   :					Union[str, Any]   							=					re.compile(R'''\[(.+?)\]\((https://huggingface\.co/.+?)\)''')


__lowerCamelCase   :					Any   							=					{
    '''DecisionTransformerConfig''',
    '''EncoderDecoderConfig''',
    '''MusicgenConfig''',
    '''RagConfig''',
    '''SpeechEncoderDecoderConfig''',
    '''TimmBackboneConfig''',
    '''VisionEncoderDecoderConfig''',
    '''VisionTextDualEncoderConfig''',
    '''LlamaConfig''',
}

def 	__UpperCAmelCase       ( __magic_name__						)->    List[Any]:



			"""simple docstring"""



			snake_case_				:					Tuple   =       None

			# source code of `config_class`
			snake_case_				:					List[Any]   =       inspect.getsource(__magic_name__						)
			snake_case_				:					List[str]   =       _re_checkpoint.findall(__magic_name__						)

			# Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
			# For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
			for ckpt_name, ckpt_link in checkpoints:
						# allow the link to end with `/`
						if ckpt_link.endswith("/"						):
									snake_case_				:					Optional[Any]   =       ckpt_link[:-1]

						# verify the checkpoint name corresponds to the checkpoint link
						snake_case_				:					str   =       F'''https://huggingface.co/{ckpt_name}'''
						if ckpt_link == ckpt_link_from_name:
									snake_case_				:					Dict   =       ckpt_name
									break

			return checkpoint

def 	__UpperCAmelCase       ( )->    Dict:



			"""simple docstring"""



			snake_case_				:					Optional[int]   =       []

			for config_class in list(CONFIG_MAPPING.values()						):
						# Skip deprecated models
						if "models.deprecated" in config_class.__module__:
									continue
						snake_case_				:					str   =       get_checkpoint_from_config_class(__magic_name__						)

						snake_case_				:					Union[str, Any]   =       config_class.__name__
						if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
									configs_without_checkpoint.append(__magic_name__						)

			if len(__magic_name__						) > 0:
						snake_case_				:					Tuple   =       "\n".join(sorted(__magic_name__						)						)
						raise ValueError(F'''The following configurations don\'t contain any valid checkpoint:\n{message}'''						)


if __name__ == "__main__":
		check_config_docstrings_have_checkpoints()




