


'''simple docstring'''
import gc
import unittest

from diffusers import FlaxDPMSolverMultistepScheduler, FlaxStableDiffusionPipeline
from diffusers.utils import is_flax_available, slow
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
 import jax
 import jax.numpy as jnp
 from flax.jax_utils import replicate
 from flax.training.common_utils import shard

@slow
@require_flax
class     _lowerCamelCase       (     unittest.TestCase					):




 '''simple docstring'''


 def 			snake_case__ (   self    ):

  """simple docstring"""







  super().tearDown()
  gc.collect()


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		Optional[Any]	  =      FlaxStableDiffusionPipeline.from_pretrained(
      'stabilityai/stable-diffusion-2'   ,   revision='bf16'   ,   dtype=jnp.bfloataa   ,   )

  __A	:		List[Any]	  =      "A painting of a squirrel eating a burger"
  __A	:		int	  =      jax.device_count()
  __A	:		Union[str, Any]	  =      num_samples * [prompt]
  __A	:		Dict	  =      sd_pipe.prepare_inputs(__lowercase    )

  __A	:		List[Any]	  =      replicate(__lowercase    )
  __A	:		str	  =      shard(__lowercase    )

  __A	:		Any	  =      jax.random.PRNGKey(0    )
  __A	:		Dict	  =      jax.random.split(__lowercase   ,   jax.device_count()    )

  __A	:		int	  =      sd_pipe(__lowercase   ,   __lowercase   ,   __lowercase   ,   num_inference_steps=25   ,   jit=__lowercase    )[0]
  assert images.shape == (jax.device_count(), 1, 768, 768, 3)

  __A	:		List[str]	  =      images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]    )
  __A	:		Union[str, Any]	  =      images[0, 253:256, 253:256, -1]

  __A	:		Dict	  =      jnp.asarray(jax.device_get(image_slice.flatten()    )    )
  __A	:		List[str]	  =      jnp.array([0.4_2_3_8, 0.4_4_1_4, 0.4_3_9_5, 0.4_4_5_3, 0.4_6_2_9, 0.4_5_9_0, 0.4_5_3_1, 0.4_5_5_0_8, 0.4_5_1_2]    )
  print(F"""output_slice: {output_slice}"""    )
  assert jnp.abs(output_slice - expected_slice    ).max() < 1E-2







 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		str	  =      "stabilityai/stable-diffusion-2"
  __A	:		Dict	  =      FlaxDPMSolverMultistepScheduler.from_pretrained(__lowercase   ,   subfolder='scheduler'    )
  __A	:		Any	  =      FlaxStableDiffusionPipeline.from_pretrained(
      __lowercase   ,   scheduler=__lowercase   ,   revision='bf16'   ,   dtype=jnp.bfloataa   ,   )
  __A	:		Any	  =      scheduler_params

  __A	:		Optional[Any]	  =      "A painting of a squirrel eating a burger"
  __A	:		Dict	  =      jax.device_count()
  __A	:		List[str]	  =      num_samples * [prompt]
  __A	:		int	  =      sd_pipe.prepare_inputs(__lowercase    )

  __A	:		Optional[Any]	  =      replicate(__lowercase    )
  __A	:		Dict	  =      shard(__lowercase    )

  __A	:		Any	  =      jax.random.PRNGKey(0    )
  __A	:		Union[str, Any]	  =      jax.random.split(__lowercase   ,   jax.device_count()    )

  __A	:		Union[str, Any]	  =      sd_pipe(__lowercase   ,   __lowercase   ,   __lowercase   ,   num_inference_steps=25   ,   jit=__lowercase    )[0]
  assert images.shape == (jax.device_count(), 1, 768, 768, 3)

  __A	:		List[Any]	  =      images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]    )
  __A	:		Union[str, Any]	  =      images[0, 253:256, 253:256, -1]

  __A	:		Tuple	  =      jnp.asarray(jax.device_get(image_slice.flatten()    )    )
  __A	:		str	  =      jnp.array([0.4_3_3_6, 0.4_2_9_6_9, 0.4_4_5_3, 0.4_1_9_9, 0.4_2_9_7, 0.4_5_3_1, 0.4_4_3_4, 0.4_4_3_4, 0.4_2_9_7]    )
  print(F"""output_slice: {output_slice}"""    )
  assert jnp.abs(output_slice - expected_slice    ).max() < 1E-2













def   __snake_case    (       _lowerCAmelCase			:			int						)			->    bool:
   if num < 0:
      return False

   A_       :					int        =      num
   A_       :					int        =      0
   while num > 0:
      A_       :					str        =      rev_num * 10 + (num % 10)
      num //= 10

   return num_copy == rev_num


if __name__ == "__main__":
 import doctest

 doctest.testmod()
