

'''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 					snake_case   (   lowercase      ,						lowercase      ,						unittest.TestCase      ):





  """simple docstring"""




  _lowerCamelCase		   =  IFSuperResolutionPipeline
  _lowerCamelCase		   =  TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
  _lowerCamelCase		   =  TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
  _lowerCamelCase		   =  PipelineTesterMixin.required_optional_params - {"latents"}






  def   snake_case		(   self					):







   """simple docstring"""
   return self._get_superresolution_dummy_components()






  def   snake_case		(   self      ,  UpperCamelCase      ,  UpperCamelCase=0					):







   """simple docstring"""
   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   snake_case		(   self					):







   """simple docstring"""
   self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3					)






  def   snake_case		(   self					):







   """simple docstring"""
   self._test_save_load_optional_components()






  @unittest.skipIf(torch_device != "cuda"      ,  reason="float16 requires CUDA"					)
  def   snake_case		(   self					):







   """simple docstring"""
   super().test_save_load_floataa(expected_max_diff=1e-1					)






  def   snake_case		(   self					):







   """simple docstring"""
   self._test_attention_slicing_forward_pass(expected_max_diff=1e-2					)






  def   snake_case		(   self					):







   """simple docstring"""
   self._test_save_load_local()







  def   snake_case		(   self					):







   """simple docstring"""
   self._test_inference_batch_single_identical(
       expected_max_diff=1e-2      ,  )







'''simple docstring'''

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 					snake_case   (   unittest.TestCase      ):





  """simple docstring"""




  def   snake_case		(   self					):







   """simple docstring"""
   lowerCamelCase_								=  tf.constant([-100, -1.0, -0.1, 0, 0.1, 1.0, 100.0]					)
   lowerCamelCase_								=  get_tf_activation("gelu"					)
   lowerCamelCase_								=  get_tf_activation("gelu_10"					)

   lowerCamelCase_								=  gelu(UpperCamelCase					)
   lowerCamelCase_								=  geluaa(UpperCamelCase					)

   lowerCamelCase_								=  tf.where(y_gelu_aa < 10.0      ,  1.0      ,  0.0					)

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







  def   snake_case		(   self					):







   """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(UpperCamelCase					):
    get_tf_activation("bogus"					)
   with self.assertRaises(UpperCamelCase					):
    get_tf_activation(UpperCamelCase					)



