





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





       '''simple docstring'''







       def 							UpperCAmelCase__			(  self			:   Tuple		):
         super().tearDown()
         gc.collect()




       def 							UpperCAmelCase__			(  self			:   Any		):
         __snake_case:						int			  =						FlaxStableDiffusionPipeline.from_pretrained(
             """stabilityai/stable-diffusion-2"""							,    revision="""bf16"""							,    dtype=jnp.bfloataa							,    )

         __snake_case:						Any			  =						"""A painting of a squirrel eating a burger"""
         __snake_case:						Union[str, Any]			  =						jax.device_count()
         __snake_case:						List[str]			  =						num_samples * [prompt]
         __snake_case:						Optional[Any]			  =						sd_pipe.prepare_inputs(_SCREAMING_SNAKE_CASE		)

         __snake_case:						List[str]			  =						replicate(_SCREAMING_SNAKE_CASE		)
         __snake_case:						Any			  =						shard(_SCREAMING_SNAKE_CASE		)

         __snake_case:						int			  =						jax.random.PRNGKey(0		)
         __snake_case:						Tuple			  =						jax.random.split(_SCREAMING_SNAKE_CASE							,    jax.device_count()		)

         __snake_case:						Dict			  =						sd_pipe(_SCREAMING_SNAKE_CASE							,    _SCREAMING_SNAKE_CASE							,    _SCREAMING_SNAKE_CASE							,    num_inference_steps=25							,    jit=_SCREAMING_SNAKE_CASE		)[0]
         assert images.shape == (jax.device_count(), 1, 768, 768, 3)

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

         __snake_case:						Any			  =						jnp.asarray(jax.device_get(image_slice.flatten()		)		)
         __snake_case:						str			  =						jnp.array([0.4238, 0.4414, 0.4395, 0.4453, 0.4629, 0.4590, 0.4531, 0.4_5508, 0.4512]		)
         print(f'''output_slice: {output_slice}'''		)
         assert jnp.abs(output_slice - expected_slice		).max() < 1E-2






       def 							UpperCAmelCase__			(  self			:   Dict		):
         __snake_case:						Optional[Any]			  =						"""stabilityai/stable-diffusion-2"""
         __snake_case:						Dict			  =						FlaxDPMSolverMultistepScheduler.from_pretrained(_SCREAMING_SNAKE_CASE							,    subfolder="""scheduler"""		)
         __snake_case:						Optional[Any]			  =						FlaxStableDiffusionPipeline.from_pretrained(
             _SCREAMING_SNAKE_CASE							,    scheduler=_SCREAMING_SNAKE_CASE							,    revision="""bf16"""							,    dtype=jnp.bfloataa							,    )
         __snake_case:						Optional[Any]			  =						scheduler_params

         __snake_case:						int			  =						"""A painting of a squirrel eating a burger"""
         __snake_case:						Optional[Any]			  =						jax.device_count()
         __snake_case:						Optional[Any]			  =						num_samples * [prompt]
         __snake_case:						Any			  =						sd_pipe.prepare_inputs(_SCREAMING_SNAKE_CASE		)

         __snake_case:						Optional[int]			  =						replicate(_SCREAMING_SNAKE_CASE		)
         __snake_case:						Dict			  =						shard(_SCREAMING_SNAKE_CASE		)

         __snake_case:						int			  =						jax.random.PRNGKey(0		)
         __snake_case:						Tuple			  =						jax.random.split(_SCREAMING_SNAKE_CASE							,    jax.device_count()		)

         __snake_case:						List[str]			  =						sd_pipe(_SCREAMING_SNAKE_CASE							,    _SCREAMING_SNAKE_CASE							,    _SCREAMING_SNAKE_CASE							,    num_inference_steps=25							,    jit=_SCREAMING_SNAKE_CASE		)[0]
         assert images.shape == (jax.device_count(), 1, 768, 768, 3)

         __snake_case:						Dict			  =						images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]		)
         __snake_case:						Optional[Any]			  =						images[0, 253:256, 253:256, -1]

         __snake_case:						Any			  =						jnp.asarray(jax.device_get(image_slice.flatten()		)		)
         __snake_case:						List[Any]			  =						jnp.array([0.4336, 0.4_2969, 0.4453, 0.4199, 0.4297, 0.4531, 0.4434, 0.4434, 0.4297]		)
         print(f'''output_slice: {output_slice}'''		)
         assert jnp.abs(output_slice - expected_slice		).max() < 1E-2













import math







def       A__							(   SCREAMING_SNAKE_CASE__)       ->   int:

  if not isinstance(SCREAMING_SNAKE_CASE__ , SCREAMING_SNAKE_CASE__):
    __snake_case:						Optional[int]			  =						F'''Input value of [number={number}] must be an integer'''
    raise TypeError(SCREAMING_SNAKE_CASE__)

  if number < 1:
    __snake_case:						Optional[int]			  =						F'''Input value of [number={number}] must be > 0'''
    raise ValueError(SCREAMING_SNAKE_CASE__)
  elif number == 1:
    return 3
  elif number == 2:
    return 5
  else:
    __snake_case:						List[Any]			  =						int(math.log(number // 3 , 2)) + 2

    __snake_case:						str			  =						[3, 5]
    __snake_case:						int			  =						2
    __snake_case:						List[str]			  =						3
    for block in range(1 , SCREAMING_SNAKE_CASE__):
      for _ in range(SCREAMING_SNAKE_CASE__):
        proth_list.append(2 ** (block + 1) + proth_list[proth_index - 1])
        proth_index += 1
      increment *= 2

  return proth_list[number - 1]


if __name__ == "__main__":
      import doctest

      doctest.testmod()

      for number in range(11):
            __UpperCAmelCase	:       Optional[int]    	=							0
            try:
                  __UpperCAmelCase	:       int    	=							proth(number)
            except ValueError:
                  print(f'ValueError: there is no {number}th Proth number')
                  continue

            print(f'The {number}th Proth number: {value}')






