


import random
import unittest

import torch

from diffusers import IFImgaImgPipeline
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__(     snake_case__     ,     snake_case__     ,     unittest.TestCase    ):






    '''simple docstring'''





    A_	:  Union[str, Any]								=			IFImgaImgPipeline
    A_	:  int								=			TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'width', 'height'}
    A_	:  List[Any]								=			TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
    A_	:  str								=			PipelineTesterMixin.required_optional_params - {'latents'}





    def        _lowerCamelCase			(						self					: str						):





       '''simple docstring'''
       return self._get_dummy_components()





    def        _lowerCamelCase			(						self					: str							, __snake_case					: Union[str, Any]							, __snake_case					: List[Any]=0						):





       '''simple docstring'''
       if str(__snake_case						).startswith('''mps'''						):
          UpperCAmelCase_				:   List[str]							= torch.manual_seed(__snake_case						)
       else:
          UpperCAmelCase_				:   Optional[int]							= torch.Generator(device=__snake_case						).manual_seed(__snake_case						)

       UpperCAmelCase_				:   Any							= floats_tensor((1, 3, 32, 32)							, rng=random.Random(__snake_case						)						).to(__snake_case						)

       UpperCAmelCase_				:   Any							= {
           '''prompt''': '''A painting of a squirrel eating a burger''',
           '''image''': image,
           '''generator''': generator,
           '''num_inference_steps''': 2,
           '''output_type''': '''numpy''',
       }

       return inputs





    def        _lowerCamelCase			(						self					: Any						):





       '''simple docstring'''
       self._test_save_load_optional_components()





    @unittest.skipIf(
        torch_device != '''cuda''' or not is_xformers_available()							, reason='''XFormers attention is only available with CUDA and `xformers` installed'''							, )
    def        _lowerCamelCase			(						self					: List[Any]						):





       '''simple docstring'''
       self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3						)





    @unittest.skipIf(torch_device != '''cuda'''							, reason='''float16 requires CUDA'''						)
    def        _lowerCamelCase			(						self					: Tuple						):





       '''simple docstring'''
       # 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						)





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





       '''simple docstring'''
       super().test_floataa_inference(expected_max_diff=1E-1						)





    def        _lowerCamelCase			(						self					: List[str]						):





       '''simple docstring'''
       self._test_attention_slicing_forward_pass(expected_max_diff=1E-2						)





    def        _lowerCamelCase			(						self					: Tuple						):





       '''simple docstring'''
       self._test_save_load_local()





    def        _lowerCamelCase			(						self					: Optional[Any]						):





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



import unittest

import numpy as np

from transformers import is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
       import tensorflow as tf

       from transformers.activations_tf import get_tf_activation





@require_tf
class 			lowerCAmelCase__(     unittest.TestCase    ):






    '''simple docstring'''





    def        _lowerCamelCase			(						self					: Optional[int]						):





       '''simple docstring'''
       UpperCAmelCase_				:   str							= tf.constant([-100, -1.0, -0.1, 0, 0.1, 1.0, 100.0]						)
       UpperCAmelCase_				:   List[Any]							= get_tf_activation('''gelu'''						)
       UpperCAmelCase_				:   Any							= get_tf_activation('''gelu_10'''						)

       UpperCAmelCase_				:   int							= gelu(__snake_case						)
       UpperCAmelCase_				:   Union[str, Any]							= geluaa(__snake_case						)

       UpperCAmelCase_				:   Union[str, Any]							= tf.where(y_gelu_aa < 10.0							, 1.0							, 0.0						)

       self.assertEqual(tf.math.reduce_max(__snake_case						).numpy().item()							, 10.0						)
       self.assertTrue(np.allclose(y_gelu * clipped_mask							, y_gelu_aa * clipped_mask						)						)





    def        _lowerCamelCase			(						self					: Dict						):





       '''simple docstring'''
       get_tf_activation('''gelu'''						)
       get_tf_activation('''gelu_10'''						)
       get_tf_activation('''gelu_fast'''						)
       get_tf_activation('''gelu_new'''						)
       get_tf_activation('''glu'''						)
       get_tf_activation('''mish'''						)
       get_tf_activation('''quick_gelu'''						)
       get_tf_activation('''relu'''						)
       get_tf_activation('''sigmoid'''						)
       get_tf_activation('''silu'''						)
       get_tf_activation('''swish'''						)
       get_tf_activation('''tanh'''						)
       with self.assertRaises(__snake_case						):
          get_tf_activation('''bogus'''						)
       with self.assertRaises(__snake_case						):
          get_tf_activation(__snake_case						)