



"""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    ):






     '''simple docstring'''





     _A		:      Union[str, Any]						=					IFSuperResolutionPipeline
     _A		:      Optional[Any]						=					TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
     _A		:      str						=					TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
     _A		:      Union[str, Any]						=					PipelineTesterMixin.required_optional_params - {"""latents"""}






     def        lowerCAmelCase_    (	self:							Union[str, Any]						)       ->     int:
           return self._get_superresolution_dummy_components()






     def        lowerCAmelCase_    (	self:							List[str]						,					snake_case:							Union[str, Any]						,					snake_case:							str=0						)       ->     Tuple:
           if str(snake_case						).startswith("""mps"""						):
                 snake_case_			:Any						=      torch.manual_seed(snake_case						)
           else:
                 snake_case_			:int						=      torch.Generator(device=snake_case						).manual_seed(snake_case						)

           snake_case_			:str						=      floats_tensor((1, 3, 32, 32)						,					rng=random.Random(snake_case						)						).to(snake_case						)

           snake_case_			:int						=      {
               """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        lowerCAmelCase_    (	self:							Dict						)       ->     Any:
           self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3						)






     def        lowerCAmelCase_    (	self:							List[Any]						)       ->     Tuple:
           self._test_save_load_optional_components()






     @unittest.skipIf(torch_device != """cuda"""						,					reason="""float16 requires CUDA"""						)
     def        lowerCAmelCase_    (	self:							List[str]						)       ->     List[Any]:
           # 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        lowerCAmelCase_    (	self:							List[Any]						)       ->     Tuple:
           self._test_attention_slicing_forward_pass(expected_max_diff=1E-2						)






     def        lowerCAmelCase_    (	self:							Dict						)       ->     str:
           self._test_save_load_local()






     def        lowerCAmelCase_    (	self:							Optional[Any]						)       ->     List[str]:
           self._test_inference_batch_single_identical(
               expected_max_diff=1E-2						,					)





"""simple docstring"""
import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import Mock, patch

import diffusers.utils.hub_utils
class     lowerCamelCase  (      unittest.TestCase    ):






					'''simple docstring'''





					@patch("""diffusers.utils.hub_utils.get_full_repo_name"""						)
					def        lowerCAmelCase_    (	self:							int						,					snake_case:							Mock						)       ->     None:
											snake_case_			:str						=      """full_repo_name"""
											with TemporaryDirectory() as tmpdir:
																	# Dummy args values
																	snake_case_			:int						=      Mock()
																	snake_case_			:Any						=      tmpdir
																	snake_case_			:int						=      0
																	snake_case_			:Optional[int]						=      """hub_token"""
																	snake_case_			:str						=      """dataset_name"""
																	snake_case_			:List[str]						=      0.0_1
																	snake_case_			:Dict						=      100_000
																	snake_case_			:Optional[Any]						=      10_000
																	snake_case_			:Optional[Any]						=      0.0_1
																	snake_case_			:Dict						=      0.0_2
																	snake_case_			:Dict						=      0.0_3
																	snake_case_			:Union[str, Any]						=      0.0_0_0_5
																	snake_case_			:Optional[Any]						=      0.0_0_0_0_0_1
																	snake_case_			:List[Any]						=      1
																	snake_case_			:Optional[Any]						=      10
																	snake_case_			:Dict						=      0.0_0_1
																	snake_case_			:Any						=      0.1
																	snake_case_			:List[Any]						=      0.2
																	snake_case_			:Any						=      True

																	# Model card mush be rendered and saved
																	diffusers.utils.hub_utils.create_model_card(snake_case						,					model_name="""model_name"""						)
																	self.assertTrue((Path(snake_case						) / """README.md""").is_file()						)
