

import random
import unittest

import torch

from diffusers import IFInpaintingPipeline
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				(					SCREAMING_SNAKE_CASE  ,						SCREAMING_SNAKE_CASE  ,						unittest.TestCase			):
 _lowercase  :   Optional[int]       				=  IFInpaintingPipeline
 _lowercase  :   Optional[Any]       				=  TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {"width", "height"}
 _lowercase  :   Union[str, Any]       				=  TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS
 _lowercase  :   Union[str, Any]       				=  PipelineTesterMixin.required_optional_params - {"latents"}







 def 	_SCREAMING_SNAKE_CASE							(   self: Optional[int]      ):

      '''simple docstring'''





      return self._get_dummy_components()







 def 	_SCREAMING_SNAKE_CASE							(   self: str  , __UpperCamelCase: Tuple  , __UpperCamelCase: str=0      ):

      '''simple docstring'''





      if str(__UpperCamelCase      ).startswith('mps'      ):
           __magic_name__							=    torch.manual_seed(__UpperCamelCase      )
      else:
           __magic_name__							=    torch.Generator(device=__UpperCamelCase      ).manual_seed(__UpperCamelCase      )

      __magic_name__							=    floats_tensor((1, 3, 32, 32)  , rng=random.Random(__UpperCamelCase      )      ).to(__UpperCamelCase      )
      __magic_name__							=    floats_tensor((1, 3, 32, 32)  , rng=random.Random(__UpperCamelCase      )      ).to(__UpperCamelCase      )

      __magic_name__							=    {
          'prompt': 'A painting of a squirrel eating a burger',
          'image': 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 	_SCREAMING_SNAKE_CASE							(   self: str      ):

      '''simple docstring'''





      self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3      )







 def 	_SCREAMING_SNAKE_CASE							(   self: Dict      ):

      '''simple docstring'''





      self._test_save_load_optional_components()







 @unittest.skipIf(torch_device != 'cuda'  , reason='float16 requires CUDA'      )
 def 	_SCREAMING_SNAKE_CASE							(   self: Union[str, Any]      ):

      '''simple docstring'''





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







 def 	_SCREAMING_SNAKE_CASE							(   self: List[Any]      ):

      '''simple docstring'''





      self._test_attention_slicing_forward_pass(expected_max_diff=1E-2      )







 def 	_SCREAMING_SNAKE_CASE							(   self: Optional[Any]      ):

      '''simple docstring'''





      self._test_save_load_local()







 def 	_SCREAMING_SNAKE_CASE							(   self: Optional[Any]      ):

      '''simple docstring'''





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







import unittest

from transformers import AutoConfig, AutoTokenizer, BertConfig, TensorType, is_flax_available
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, require_flax, slow


if is_flax_available():
						import jax

						from transformers.models.auto.modeling_flax_auto import FlaxAutoModel
						from transformers.models.bert.modeling_flax_bert import FlaxBertModel
						from transformers.models.roberta.modeling_flax_roberta import FlaxRobertaModel

@require_flax
class 				__UpperCamelCase				(					unittest.TestCase			):







	@slow
	def 	_SCREAMING_SNAKE_CASE							(   self: Any      ):

						'''simple docstring'''





						for model_name in ["bert-base-cased", "bert-large-uncased"]:
											with self.subTest(__UpperCamelCase      ):
																__magic_name__							=    AutoConfig.from_pretrained(__UpperCamelCase      )
																self.assertIsNotNone(__UpperCamelCase      )
																self.assertIsInstance(__UpperCamelCase  , __UpperCamelCase      )

																__magic_name__							=    FlaxAutoModel.from_pretrained(__UpperCamelCase      )
																self.assertIsNotNone(__UpperCamelCase      )
																self.assertIsInstance(__UpperCamelCase  , __UpperCamelCase      )







	@slow
	def 	_SCREAMING_SNAKE_CASE							(   self: Tuple      ):

						'''simple docstring'''





						for model_name in ["roberta-base", "roberta-large"]:
											with self.subTest(__UpperCamelCase      ):
																__magic_name__							=    AutoConfig.from_pretrained(__UpperCamelCase      )
																self.assertIsNotNone(__UpperCamelCase      )
																self.assertIsInstance(__UpperCamelCase  , __UpperCamelCase      )

																__magic_name__							=    FlaxAutoModel.from_pretrained(__UpperCamelCase      )
																self.assertIsNotNone(__UpperCamelCase      )
																self.assertIsInstance(__UpperCamelCase  , __UpperCamelCase      )







	@slow
	def 	_SCREAMING_SNAKE_CASE							(   self: Dict      ):

						'''simple docstring'''





						for model_name in ["bert-base-cased", "bert-large-uncased"]:
											__magic_name__							=    AutoTokenizer.from_pretrained(__UpperCamelCase      )
											__magic_name__							=    FlaxBertModel.from_pretrained(__UpperCamelCase      )
											__magic_name__							=    tokenizer('Do you support jax jitted function?'  , return_tensors=TensorType.JAX      )

											@jax.jit
											def eval(**__UpperCamelCase: Optional[Any]      ):
																return model(**__UpperCamelCase      )

											eval(**__UpperCamelCase      ).block_until_ready()







	@slow
	def 	_SCREAMING_SNAKE_CASE							(   self: int      ):

						'''simple docstring'''





						for model_name in ["roberta-base", "roberta-large"]:
											__magic_name__							=    AutoTokenizer.from_pretrained(__UpperCamelCase      )
											__magic_name__							=    FlaxRobertaModel.from_pretrained(__UpperCamelCase      )
											__magic_name__							=    tokenizer('Do you support jax jitted function?'  , return_tensors=TensorType.JAX      )

											@jax.jit
											def eval(**__UpperCamelCase: Any      ):
																return model(**__UpperCamelCase      )

											eval(**__UpperCamelCase      ).block_until_ready()







	def 	_SCREAMING_SNAKE_CASE							(   self: Tuple      ):

						'''simple docstring'''





						with self.assertRaisesRegex(
						    __UpperCamelCase  , 'bert-base is not a local folder and is not a valid model identifier'      ):
											__magic_name__							=    FlaxAutoModel.from_pretrained('bert-base'      )







	def 	_SCREAMING_SNAKE_CASE							(   self: List[Any]      ):

						'''simple docstring'''





						with self.assertRaisesRegex(
						    __UpperCamelCase  , r'aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'      ):
											__magic_name__							=    FlaxAutoModel.from_pretrained(__UpperCamelCase  , revision='aaaaaa'      )







	def 	_SCREAMING_SNAKE_CASE							(   self: str      ):

						'''simple docstring'''





						with self.assertRaisesRegex(
						    __UpperCamelCase  , 'hf-internal-testing/config-no-model does not appear to have a file named flax_model.msgpack'  , ):
											__magic_name__							=    FlaxAutoModel.from_pretrained('hf-internal-testing/config-no-model'      )







	def 	_SCREAMING_SNAKE_CASE							(   self: int      ):

						'''simple docstring'''





						with self.assertRaisesRegex(__UpperCamelCase  , 'Use `from_pt=True` to load this model'      ):
											__magic_name__							=    FlaxAutoModel.from_pretrained('hf-internal-testing/tiny-bert-pt-only'      )




