


"""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 	__UpperCamelCase    (    UpperCamelCase      ,    UpperCamelCase      ,    unittest.TestCase	):
					lowercase_						:							Optional[Any]			=     IFSuperResolutionPipeline
					lowercase_						:							int			=     TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"""width""", """height"""}
					lowercase_						:							Optional[Any]			=     TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
					lowercase_						:							int			=     PipelineTesterMixin.required_optional_params - {"""latents"""}
					def 					UpperCAmelCase__   (       self       :  Union[str, Any]      )  ->					Dict:
											return self._get_superresolution_dummy_components()
					def 					UpperCAmelCase__   (       self       :  int    ,   UpperCAmelCase       :  Any    ,   UpperCAmelCase       :  Any=0      )  ->					Optional[Any]:
											if str(UpperCAmelCase      ).startswith('mps'      ):
																	lowerCAmelCase      :Optional[int]				  = torch.manual_seed(UpperCAmelCase      )
											else:
																	lowerCAmelCase      :List[str]				  = torch.Generator(device=UpperCAmelCase      ).manual_seed(UpperCAmelCase      )

											lowerCAmelCase      :Optional[Any]				  = floats_tensor((1, 3, 32, 32)    ,   rng=random.Random(UpperCAmelCase      )      ).to(UpperCAmelCase      )

											lowerCAmelCase      :List[Any]				  = {
											    '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       :  Union[str, Any]      )  ->					List[Any]:
											self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3      )
					def 					UpperCAmelCase__   (       self       :  Optional[Any]      )  ->					str:
											self._test_save_load_optional_components()
					@unittest.skipIf(torch_device != 'cuda'    ,   reason='float16 requires CUDA'      )
					def 					UpperCAmelCase__   (       self       :  List[Any]      )  ->					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       :  Optional[int]      )  ->					Union[str, Any]:
											self._test_attention_slicing_forward_pass(expected_max_diff=1e-2      )
					def 					UpperCAmelCase__   (       self       :  List[Any]      )  ->					Union[str, Any]:
											self._test_save_load_local()
					def 					UpperCAmelCase__   (       self       :  Tuple      )  ->					Union[str, Any]:
											self._test_inference_batch_single_identical(
											    expected_max_diff=1e-2    ,   )







"""simple docstring"""


import unittest
import warnings
from dataclasses import dataclass

from transformers.convert_slow_tokenizer import SpmConverter
from transformers.testing_utils import get_tests_dir




@dataclass
class 	__UpperCamelCase    :
					lowercase_						:							str




class 	__UpperCamelCase    (    unittest.TestCase	):
					def 					UpperCAmelCase__   (       self       :  Union[str, Any]      )  ->					Optional[Any]:
											lowerCAmelCase      :List[str]				  = get_tests_dir('fixtures/test_sentencepiece.model'      )
											lowerCAmelCase      :Tuple				  = get_tests_dir('fixtures/test_sentencepiece_with_bytefallback.model'      )

											lowerCAmelCase      :List[str]				  = FakeOriginalTokenizer(vocab_file=UpperCAmelCase      )

											with warnings.catch_warnings(record=UpperCAmelCase      ) as w:
																	lowerCAmelCase      :Dict				  = SpmConverter(UpperCAmelCase      )
											self.assertEqual(len(UpperCAmelCase      )    ,   0      )

											lowerCAmelCase      :int				  = FakeOriginalTokenizer(vocab_file=UpperCAmelCase      )

											with warnings.catch_warnings(record=UpperCAmelCase      ) as w:
																	lowerCAmelCase      :List[str]				  = SpmConverter(UpperCAmelCase      )
											self.assertEqual(len(UpperCAmelCase      )    ,   1      )

											self.assertIn(
											    'The sentencepiece tokenizer that you are converting to a fast tokenizer uses the byte fallback option'
											    ' which is not implemented in the fast tokenizers.'    ,   str(w[0].message      )    ,   )