




"""simple docstring"""

import random






def 		_snake_case	(   _snake_case				:   int				)       ->   bool:






      '''simple docstring'''


      _A     =  num - 1
      _A     =  0

      while s % 2 == 0:
            _A     =  s // 2
            t += 1

      for _ in range(5				):
            _A     =  random.randrange(2							,    num - 1				)
            _A     =  pow(_snake_case							,    _snake_case							,    _snake_case				)
            if v != 1:
                  _A     =  0
                  while v != (num - 1):
                        if i == t - 1:
                              return False
                        else:
                              _A     =  i + 1
                              _A     =  (v**2) % num
      return True






def 		_snake_case	(   _snake_case				:   int				)       ->   bool:






      '''simple docstring'''


      if num < 2:
            return False

      _A     =  [
          2,
          3,
          5,
          7,
          11,
          13,
          17,
          19,
          23,
          29,
          31,
          37,
          41,
          43,
          47,
          53,
          59,
          61,
          67,
          71,
          73,
          79,
          83,
          89,
          97,
          1_01,
          1_03,
          1_07,
          1_09,
          1_13,
          1_27,
          1_31,
          1_37,
          1_39,
          1_49,
          1_51,
          1_57,
          1_63,
          1_67,
          1_73,
          1_79,
          1_81,
          1_91,
          1_93,
          1_97,
          1_99,
          2_11,
          2_23,
          2_27,
          2_29,
          2_33,
          2_39,
          2_41,
          2_51,
          2_57,
          2_63,
          2_69,
          2_71,
          2_77,
          2_81,
          2_83,
          2_93,
          3_07,
          3_11,
          3_13,
          3_17,
          3_31,
          3_37,
          3_47,
          3_49,
          3_53,
          3_59,
          3_67,
          3_73,
          3_79,
          3_83,
          3_89,
          3_97,
          4_01,
          4_09,
          4_19,
          4_21,
          4_31,
          4_33,
          4_39,
          4_43,
          4_49,
          4_57,
          4_61,
          4_63,
          4_67,
          4_79,
          4_87,
          4_91,
          4_99,
          5_03,
          5_09,
          5_21,
          5_23,
          5_41,
          5_47,
          5_57,
          5_63,
          5_69,
          5_71,
          5_77,
          5_87,
          5_93,
          5_99,
          6_01,
          6_07,
          6_13,
          6_17,
          6_19,
          6_31,
          6_41,
          6_43,
          6_47,
          6_53,
          6_59,
          6_61,
          6_73,
          6_77,
          6_83,
          6_91,
          7_01,
          7_09,
          7_19,
          7_27,
          7_33,
          7_39,
          7_43,
          7_51,
          7_57,
          7_61,
          7_69,
          7_73,
          7_87,
          7_97,
          8_09,
          8_11,
          8_21,
          8_23,
          8_27,
          8_29,
          8_39,
          8_53,
          8_57,
          8_59,
          8_63,
          8_77,
          8_81,
          8_83,
          8_87,
          9_07,
          9_11,
          9_19,
          9_29,
          9_37,
          9_41,
          9_47,
          9_53,
          9_67,
          9_71,
          9_77,
          9_83,
          9_91,
          9_97,
      ]

      if num in low_primes:
            return True

      for prime in low_primes:
            if (num % prime) == 0:
                  return False

      return rabin_miller(_snake_case				)






def 		_snake_case	(   _snake_case				:   int = 10_24				)       ->   int:






      '''simple docstring'''


      while True:
            _A     =  random.randrange(2 ** (keysize - 1)							,    2 ** (keysize)				)
            if is_prime_low_num(_snake_case				):
                  return num


if __name__ == "__main__":
       a							      =     generate_large_prime()
       print(('''Prime number:''', num))
       print(('''is_prime_low_num:''', is_prime_low_num(num)))







"""simple docstring"""




import gc
import unittest

import numpy as np
import torch

from diffusers import AutoencoderKL, DDIMScheduler, DiTPipeline, DPMSolverMultistepScheduler, TransformeraDModel
from diffusers.utils import is_xformers_available, load_numpy, slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import (
    CLASS_CONDITIONED_IMAGE_GENERATION_BATCH_PARAMS,
    CLASS_CONDITIONED_IMAGE_GENERATION_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin


enable_full_determinism()






class        __magic_name__				(			UpperCAmelCase__		,   unittest.TestCase							):






				'''simple docstring'''
				__UpperCamelCase         =		DiTPipeline
				__UpperCamelCase         =		CLASS_CONDITIONED_IMAGE_GENERATION_PARAMS
				__UpperCamelCase         =		PipelineTesterMixin.required_optional_params - {
				    "latents",
				    "num_images_per_prompt",
				    "callback",
				    "callback_steps",
				}
				__UpperCamelCase         =		CLASS_CONDITIONED_IMAGE_GENERATION_BATCH_PARAMS
				__UpperCamelCase         =		False





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							torch.manual_seed(0					)
							lowerCamelCase      =   TransformeraDModel(
							    sample_size=16						,					num_layers=2						,					patch_size=4						,					attention_head_dim=8						,					num_attention_heads=2						,					in_channels=4						,					out_channels=8						,					attention_bias=_a						,					activation_fn="""gelu-approximate"""						,					num_embeds_ada_norm=1_000						,					norm_type="""ada_norm_zero"""						,					norm_elementwise_affine=_a						,					)
							lowerCamelCase      =   AutoencoderKL()
							lowerCamelCase      =   DDIMScheduler()
							lowerCamelCase      =   {"""transformer""": transformer.eval(), """vae""": vae.eval(), """scheduler""": scheduler}
							return components





				def   _lowerCAmelCase							(			self						,					_a						,					_a=0					):





							"""simple docstring"""
							if str(_a					).startswith("""mps"""					):
										lowerCamelCase      =   torch.manual_seed(_a					)
							else:
										lowerCamelCase      =   torch.Generator(device=_a					).manual_seed(_a					)
							lowerCamelCase      =   {
							    """class_labels""": [1],
							    """generator""": generator,
							    """num_inference_steps""": 2,
							    """output_type""": """numpy""",
							}
							return inputs





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							lowerCamelCase      =   """cpu"""

							lowerCamelCase      =   self.get_dummy_components()
							lowerCamelCase      =   self.pipeline_class(**_a					)
							pipe.to(_a					)
							pipe.set_progress_bar_config(disable=_a					)

							lowerCamelCase      =   self.get_dummy_inputs(_a					)
							lowerCamelCase      =   pipe(**_a					).images
							lowerCamelCase      =   image[0, -3:, -3:, -1]

							self.assertEqual(image.shape						,					(1, 16, 16, 3)					)
							lowerCamelCase      =   np.array([0.2_946, 0.6_601, 0.4_329, 0.3_296, 0.4_144, 0.5_319, 0.7_273, 0.5_013, 0.4_457]					)
							lowerCamelCase      =   np.abs(image_slice.flatten() - expected_slice					).max()
							self.assertLessEqual(_a						,					1e-3					)





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							self._test_inference_batch_single_identical(relax_max_difference=_a						,					expected_max_diff=1e-3					)





				@unittest.skipIf(
				    torch_device != """cuda""" or not is_xformers_available()						,					reason="""XFormers attention is only available with CUDA and `xformers` installed"""						,					)
				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3					)






@require_torch_gpu
@slow
class        __magic_name__				(			unittest.TestCase							):






				'''simple docstring'''





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							super().tearDown()
							gc.collect()
							torch.cuda.empty_cache()





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							lowerCamelCase      =   torch.manual_seed(0					)

							lowerCamelCase      =   DiTPipeline.from_pretrained("""facebook/DiT-XL-2-256"""					)
							pipe.to("""cuda"""					)

							lowerCamelCase      =   ["""vase""", """umbrella""", """white shark""", """white wolf"""]
							lowerCamelCase      =   pipe.get_label_ids(_a					)

							lowerCamelCase      =   pipe(_a						,					generator=_a						,					num_inference_steps=40						,					output_type="""np"""					).images

							for word, image in zip(_a						,					_a					):
										lowerCamelCase      =   load_numpy(
										    f'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/dit/{word}.npy'					)
										assert np.abs((expected_image - image).max()					) < 1e-2





				def   _lowerCAmelCase							(			self					):





							"""simple docstring"""
							lowerCamelCase      =   DiTPipeline.from_pretrained("""facebook/DiT-XL-2-512"""					)
							lowerCamelCase      =   DPMSolverMultistepScheduler.from_config(pipe.scheduler.config					)
							pipe.to("""cuda"""					)

							lowerCamelCase      =   ["""vase""", """umbrella"""]
							lowerCamelCase      =   pipe.get_label_ids(_a					)

							lowerCamelCase      =   torch.manual_seed(0					)
							lowerCamelCase      =   pipe(_a						,					generator=_a						,					num_inference_steps=25						,					output_type="""np"""					).images

							for word, image in zip(_a						,					_a					):
										lowerCamelCase      =   load_numpy(
										    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
										    f'/dit/{word}_512.npy'					)

										assert np.abs((expected_image - image).max()					) < 1e-1



