
"""simple docstring"""


import random
import unittest

import torch

from diffusers import IFSuperResolutionPipeline
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    __lowerCamelCase     (   lowerCAmelCase	,  lowerCAmelCase	,  unittest.TestCase ):
				a__:			List[str]									=						IFSuperResolutionPipeline
				a__:			Union[str, Any]									=						TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'width', 'height'}
				a__:			List[Any]									=						TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
				a__:			str									=						PipelineTesterMixin.required_optional_params - {'latents'}




				def 					UpperCAmelCase__	(							self      ):
							return self._get_superresolution_dummy_components()




				def 					UpperCAmelCase__	(							self       ,	UpperCAmelCase       ,	UpperCAmelCase=0      ):
							if str(UpperCAmelCase      ).startswith('''mps'''      ):
										lowerCamelCase_ 		=     torch.manual_seed(UpperCAmelCase      )
							else:
										lowerCamelCase_ 		=     torch.Generator(device=UpperCAmelCase      ).manual_seed(UpperCAmelCase      )

							lowerCamelCase_ 		=     floats_tensor((1, 3, 32, 32)       ,	rng=random.Random(UpperCAmelCase      )      ).to(UpperCAmelCase      )

							lowerCamelCase_ 		=     {
							    '''prompt''': '''A painting of a squirrel eating a burger''',
							    '''image''': 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      ):
							self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3      )




				def 					UpperCAmelCase__	(							self      ):
							self._test_save_load_optional_components()




				@unittest.skipIf(torch_device != '''cuda'''       ,	reason='''float16 requires CUDA'''      )
				def 					UpperCAmelCase__	(							self      ):
							# 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      ):
							self._test_attention_slicing_forward_pass(expected_max_diff=1e-2      )




				def 					UpperCAmelCase__	(							self      ):
							self._test_save_load_local()





				def 					UpperCAmelCase__	(							self      ):
							self._test_inference_batch_single_identical(
							    expected_max_diff=1e-2       ,	)





"""simple docstring"""


import glob
import os

from get_test_info import get_tester_classes


if __name__ == "__main__":
						A_						       =				[]

						A_						       =				os.path.join("""tests""", """models""", """**""", """test_modeling_*.py""")
						A_						       =				glob.glob(pattern)
						# TODO: deal with TF/Flax too
						A_						       =				[
						    x for x in test_files if not (x.startswith("""test_modeling_tf_""") or x.startswith("""test_modeling_flax_"""))
						]

						for test_file in test_files:
												A_						       =				get_tester_classes(test_file)
												for tester_class in tester_classes:
																		# A few tester classes don't have `parent` parameter in `__init__`.
																		# TODO: deal this better
																		try:
																								A_						       =				tester_class(parent=None)
																		except Exception:
																								continue
																		if hasattr(tester, """get_config"""):
																								A_						       =				tester.get_config()
																								for k, v in config.to_dict().items():
																														if isinstance(v, int):
																																				A_						       =				None
																																				if k in ["vocab_size"]:
																																										A_						       =				100
																																				elif k in ["max_position_embeddings"]:
																																										A_						       =				128
																																				elif k in ["hidden_size", "d_model"]:
																																										A_						       =				40
																																				elif k == ["num_layers", "num_hidden_layers", "num_encoder_layers", "num_decoder_layers"]:
																																										A_						       =				5
																																				if target is not None and v > target:
																																										failures.append(
																																										    f"{tester_class.__name__} will produce a `config` of type `{config.__class__.__name__}`"
																																										    f" with config[\"{k}\"] = {v} which is too large for testing! Set its value to be smaller"
																																										    f" than {target}."
																																										)

						if len(failures) > 0:
												raise Exception(f"There were {len(failures)} failures:\n" + """\n""".join(failures))



