




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


				def     A_					(						self       :   Tuple   ):
									# clean up the VRAM after each test
									super().tearDown()
									gc.collect()


				def     A_					(						self       :   List[Any]   ):
									snake_case_     ,snake_case_		     =							FlaxStableDiffusionPipeline.from_pretrained(
									    '''stabilityai/stable-diffusion-2'''			,							revision='''bf16'''			,							dtype=jnp.bfloataa			,							)

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

									snake_case_		     =							replicate(lowercase_   )
									snake_case_		     =							shard(lowercase_   )

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

									snake_case_		     =							sd_pipe(lowercase_			,							lowercase_			,							lowercase_			,							num_inference_steps=25			,							jit=lowercase_   )[0]
									assert images.shape == (jax.device_count(), 1, 768, 768, 3)

									snake_case_		     =							images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]   )
									snake_case_		     =							images[0, 253:256, 253:256, -1]

									snake_case_		     =							jnp.asarray(jax.device_get(image_slice.flatten()   )   )
									snake_case_		     =							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     A_					(						self       :   str   ):
									snake_case_		     =							'''stabilityai/stable-diffusion-2'''
									snake_case_     ,snake_case_		     =							FlaxDPMSolverMultistepScheduler.from_pretrained(lowercase_			,							subfolder='''scheduler'''   )
									snake_case_     ,snake_case_		     =							FlaxStableDiffusionPipeline.from_pretrained(
									    lowercase_			,							scheduler=lowercase_			,							revision='''bf16'''			,							dtype=jnp.bfloataa			,							)
									snake_case_		     =							scheduler_params

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

									snake_case_		     =							replicate(lowercase_   )
									snake_case_		     =							shard(lowercase_   )

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

									snake_case_		     =							sd_pipe(lowercase_			,							lowercase_			,							lowercase_			,							num_inference_steps=25			,							jit=lowercase_   )[0]
									assert images.shape == (jax.device_count(), 1, 768, 768, 3)

									snake_case_		     =							images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]   )
									snake_case_		     =							images[0, 253:256, 253:256, -1]

									snake_case_		     =							jnp.asarray(jax.device_get(image_slice.flatten()   )   )
									snake_case_		     =							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







'''simple docstring'''

def 						__magic_name__       (      __UpperCAmelCase, __UpperCAmelCase      )						->   int:

					'''simple docstring'''

					return int((input_a, input_a).count(0      ) == 0      )


def 						__magic_name__       (      )						->   None:

					'''simple docstring'''

					assert and_gate(0, 0      ) == 0
					assert and_gate(0, 1      ) == 0
					assert and_gate(1, 0      ) == 0
					assert and_gate(1, 1      ) == 1


if __name__ == "__main__":
							test_and_gate()
							print(and_gate(1, 0))
							print(and_gate(0, 0))
							print(and_gate(0, 1))
							print(and_gate(1, 1))

