

import gc
import unittest

from diffusers import FlaxControlNetModel, FlaxStableDiffusionControlNetPipeline
from diffusers.utils import is_flax_available, load_image, 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     __lowercase (unittest.TestCase					):
 def       UpperCamelCase__    (				self   )   ->Union[str, Any]:



       '''simple docstring'''





       super().tearDown()
       gc.collect()
 def       UpperCamelCase__    (				self   )   ->List[Any]:



       '''simple docstring'''





       __lowerCAmelCase,				__lowerCAmelCase   :		Union[str, Any]   =   FlaxControlNetModel.from_pretrained(
           '''lllyasviel/sd-controlnet-canny''' ,				from_pt=snake_case_ ,				dtype=jnp.bfloataa   )
       __lowerCAmelCase,				__lowerCAmelCase   :		Optional[Any]   =   FlaxStableDiffusionControlNetPipeline.from_pretrained(
           '''runwayml/stable-diffusion-v1-5''' ,				controlnet=snake_case_ ,				from_pt=snake_case_ ,				dtype=jnp.bfloataa   )
       __lowerCAmelCase   :		Tuple   =   controlnet_params

       __lowerCAmelCase   :		Union[str, Any]   =   '''bird'''
       __lowerCAmelCase   :		Dict   =   jax.device_count()
       __lowerCAmelCase   :		Tuple   =   pipe.prepare_text_inputs([prompts] * num_samples   )

       __lowerCAmelCase   :		Union[str, Any]   =   load_image(
           '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/bird_canny.png'''   )
       __lowerCAmelCase   :		Union[str, Any]   =   pipe.prepare_image_inputs([canny_image] * num_samples   )

       __lowerCAmelCase   :		List[str]   =   jax.random.PRNGKey(0   )
       __lowerCAmelCase   :		Tuple   =   jax.random.split(snake_case_ ,				jax.device_count()   )

       __lowerCAmelCase   :		Union[str, Any]   =   replicate(snake_case_   )
       __lowerCAmelCase   :		Optional[Any]   =   shard(snake_case_   )
       __lowerCAmelCase   :		Tuple   =   shard(snake_case_   )

       __lowerCAmelCase   :		Tuple   =   pipe(
           prompt_ids=snake_case_ ,				image=snake_case_ ,				params=snake_case_ ,				prng_seed=snake_case_ ,				num_inference_steps=50 ,				jit=snake_case_ ,				).images
       assert images.shape == (jax.device_count(), 1, 768, 512, 3)

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

       __lowerCAmelCase   :		Dict   =   jnp.asarray(jax.device_get(image_slice.flatten()   )   )
       __lowerCAmelCase   :		Union[str, Any]   =   jnp.array(
           [0.167_969, 0.116_699, 0.081_543, 0.154_297, 0.132_812, 0.108_887, 0.169_922, 0.169_922, 0.205_078]   )
       print(f"""output_slice: {output_slice}"""   )
       assert jnp.abs(output_slice - expected_slice   ).max() < 1e-2





 def       UpperCamelCase__    (				self   )   ->Union[str, Any]:



       '''simple docstring'''





       __lowerCAmelCase,				__lowerCAmelCase   :		Any   =   FlaxControlNetModel.from_pretrained(
           '''lllyasviel/sd-controlnet-openpose''' ,				from_pt=snake_case_ ,				dtype=jnp.bfloataa   )
       __lowerCAmelCase,				__lowerCAmelCase   :		List[Any]   =   FlaxStableDiffusionControlNetPipeline.from_pretrained(
           '''runwayml/stable-diffusion-v1-5''' ,				controlnet=snake_case_ ,				from_pt=snake_case_ ,				dtype=jnp.bfloataa   )
       __lowerCAmelCase   :		Optional[Any]   =   controlnet_params

       __lowerCAmelCase   :		List[str]   =   '''Chef in the kitchen'''
       __lowerCAmelCase   :		Union[str, Any]   =   jax.device_count()
       __lowerCAmelCase   :		Union[str, Any]   =   pipe.prepare_text_inputs([prompts] * num_samples   )

       __lowerCAmelCase   :		Any   =   load_image(
           '''https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/pose.png'''   )
       __lowerCAmelCase   :		Optional[Any]   =   pipe.prepare_image_inputs([pose_image] * num_samples   )

       __lowerCAmelCase   :		int   =   jax.random.PRNGKey(0   )
       __lowerCAmelCase   :		Tuple   =   jax.random.split(snake_case_ ,				jax.device_count()   )

       __lowerCAmelCase   :		Optional[Any]   =   replicate(snake_case_   )
       __lowerCAmelCase   :		Dict   =   shard(snake_case_   )
       __lowerCAmelCase   :		Dict   =   shard(snake_case_   )

       __lowerCAmelCase   :		Optional[Any]   =   pipe(
           prompt_ids=snake_case_ ,				image=snake_case_ ,				params=snake_case_ ,				prng_seed=snake_case_ ,				num_inference_steps=50 ,				jit=snake_case_ ,				).images
       assert images.shape == (jax.device_count(), 1, 768, 512, 3)

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

       __lowerCAmelCase   :		int   =   jnp.asarray(jax.device_get(image_slice.flatten()   )   )
       __lowerCAmelCase   :		str   =   jnp.array(
           [[0.271_484, 0.261_719, 0.275_391, 0.277_344, 0.279_297, 0.291_016, 0.294_922, 0.302_734, 0.302_734]]   )
       print(f"""output_slice: {output_slice}"""   )
       assert jnp.abs(output_slice - expected_slice   ).max() < 1e-2









from __future__ import annotations

import math





def 				__lowerCAmelCase(       _SCREAMING_SNAKE_CASE				)							-> list[int]:




    """simple docstring"""




    if num <= 0:
        _A     =							F"{num}: Invalid input, please enter a positive integer."
        raise ValueError(_SCREAMING_SNAKE_CASE				)

    _A     =							[True] * (num + 1)
    _A     =							[]
    _A     =							2
    _A     =							int(math.sqrt(_SCREAMING_SNAKE_CASE				)				)

    while start <= end:
        # If start is a prime
        if sieve[start] is True:
            prime.append(_SCREAMING_SNAKE_CASE				)

            # Set multiples of start be False
            for i in range(start * start							,     num + 1							,     _SCREAMING_SNAKE_CASE				):
                if sieve[i] is True:
                    _A     =							False

        start += 1

    for j in range(end + 1							,     num + 1				):
        if sieve[j] is True:
            prime.append(_SCREAMING_SNAKE_CASE				)

    return prime


if __name__ == "__main__":
 print(prime_sieve(int(input("Enter a positive integer: ").strip())))





