

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







    """simple docstring"""





    def 						snake_case__					(				self			:	List[Any]		)->   List[Any]:





        '''simple docstring'''







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


    def 						snake_case__					(				self			:	List[Any]		)->   Dict:





        '''simple docstring'''







        A__				,						A__   				=       FlaxStableDiffusionPipeline.from_pretrained(
            'stabilityai/stable-diffusion-2',revision='bf16',dtype=jnp.bfloataa,)

        A__   				=       'A painting of a squirrel eating a burger'
        A__   				=       jax.device_count()
        A__   				=       num_samples * [prompt]
        A__   				=       sd_pipe.prepare_inputs(lowercase_		)

        A__   				=       replicate(lowercase_		)
        A__   				=       shard(lowercase_		)

        A__   				=       jax.random.PRNGKey(0		)
        A__   				=       jax.random.split(lowercase_,jax.device_count()		)

        A__   				=       sd_pipe(lowercase_,lowercase_,lowercase_,num_inference_steps=2_5,jit=lowercase_		)[0]
        assert images.shape == (jax.device_count(), 1, 7_6_8, 7_6_8, 3)

        A__   				=       images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]		)
        A__   				=       images[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

        A__   				=       jnp.asarray(jax.device_get(image_slice.flatten()		)		)
        A__   				=       jnp.array([0.4_238, 0.4_414, 0.4_395, 0.4_453, 0.4_629, 0.4_590, 0.4_531, 0.45_508, 0.4_512]		)
        print(F'output_slice: {output_slice}'		)
        assert jnp.abs(output_slice - expected_slice		).max() < 1E-2


    def 						snake_case__					(				self			:	List[Any]		)->   str:





        '''simple docstring'''







        A__   				=       'stabilityai/stable-diffusion-2'
        A__				,						A__   				=       FlaxDPMSolverMultistepScheduler.from_pretrained(lowercase_,subfolder='scheduler'		)
        A__				,						A__   				=       FlaxStableDiffusionPipeline.from_pretrained(
            lowercase_,scheduler=lowercase_,revision='bf16',dtype=jnp.bfloataa,)
        A__   				=       scheduler_params

        A__   				=       'A painting of a squirrel eating a burger'
        A__   				=       jax.device_count()
        A__   				=       num_samples * [prompt]
        A__   				=       sd_pipe.prepare_inputs(lowercase_		)

        A__   				=       replicate(lowercase_		)
        A__   				=       shard(lowercase_		)

        A__   				=       jax.random.PRNGKey(0		)
        A__   				=       jax.random.split(lowercase_,jax.device_count()		)

        A__   				=       sd_pipe(lowercase_,lowercase_,lowercase_,num_inference_steps=2_5,jit=lowercase_		)[0]
        assert images.shape == (jax.device_count(), 1, 7_6_8, 7_6_8, 3)

        A__   				=       images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]		)
        A__   				=       images[0, 2_5_3:2_5_6, 2_5_3:2_5_6, -1]

        A__   				=       jnp.asarray(jax.device_get(image_slice.flatten()		)		)
        A__   				=       jnp.array([0.4_336, 0.42_969, 0.4_453, 0.4_199, 0.4_297, 0.4_531, 0.4_434, 0.4_434, 0.4_297]		)
        print(F'output_slice: {output_slice}'		)
        assert jnp.abs(output_slice - expected_slice		).max() < 1E-2




def 						_snake_case(   SCREAMING_SNAKE_CASE__      :     int = 1000				)							->				int:





    '''simple docstring'''






    A__   				=       3
    A__   				=       0
    while a < n:
        if a % 3 == 0 or a % 5 == 0:
            result += a
        elif a % 15 == 0:
            result -= a
        a += 1
    return result


if __name__ == "__main__":
     print(f"""{solution() = }""")

